fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ISCSID --
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Discovery of targets and access to the persistent storage starts here.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/thread.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/types.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/proc.h> /* declares: p0 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/cmn_err.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/scsi/adapters/iscsi_if.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <netinet/in.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "iscsi_targetparam.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "isns_client.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "isns_protocol.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "persistent.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "iscsi.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/ethernet.h>
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng#include <sys/bootprops.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * local function prototypes
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic boolean_t iscsid_init_config(iscsi_hba_t *ihp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic boolean_t iscsid_init_targets(iscsi_hba_t *ihp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void iscsid_thread_static(iscsi_thread_t *thread, void *p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void iscsid_thread_sendtgts(iscsi_thread_t *thread, void *p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void iscsid_thread_isns(iscsi_thread_t *thread, void *p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void iscsid_thread_slp(iscsi_thread_t *thread, void *p);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Mengstatic void iscsid_thread_boot_wd(iscsi_thread_t *thread, void *p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void iscsid_threads_create(iscsi_hba_t *ihp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void iscsid_threads_destroy(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int iscsid_copyto_param_set(uint32_t param_id,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_login_params_t *params, iscsi_param_set_t *ipsp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void iscsid_add_pg_list_to_cache(iscsi_hba_t *ihp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_portal_group_list_t *pg_list);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void iscsid_remove_target_param(char *name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic boolean_t iscsid_add(iscsi_hba_t *ihp, iSCSIDiscoveryMethod_t method,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct sockaddr *addr_dsc, char *target_name, int tpgt,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct sockaddr *addr_tgt);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void iscsi_discovery_event(iscsi_hba_t *ihp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iSCSIDiscoveryMethod_t m, boolean_t start);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Mengstatic boolean_t iscsid_boot_init_config(iscsi_hba_t *ihp);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Mengstatic iscsi_sess_t *iscsi_add_boot_sess(iscsi_hba_t *ihp, int isid);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Mengstatic boolean_t iscsid_make_entry(ib_boot_prop_t *boot_prop_entry,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng entry_t *entry);
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Mengstatic boolean_t iscsid_check_active_boot_conn(iscsi_hba_t *ihp);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Mengextern int modrootloaded;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Mengint iscsi_configroot_retry = 20;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Mengstatic boolean_t iscsi_configroot_printed = FALSE;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlapstatic int iscsi_net_up = 0;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Mengextern ib_boot_prop_t *iscsiboot_prop;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng#define ISCSI_CONFIGROOT_DELAY 1
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iSCSI target discovery thread table
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct iscsid_thr_table {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void (*func_start)(iscsi_thread_t *, void *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_thread_t *thr_id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iSCSIDiscoveryMethod_t method;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *name;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} iscsid_thr_table;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic iscsid_thr_table iscsid_thr[] = {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { iscsid_thread_static, NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iSCSIDiscoveryMethodStatic,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Static" },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { iscsid_thread_sendtgts, NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iSCSIDiscoveryMethodSendTargets,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "SendTarget" },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { iscsid_thread_slp, NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iSCSIDiscoveryMethodSLP,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "SLP" },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { iscsid_thread_isns, NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iSCSIDiscoveryMethodISNS,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "iSNS" },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { NULL, NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iSCSIDiscoveryMethodUnknown,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NULL }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * discovery method event table
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteiSCSIDiscoveryMethod_t for_failure[] = {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iSCSIDiscoveryMethodStatic,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iSCSIDiscoveryMethodSLP,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iSCSIDiscoveryMethodISNS,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iSCSIDiscoveryMethodSendTargets,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iSCSIDiscoveryMethodUnknown /* terminating value */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng/*
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * The following private tunable, set in /etc/system, e.g.,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * set iscsi:iscsi_boot_max_delay = 360
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * , provides with customer a max wait time in
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * seconds to wait for boot lun online during iscsi boot.
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * Defaults to 180s.
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Mengint iscsi_boot_max_delay = ISCSI_BOOT_DEFAULT_MAX_DELAY;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * discovery configuration semaphore
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteksema_t iscsid_config_semaphore;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Mengstatic iscsi_thread_t *iscsi_boot_wd_handle = NULL;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define CHECK_METHOD(v) ((dm & v) ? B_TRUE : B_FALSE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng/*
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * Check if IP is valid
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Mengstatic boolean_t
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Mengiscsid_ip_check(char *ip)
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng{
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng int i = 0;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (!ip)
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng return (B_FALSE);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng for (; (ip[i] == 0) && (i < IB_IP_BUFLEN); i++) {}
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (i == IB_IP_BUFLEN) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /* invalid IP address */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng return (B_FALSE);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng return (B_TRUE);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng}
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng/*
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * Make an entry for the boot target.
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * return B_TRUE upon success
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * B_FALSE if fail
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Mengstatic boolean_t
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Mengiscsid_make_entry(ib_boot_prop_t *boot_prop_entry, entry_t *entry)
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng{
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (entry == NULL || boot_prop_entry == NULL) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng return (B_FALSE);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (!iscsid_ip_check(
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (char *)&boot_prop_entry->boot_tgt.tgt_ip_u))
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng return (B_FALSE);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (boot_prop_entry->boot_tgt.sin_family != AF_INET &&
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng boot_prop_entry->boot_tgt.sin_family != AF_INET6)
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng return (B_FALSE);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng entry->e_vers = ISCSI_INTERFACE_VERSION;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng mutex_enter(&iscsi_oid_mutex);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng entry->e_oid = iscsi_oid++;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng mutex_exit(&iscsi_oid_mutex);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng entry->e_tpgt = ISCSI_DEFAULT_TPGT;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (boot_prop_entry->boot_tgt.sin_family == AF_INET) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng entry->e_u.u_in4.s_addr =
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng boot_prop_entry->boot_tgt.tgt_ip_u.u_in4.s_addr;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng entry->e_insize = sizeof (struct in_addr);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng } else {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (void) bcopy(
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng &boot_prop_entry->boot_tgt.tgt_ip_u.u_in6.s6_addr,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng entry->e_u.u_in6.s6_addr, 16);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng entry->e_insize = sizeof (struct in6_addr);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng entry->e_port = boot_prop_entry->boot_tgt.tgt_port;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng entry->e_boot = B_TRUE;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng return (B_TRUE);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng}
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng/*
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * Create the boot session
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Mengstatic void
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Mengiscsi_boot_session_create(iscsi_hba_t *ihp,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng ib_boot_prop_t *boot_prop_table)
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng{
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iSCSIDiscoveryMethod_t dm;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng entry_t e;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsi_sockaddr_t addr_dsc;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (ihp == NULL || boot_prop_table == NULL) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng return;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (!iscsid_ip_check(
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (char *)&boot_prop_table->boot_tgt.tgt_ip_u)) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng return;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (boot_prop_table->boot_tgt.tgt_name != NULL) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng dm = iSCSIDiscoveryMethodStatic |
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iSCSIDiscoveryMethodBoot;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (!iscsid_make_entry(boot_prop_table, &e))
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng return;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsid_addr_to_sockaddr(e.e_insize, &e.e_u,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng e.e_port, &addr_dsc.sin);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (void) iscsid_add(ihp, dm, &addr_dsc.sin,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (char *)boot_prop_table->boot_tgt.tgt_name,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng e.e_tpgt, &addr_dsc.sin);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng } else {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng dm = iSCSIDiscoveryMethodSendTargets |
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iSCSIDiscoveryMethodBoot;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (!iscsid_make_entry(boot_prop_table, &e))
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng return;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsid_addr_to_sockaddr(e.e_insize, &e.e_u,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng e.e_port, &addr_dsc.sin);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsid_do_sendtgts(&e);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (void) iscsid_login_tgt(ihp, NULL, dm,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng &addr_dsc.sin);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng}
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng * iscsid_init -- to initialize stuffs related to iscsi daemon,
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng * and to create boot session if needed
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteboolean_t
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Mengiscsid_init(iscsi_hba_t *ihp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng boolean_t rval = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sema_init(&iscsid_config_semaphore, 1, NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SEMA_DRIVER, NULL);
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng persistent_init();
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng iscsid_threads_create(ihp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng if (modrootloaded == 1) {
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng /* normal case, load the persistent store */
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng if (persistent_load() == B_TRUE) {
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng ihp->hba_persistent_loaded = B_TRUE;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng } else {
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng return (B_FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng if ((modrootloaded == 0) && (iscsiboot_prop != NULL)) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (!iscsid_boot_init_config(ihp)) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng rval = B_FALSE;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng } else {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsi_boot_session_create(ihp, iscsiboot_prop);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsi_boot_wd_handle =
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsi_thread_create(ihp->hba_dip,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng "BootWD", iscsid_thread_boot_wd, ihp);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (iscsi_boot_wd_handle) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng rval = iscsi_thread_start(
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsi_boot_wd_handle);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng } else {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng rval = B_FALSE;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng if (rval == B_FALSE) {
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng cmn_err(CE_NOTE, "Initializaton of iscsi boot session"
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng " partially failed");
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng return (rval);
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng}
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng/*
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng * iscsid_start -- start the iscsi initiator daemon, actually this code
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng * is just to enable discovery methods which are set enabled in
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng * persistent store, as an economic way to present the 'daemon' funtionality
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng */
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Mengboolean_t
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Mengiscsid_start(iscsi_hba_t *ihp) {
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng boolean_t rval = B_FALSE;
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng iSCSIDiscoveryMethod_t dm;
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng iSCSIDiscoveryMethod_t *fdm;
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng rval = iscsid_init_config(ihp);
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng if (rval == B_TRUE) {
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng rval = iscsid_init_targets(ihp);
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng if (rval == B_TRUE) {
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng dm = persistent_disc_meth_get();
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng rval = iscsid_enable_discovery(ihp, dm, B_TRUE);
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng if (rval == B_TRUE) {
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng iscsid_poke_discovery(ihp,
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng iSCSIDiscoveryMethodUnknown);
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng (void) iscsid_login_tgt(ihp, NULL,
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng iSCSIDiscoveryMethodUnknown, NULL);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng }
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng if (rval == B_FALSE) {
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng /*
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng * In case of failure the events still need to be sent
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng * because the door daemon will pause until all these
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng * events have occurred.
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng */
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng for (fdm = &for_failure[0]; *fdm !=
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng iSCSIDiscoveryMethodUnknown; fdm++) {
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng /* ---- Send both start and end events ---- */
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng iscsi_discovery_event(ihp, *fdm, B_TRUE);
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng iscsi_discovery_event(ihp, *fdm, B_FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng return (rval);
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng}
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng/*
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng * iscsid_stop -- stop the iscsi initiator daemon, by disabling
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng * all the discovery methods first, and then try to stop all
08dcd69c259e91563982b9e7715366f99fee816eJack Meng * related threads. This is a try-best effort, leave any 'busy' device
08dcd69c259e91563982b9e7715366f99fee816eJack Meng * (and therefore session) there and just return.
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng */
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Mengboolean_t
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Mengiscsid_stop(iscsi_hba_t *ihp) {
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng boolean_t rval = B_FALSE;
aefdd1313598221872b3e520302b40e1874f2dc7bing zhao - Sun Microsystems - Beijing China iscsi_sess_t *isp = NULL;
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng
08dcd69c259e91563982b9e7715366f99fee816eJack Meng (void) iscsid_disable_discovery(ihp, ISCSI_ALL_DISCOVERY_METHODS);
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng /* final check */
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng rw_enter(&ihp->hba_sess_list_rwlock, RW_READER);
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng if (ihp->hba_sess_list == NULL) {
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng rval = B_TRUE;
aefdd1313598221872b3e520302b40e1874f2dc7bing zhao - Sun Microsystems - Beijing China } else {
aefdd1313598221872b3e520302b40e1874f2dc7bing zhao - Sun Microsystems - Beijing China /*
aefdd1313598221872b3e520302b40e1874f2dc7bing zhao - Sun Microsystems - Beijing China * If only boot session is left, that is OK.
08dcd69c259e91563982b9e7715366f99fee816eJack Meng * Otherwise, we should report that some sessions are left.
aefdd1313598221872b3e520302b40e1874f2dc7bing zhao - Sun Microsystems - Beijing China */
aefdd1313598221872b3e520302b40e1874f2dc7bing zhao - Sun Microsystems - Beijing China rval = B_TRUE;
aefdd1313598221872b3e520302b40e1874f2dc7bing zhao - Sun Microsystems - Beijing China for (isp = ihp->hba_sess_list; isp != NULL;
aefdd1313598221872b3e520302b40e1874f2dc7bing zhao - Sun Microsystems - Beijing China isp = isp->sess_next) {
aefdd1313598221872b3e520302b40e1874f2dc7bing zhao - Sun Microsystems - Beijing China if (isp->sess_boot == B_FALSE) {
aefdd1313598221872b3e520302b40e1874f2dc7bing zhao - Sun Microsystems - Beijing China rval = B_FALSE;
aefdd1313598221872b3e520302b40e1874f2dc7bing zhao - Sun Microsystems - Beijing China break;
aefdd1313598221872b3e520302b40e1874f2dc7bing zhao - Sun Microsystems - Beijing China }
aefdd1313598221872b3e520302b40e1874f2dc7bing zhao - Sun Microsystems - Beijing China }
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng }
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng rw_exit(&ihp->hba_sess_list_rwlock);
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rval);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsid_fini -- do whatever is required to clean up
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsid_fini()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (iscsi_boot_wd_handle != NULL) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsi_thread_destroy(iscsi_boot_wd_handle);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsi_boot_wd_handle = NULL;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng iscsid_threads_destroy();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte persistent_fini();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sema_destroy(&iscsid_config_semaphore);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsid_props -- returns discovery thread information, used by ioctl code
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsid_props(iSCSIDiscoveryProperties_t *props)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iSCSIDiscoveryMethod_t dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dm = persistent_disc_meth_get();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte props->vers = ISCSI_INTERFACE_VERSION;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* ---- change once thread is implemented ---- */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte props->iSNSDiscoverySettable = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte props->SLPDiscoverySettable = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte props->StaticDiscoverySettable = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte props->SendTargetsDiscoverySettable = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte props->iSNSDiscoveryMethod = iSNSDiscoveryMethodStatic;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte props->iSNSDiscoveryEnabled = CHECK_METHOD(iSCSIDiscoveryMethodISNS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte props->StaticDiscoveryEnabled =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CHECK_METHOD(iSCSIDiscoveryMethodStatic);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte props->SendTargetsDiscoveryEnabled =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CHECK_METHOD(iSCSIDiscoveryMethodSendTargets);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte props->SLPDiscoveryEnabled = CHECK_METHOD(iSCSIDiscoveryMethodSLP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsid_enable_discovery - start specified discovery methods
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteboolean_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsid_enable_discovery(iscsi_hba_t *ihp, iSCSIDiscoveryMethod_t idm,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte boolean_t poke)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte boolean_t rval = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsid_thr_table *dt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * start the specified discovery method(s)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (dt = &iscsid_thr[0]; dt->method != iSCSIDiscoveryMethodUnknown;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dt++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (idm & dt->method) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dt->thr_id != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = iscsi_thread_start(dt->thr_id);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rval == B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (poke == B_TRUE) {
49311b3511690f5b23558b0fba067bc8067c7a87Jack Meng (void) iscsi_thread_send_wakeup(
49311b3511690f5b23558b0fba067bc8067c7a87Jack Meng dt->thr_id);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * unexpected condition. The threads for each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * discovery method should have started at
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * initialization
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(B_FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* END for() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rval);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsid_disable_discovery - stop specified discovery methods
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteboolean_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsid_disable_discovery(iscsi_hba_t *ihp, iSCSIDiscoveryMethod_t idm)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte boolean_t rval = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsid_thr_table *dt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stop the specified discovery method(s)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (dt = &iscsid_thr[0]; dt->method != iSCSIDiscoveryMethodUnknown;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dt++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (idm & dt->method) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* signal discovery event change - begin */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_discovery_event(ihp, dt->method, B_TRUE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Attempt to logout of all associated targets */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = iscsid_del(ihp, NULL, dt->method, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rval == B_TRUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Successfully logged out of targets */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dt->thr_id != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = iscsi_thread_stop(dt->thr_id);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rval == B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * signal discovery
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * event change - end
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_discovery_event(ihp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dt->method, B_FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * unexpected condition. The threads
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * for each discovery method should
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * have started at initialization
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(B_FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* signal discovery event change - end */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_discovery_event(ihp, dt->method, B_FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* END for() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rval);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsid_poke_discovery - wakeup discovery methods to find any new targets
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and wait for all discovery processes to complete.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsid_poke_discovery(iscsi_hba_t *ihp, iSCSIDiscoveryMethod_t method)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define ISCSI_DISCOVERY_DELAY 1
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iSCSIDiscoveryMethod_t dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsid_thr_table *dt;
49311b3511690f5b23558b0fba067bc8067c7a87Jack Meng boolean_t send_wakeup;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ihp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* reset discovery flags */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&ihp->hba_discovery_events_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ihp->hba_discovery_in_progress = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ihp->hba_discovery_events = iSCSIDiscoveryMethodUnknown;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&ihp->hba_discovery_events_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* start all enabled discovery methods */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dm = persistent_disc_meth_get();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (dt = &iscsid_thr[0]; dt->method != iSCSIDiscoveryMethodUnknown;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dt++) {
49311b3511690f5b23558b0fba067bc8067c7a87Jack Meng send_wakeup = B_FALSE;
49311b3511690f5b23558b0fba067bc8067c7a87Jack Meng
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((method == iSCSIDiscoveryMethodUnknown) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (method == dt->method)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((dm & dt->method) && (dt->thr_id != NULL)) {
49311b3511690f5b23558b0fba067bc8067c7a87Jack Meng if (iscsi_thread_send_wakeup(dt->thr_id) ==
49311b3511690f5b23558b0fba067bc8067c7a87Jack Meng B_TRUE) {
49311b3511690f5b23558b0fba067bc8067c7a87Jack Meng send_wakeup = B_TRUE;
49311b3511690f5b23558b0fba067bc8067c7a87Jack Meng }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
49311b3511690f5b23558b0fba067bc8067c7a87Jack Meng }
49311b3511690f5b23558b0fba067bc8067c7a87Jack Meng
49311b3511690f5b23558b0fba067bc8067c7a87Jack Meng if (send_wakeup == B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_discovery_event(ihp, dt->method, B_TRUE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_discovery_event(ihp, dt->method, B_FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&ihp->hba_discovery_events_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (ihp->hba_discovery_events != ISCSI_ALL_DISCOVERY_METHODS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&ihp->hba_discovery_events_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(SEC_TO_TICK(ISCSI_DISCOVERY_DELAY));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&ihp->hba_discovery_events_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ihp->hba_discovery_in_progress = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&ihp->hba_discovery_events_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsid_do_sendtgts - issue send targets command to the given discovery
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * address and then add the discovered targets to the discovery queue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsid_do_sendtgts(entry_t *disc_addr)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SENDTGTS_DEFAULT_NUM_TARGETS 10
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int stl_sz;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int stl_num_tgts = SENDTGTS_DEFAULT_NUM_TARGETS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sendtgts_list_t *stl_hdr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte boolean_t retry = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char inp_buf[INET6_ADDRSTRLEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte const char *ip;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ctr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsi_hba_t *ihp;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iSCSIDiscoveryMethod_t dm = iSCSIDiscoveryMethodSendTargets;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* allocate and initialize sendtargets list header */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stl_sz = sizeof (*stl_hdr) + ((stl_num_tgts - 1) *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (iscsi_sendtgts_entry_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stl_hdr = kmem_zalloc(stl_sz, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteretry_sendtgts:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stl_hdr->stl_in_cnt = stl_num_tgts;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(disc_addr, &(stl_hdr->stl_entry),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (stl_hdr->stl_entry));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stl_hdr->stl_entry.e_vers = ISCSI_INTERFACE_VERSION;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* lock interface so only one SendTargets operation occurs */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ihp = (iscsi_hba_t *)ddi_get_soft_state(iscsi_state, 0)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE, "!iscsi discovery failure - SendTargets. "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "failure to get soft state");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(stl_hdr, stl_sz);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sema_p(&ihp->hba_sendtgts_semaphore);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = iscsi_ioctl_sendtgts_get(ihp, stl_hdr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sema_v(&ihp->hba_sendtgts_semaphore);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ip = inet_ntop((disc_addr->e_insize ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (struct in_addr) ? AF_INET : AF_INET6),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &disc_addr->e_u, inp_buf, sizeof (inp_buf));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "iscsi discovery failure - SendTargets (%s)\n", ip);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(stl_hdr, stl_sz);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* check if all targets received */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stl_hdr->stl_in_cnt < stl_hdr->stl_out_cnt) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (retry == B_TRUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stl_num_tgts = stl_hdr->stl_out_cnt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(stl_hdr, stl_sz);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stl_sz = sizeof (*stl_hdr) +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((stl_num_tgts - 1) *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (iscsi_sendtgts_entry_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stl_hdr = kmem_zalloc(stl_sz, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte retry = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto retry_sendtgts;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ip = inet_ntop((disc_addr->e_insize ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (struct in_addr) ?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte AF_INET : AF_INET6), &disc_addr->e_u,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte inp_buf, sizeof (inp_buf));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE, "iscsi discovery failure - "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "SendTargets overflow (%s)\n", ip);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(stl_hdr, stl_sz);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ctr = 0; ctr < stl_hdr->stl_out_cnt; ctr++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sockaddr_t addr_dsc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sockaddr_t addr_tgt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsid_addr_to_sockaddr(disc_addr->e_insize,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &disc_addr->e_u, disc_addr->e_port, &addr_dsc.sin);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsid_addr_to_sockaddr(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stl_hdr->stl_list[ctr].ste_ipaddr.a_addr.i_insize,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &(stl_hdr->stl_list[ctr].ste_ipaddr.a_addr.i_addr),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stl_hdr->stl_list[ctr].ste_ipaddr.a_port,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &addr_tgt.sin);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (disc_addr->e_boot == B_TRUE) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng dm = dm | iSCSIDiscoveryMethodBoot;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (void) iscsid_add(ihp, dm,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &addr_dsc.sin, (char *)stl_hdr->stl_list[ctr].ste_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stl_hdr->stl_list[ctr].ste_tpgt,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &addr_tgt.sin);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(stl_hdr, stl_sz);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsid_do_isns_query_one_server(iscsi_hba_t *ihp, entry_t *isns_server)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int pg_sz, query_status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_addr_t *ap;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_portal_group_list_t *pg_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ap = (iscsi_addr_t *)kmem_zalloc(sizeof (iscsi_addr_t), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ap->a_port = isns_server->e_port;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ap->a_addr.i_insize = isns_server->e_insize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_server->e_insize == sizeof (struct in_addr)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ap->a_addr.i_addr.in4.s_addr = (isns_server->e_u.u_in4.s_addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (isns_server->e_insize == sizeof (struct in6_addr)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(&(isns_server->e_u.u_in6.s6_addr),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ap->a_addr.i_addr.in6.s6_addr, 16);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ap, sizeof (iscsi_addr_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pg_list = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte query_status = isns_query_one_server(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ap, ihp->hba_isid,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ihp->hba_name, ihp->hba_alias,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_INITIATOR_NODE_TYPE, &pg_list);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ap, sizeof (iscsi_addr_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (query_status != isns_ok || pg_list == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE1(iscsid_do_isns_query_one_server_status,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int, query_status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsid_add_pg_list_to_cache(ihp, pg_list);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pg_sz = sizeof (isns_portal_group_list_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pg_list->pg_out_cnt > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pg_sz += (pg_list->pg_out_cnt - 1) *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (isns_portal_group_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pg_list, pg_sz);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsid_do_isns_query(iscsi_hba_t *ihp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int pg_sz, query_status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_portal_group_list_t *pg_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pg_list = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte query_status = isns_query(ihp->hba_isid,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ihp->hba_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ihp->hba_alias,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_INITIATOR_NODE_TYPE,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &pg_list);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China if (pg_list == NULL) {
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China DTRACE_PROBE1(iscsid_do_isns_query_status,
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China int, query_status);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China return;
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China }
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((query_status != isns_ok &&
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China query_status != isns_op_partially_failed)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE1(iscsid_do_isns_query_status,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int, query_status);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China pg_sz = sizeof (isns_portal_group_list_t);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China if (pg_list->pg_out_cnt > 0) {
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China pg_sz += (pg_list->pg_out_cnt - 1) *
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China sizeof (isns_portal_group_t);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China }
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China kmem_free(pg_list, pg_sz);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsid_add_pg_list_to_cache(ihp, pg_list);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pg_sz = sizeof (isns_portal_group_list_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pg_list->pg_out_cnt > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pg_sz += (pg_list->pg_out_cnt - 1) *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (isns_portal_group_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pg_list, pg_sz);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsid_config_one - for the given target name, attempt
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to login to all targets associated with name. If target
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * name is not found in discovery queue, reset the discovery
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * queue, kick the discovery processes, and then retry.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NOTE: The caller of this function must hold the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsid_config_semaphore across this call.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsid_config_one(iscsi_hba_t *ihp, char *name, boolean_t protect)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng boolean_t rc = B_FALSE;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng int retry = 0;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng int lun_online = 0;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng int cur_sec = 0;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (!modrootloaded && (iscsiboot_prop != NULL)) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (!iscsi_configroot_printed) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng cmn_err(CE_NOTE, "Configuring"
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng " iSCSI boot session...");
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsi_configroot_printed = B_TRUE;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap if (iscsi_net_up == 0) {
bbe725837bc5e084e6762c7984672bc05d76baf1Jack Meng if (iscsi_net_interface(B_FALSE) ==
bbe725837bc5e084e6762c7984672bc05d76baf1Jack Meng ISCSI_STATUS_SUCCESS) {
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iscsi_net_up = 1;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap } else {
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap cmn_err(CE_WARN, "Failed to configure interface"
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap " for iSCSI boot session");
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap return;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap }
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng while (rc == B_FALSE && retry <
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsi_configroot_retry) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng rc = iscsid_login_tgt(ihp, name,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iSCSIDiscoveryMethodBoot, NULL);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (rc == B_FALSE) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /*
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * create boot session
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsi_boot_session_create(ihp,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsiboot_prop);
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng retry++;
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng continue;
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng }
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng rc = iscsid_check_active_boot_conn(ihp);
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng if (rc == B_FALSE) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /*
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng * no active connection for the boot
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng * session, retry the login until
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng * one is found or the retry count
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng * is exceeded
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng */
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng delay(SEC_TO_TICK(ISCSI_CONFIGROOT_DELAY));
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng retry++;
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng continue;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng /*
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng * The boot session has been created with active
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng * connection. If the target lun has not been online,
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng * we should wait here for a while
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng */
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng do {
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng lun_online =
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng iscsiboot_prop->boot_tgt.lun_online;
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng if (lun_online == 0) {
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng delay(SEC_TO_TICK(
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng ISCSI_CONFIGROOT_DELAY));
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng cur_sec++;
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng }
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng } while ((lun_online == 0) &&
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng (cur_sec < iscsi_boot_max_delay));
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng retry++;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (!rc) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng cmn_err(CE_WARN, "Failed to configure iSCSI"
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng " boot session");
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng } else {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng rc = iscsid_login_tgt(ihp, name, iSCSIDiscoveryMethodUnknown,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * If we didn't login to the device we might have
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * to update our discovery information and attempt
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * the login again.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (rc == B_FALSE) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /*
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * Stale /dev links can cause us to get floods
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * of config requests. Prevent these repeated
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * requests from causing unneeded discovery updates
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * if ISCSI_CONFIG_STORM_PROTECT is set.
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if ((protect == B_FALSE) ||
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (ddi_get_lbolt() > ihp->hba_config_lbolt +
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng SEC_TO_TICK(ihp->hba_config_storm_delay))) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng ihp->hba_config_lbolt = ddi_get_lbolt();
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsid_poke_discovery(ihp,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iSCSIDiscoveryMethodUnknown);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (void) iscsid_login_tgt(ihp, name,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iSCSIDiscoveryMethodUnknown, NULL);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsid_config_all - reset the discovery queue, kick the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * discovery processes, and login to all targets found
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NOTE: The caller of this function must hold the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsid_config_semaphore across this call.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsid_config_all(iscsi_hba_t *ihp, boolean_t protect)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng boolean_t rc = B_FALSE;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng int retry = 0;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng int lun_online = 0;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng int cur_sec = 0;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (!modrootloaded && iscsiboot_prop != NULL) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (!iscsi_configroot_printed) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng cmn_err(CE_NOTE, "Configuring"
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng " iSCSI boot session...");
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsi_configroot_printed = B_TRUE;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap if (iscsi_net_up == 0) {
bbe725837bc5e084e6762c7984672bc05d76baf1Jack Meng if (iscsi_net_interface(B_FALSE) ==
bbe725837bc5e084e6762c7984672bc05d76baf1Jack Meng ISCSI_STATUS_SUCCESS) {
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iscsi_net_up = 1;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap }
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng while (rc == B_FALSE && retry <
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsi_configroot_retry) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng rc = iscsid_login_tgt(ihp, NULL,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iSCSIDiscoveryMethodBoot, NULL);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (rc == B_FALSE) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /*
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * No boot session has been created.
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * We would like to create the boot
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * Session first.
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsi_boot_session_create(ihp,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsiboot_prop);
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng retry++;
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng continue;
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng }
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng rc = iscsid_check_active_boot_conn(ihp);
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng if (rc == B_FALSE) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /*
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng * no active connection for the boot
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng * session, retry the login until
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng * one is found or the retry count
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng * is exceeded
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng */
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng delay(SEC_TO_TICK(ISCSI_CONFIGROOT_DELAY));
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng retry++;
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng continue;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng /*
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng * The boot session has been created with active
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng * connection. If the target lun has not been online,
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng * we should wait here for a while
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng */
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng do {
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng lun_online =
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng iscsiboot_prop->boot_tgt.lun_online;
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng if (lun_online == 0) {
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng delay(SEC_TO_TICK(
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng ISCSI_CONFIGROOT_DELAY));
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng cur_sec++;
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng }
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng } while ((lun_online == 0) &&
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng (cur_sec < iscsi_boot_max_delay));
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng retry++;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (!rc) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng cmn_err(CE_WARN, "Failed to configure"
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng " boot session");
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng } else {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /*
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * Stale /dev links can cause us to get floods
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * of config requests. Prevent these repeated
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * requests from causing unneeded discovery updates
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * if ISCSI_CONFIG_STORM_PROTECT is set.
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if ((protect == B_FALSE) ||
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (ddi_get_lbolt() > ihp->hba_config_lbolt +
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng SEC_TO_TICK(ihp->hba_config_storm_delay))) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng ihp->hba_config_lbolt = ddi_get_lbolt();
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsid_poke_discovery(ihp,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iSCSIDiscoveryMethodUnknown);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (void) iscsid_login_tgt(ihp, NULL,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iSCSIDiscoveryMethodUnknown, NULL);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * isns_scn_callback - iSNS client received an SCN
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This code processes the iSNS client SCN events. These
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * could relate to the addition, removal, or update of a
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * logical unit.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_scn_callback(void *arg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i, pg_sz;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int qry_status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_portal_group_list_t *pg_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t scn_type;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_hba_t *ihp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (arg == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* No argument */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ihp = (iscsi_hba_t *)ddi_get_soft_state(iscsi_state, 0)) == NULL) {
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng kmem_free(arg, sizeof (isns_scn_callback_arg_t));
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng return;
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng }
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng /*
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng * All isns callbacks are from a standalone taskq
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng * therefore the blocking here doesn't affect the enable/disable
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng * of isns discovery method
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng */
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng if (iscsi_client_request_service(ihp) == B_FALSE) {
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng kmem_free(arg, sizeof (isns_scn_callback_arg_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scn_type = ((isns_scn_callback_arg_t *)arg)->scn_type;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE1(isns_scn_callback_scn_type, int, scn_type);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (scn_type) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ISNS_OBJ_ADDED - An object has been added.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISNS_OBJ_ADDED:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Query iSNS server for contact information */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pg_list = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qry_status = isns_query_one_node(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((isns_scn_callback_arg_t *)arg)->source_key_attr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ihp->hba_isid,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ihp->hba_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (uint8_t *)"",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_INITIATOR_NODE_TYPE,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &pg_list);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Verify portal group is found */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((qry_status != isns_ok &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qry_status != isns_op_partially_failed) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pg_list == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE1(pg_list,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_portal_group_list_t *, pg_list);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Add all portals for logical unit to discovery cache */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < pg_list->pg_out_cnt; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sockaddr_t addr_dsc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sockaddr_t addr_tgt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsid_addr_to_sockaddr(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pg_list->pg_list[i].isns_server_ip.i_insize,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &pg_list->pg_list[i].isns_server_ip.i_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pg_list->pg_list[i].isns_server_port,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &addr_dsc.sin);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsid_addr_to_sockaddr(pg_list->pg_list[i].insize,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &pg_list->pg_list[i].pg_ip_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pg_list->pg_list[i].pg_port, &addr_tgt.sin);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) iscsid_add(ihp, iSCSIDiscoveryMethodISNS,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &addr_dsc.sin, (char *)pg_list->pg_list[i].
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pg_iscsi_name, pg_list->pg_list[i].pg_tag,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &addr_tgt.sin);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Force target to login */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) iscsid_login_tgt(ihp, (char *)pg_list->
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pg_list[i].pg_iscsi_name, iSCSIDiscoveryMethodISNS,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pg_list != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pg_sz = sizeof (isns_portal_group_list_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pg_list->pg_out_cnt > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pg_sz += (pg_list->pg_out_cnt - 1) *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (isns_portal_group_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pg_list, pg_sz);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ISNS_OBJ_REMOVED - logical unit has been removed
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISNS_OBJ_REMOVED:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (iscsid_del(ihp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (char *)((isns_scn_callback_arg_t *)arg)->
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte source_key_attr, iSCSIDiscoveryMethodISNS, NULL) !=
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte B_TRUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE, "iscsi initiator - "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "isns remove scn failed for target %s\n",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (char *)((isns_scn_callback_arg_t *)arg)->
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte source_key_attr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ISNS_OBJ_UPDATED - logical unit has changed
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISNS_OBJ_UPDATED:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE, "iscsi initiator - "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "received iSNS update SCN for %s\n",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (char *)((isns_scn_callback_arg_t *)arg)->
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte source_key_attr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ISNS_OBJ_UNKNOWN -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE, "iscsi initiator - "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "received unknown iSNS SCN type 0x%x\n", scn_type);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng iscsi_client_release_service(ihp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(arg, sizeof (isns_scn_callback_arg_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsid_add - Creates discovered session and connection
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic boolean_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsid_add(iscsi_hba_t *ihp, iSCSIDiscoveryMethod_t method,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct sockaddr *addr_dsc, char *target_name, int tpgt,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct sockaddr *addr_tgt)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte boolean_t rtn = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sess_t *isp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_conn_t *icp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t oid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int idx;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int isid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_config_sess_t *ics;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *tmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ihp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(addr_dsc != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(target_name != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(addr_tgt != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* setup initial buffer for configured session information */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size = sizeof (*ics);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ics = kmem_zalloc(size, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ics->ics_in = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get configured sessions information */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmp = target_name;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (persistent_get_config_session(tmp, ics) == B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * No target information available check for
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * initiator information.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmp = (char *)ihp->hba_name;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (persistent_get_config_session(tmp, ics) == B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * No hba information is
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * found. So assume default
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * one session unbound behavior.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ics->ics_out = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ics->ics_bound = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (iscsiboot_prop && (ics->ics_out > 1) &&
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng !iscsi_chk_bootlun_mpxio(ihp)) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /*
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * iscsi boot with mpxio disabled
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * no need to search configured boot session
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (iscsi_cmp_boot_ini_name(tmp) ||
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsi_cmp_boot_tgt_name(tmp)) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng ics->ics_out = 1;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng ics->ics_bound = B_FALSE;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check to see if we need to get more information */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ics->ics_out > 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* record new size and free last buffer */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte idx = ics->ics_out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size = ISCSI_SESSION_CONFIG_SIZE(ics->ics_out);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ics, sizeof (*ics));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* allocate new buffer */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ics = kmem_zalloc(size, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ics->ics_in = idx;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get configured sessions information */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (persistent_get_config_session(tmp, ics) != B_TRUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE, "iscsi session(%s) - "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "unable to get configured session information\n",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte target_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ics, size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (B_FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* loop for all configured sessions */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&ihp->hba_sess_list_rwlock, RW_WRITER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (isid = 0; isid < ics->ics_out; isid++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* create or find matching session */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp = iscsi_sess_create(ihp, method, addr_dsc, target_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tpgt, isid, ISCSI_SESS_TYPE_NORMAL, &oid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isp == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* create or find matching connection */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!ISCSI_SUCCESS(iscsi_conn_create(addr_tgt, isp, &icp))) {
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /*
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * Teardown the session we just created. It can't
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * have any luns or connections associated with it
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * so this should always succeed (luckily since what
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * would we do if it failed?)
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap (void) iscsi_sess_destroy(isp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&ihp->hba_sess_list_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ics, size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rtn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsid_del - Attempts to delete all associated sessions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteboolean_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsid_del(iscsi_hba_t *ihp, char *target_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iSCSIDiscoveryMethod_t method, struct sockaddr *addr_dsc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte boolean_t rtn = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_status_t status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sess_t *isp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char name[ISCSI_MAX_NAME_LEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ihp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* target name can be NULL or !NULL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* addr_dsc can be NULL or !NULL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&ihp->hba_sess_list_rwlock, RW_WRITER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp = ihp->hba_sess_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (isp != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If no target_name is listed (meaning all targets)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or this specific target was listed. And the same
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * discovery method discovered this target then
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * continue evaulation. Otherwise fail.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((target_name == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (strcmp((char *)isp->sess_name, target_name) == 0)) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (isp->sess_discovered_by == method)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte boolean_t try_destroy;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If iSNS, SendTargets, or Static then special
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * handling for disc_addr.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((method == iSCSIDiscoveryMethodISNS) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (method == iSCSIDiscoveryMethodSendTargets)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If NULL addr_dsc (meaning all disc_addr)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or matching discovered addr.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((addr_dsc == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (bcmp(addr_dsc, &isp->sess_discovered_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SIZEOF_SOCKADDR(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &isp->sess_discovered_addr.sin)) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte try_destroy = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte try_destroy = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (method == iSCSIDiscoveryMethodStatic) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If NULL addr_dsc (meaning all disc_addr)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or matching active connection.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((addr_dsc == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((isp->sess_conn_act != NULL) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (bcmp(addr_dsc,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &isp->sess_conn_act->conn_base_addr.sin,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SIZEOF_SOCKADDR(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &isp->sess_conn_act->conn_base_addr.sin))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte == 0))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte try_destroy = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte try_destroy = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Unknown discovery specified */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte try_destroy = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (try_destroy == B_TRUE &&
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng isp->sess_boot == B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(name, (char *)isp->sess_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = iscsi_sess_destroy(isp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ISCSI_SUCCESS(status)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsid_remove_target_param(name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp = ihp->hba_sess_list;
5295a27a4fa085a76d771898093c66c844868fc1Jack Meng } else if (status == ISCSI_STATUS_BUSY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The most likely destroy failure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is that ndi/mdi offline failed.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This means that the resource is
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * in_use/busy.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
5295a27a4fa085a76d771898093c66c844868fc1Jack Meng cmn_err(CE_NOTE, "iscsi session(%d) - "
5295a27a4fa085a76d771898093c66c844868fc1Jack Meng "resource is in use\n",
5295a27a4fa085a76d771898093c66c844868fc1Jack Meng isp->sess_oid);
5295a27a4fa085a76d771898093c66c844868fc1Jack Meng isp = isp->sess_next;
5295a27a4fa085a76d771898093c66c844868fc1Jack Meng rtn = B_FALSE;
5295a27a4fa085a76d771898093c66c844868fc1Jack Meng } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE, "iscsi session(%d) - "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "session logout failed (%d)\n",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_oid, status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp = isp->sess_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp = isp->sess_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp = isp->sess_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&ihp->hba_sess_list_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rtn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsid_login_tgt - request target(s) to login
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteboolean_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsid_login_tgt(iscsi_hba_t *ihp, char *target_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iSCSIDiscoveryMethod_t method, struct sockaddr *addr_dsc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China boolean_t rtn = B_FALSE;
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China iscsi_sess_t *isp = NULL;
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China iscsi_sess_list_t *isp_list = NULL;
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China iscsi_sess_list_t *last_sess = NULL;
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China iscsi_sess_list_t *cur_sess = NULL;
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China int total = 0;
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China ddi_taskq_t *login_taskq = NULL;
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China char taskq_name[ISCSI_TH_MAX_NAME_LEN] = {0};
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China time_t time_stamp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ihp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&ihp->hba_sess_list_rwlock, RW_WRITER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Loop thru sessions */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp = ihp->hba_sess_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (isp != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte boolean_t try_online;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (!(method & iSCSIDiscoveryMethodBoot)) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (target_name == NULL) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (method == iSCSIDiscoveryMethodUnknown) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /* unknown method mean login to all */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng try_online = B_TRUE;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng } else if (isp->sess_discovered_by & method) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if ((method ==
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iSCSIDiscoveryMethodISNS) ||
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (method ==
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iSCSIDiscoveryMethodSendTargets)) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng#define SESS_DISC_ADDR isp->sess_discovered_addr.sin
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if ((addr_dsc == NULL) ||
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (bcmp(
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng &isp->sess_discovered_addr,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng addr_dsc, SIZEOF_SOCKADDR(
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng &SESS_DISC_ADDR))
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng == 0)) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /*
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * iSNS or sendtarget
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * discovery and
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * discovery address
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * is NULL or match
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng try_online = B_TRUE;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* addr_dsc not a match */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng try_online = B_FALSE;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng#undef SESS_DISC_ADDR
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng } else {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /* static configuration */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng try_online = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /* method not a match */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng try_online = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng } else if (strcmp(target_name,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (char *)isp->sess_name) == 0) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /* target_name match */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng try_online = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /* target_name not a match */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte try_online = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /*
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * online the boot session.
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (isp->sess_boot == B_TRUE) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng try_online = B_TRUE;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China if (try_online == B_TRUE &&
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China isp->sess_type == ISCSI_SESS_TYPE_NORMAL) {
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China total++;
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China /* Copy these sessions to the list. */
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China if (isp_list == NULL) {
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China isp_list =
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China (iscsi_sess_list_t *)kmem_zalloc(
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China sizeof (iscsi_sess_list_t), KM_SLEEP);
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China last_sess = isp_list;
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China last_sess->session = isp;
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China last_sess->next = NULL;
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China } else {
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China last_sess->next =
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China (iscsi_sess_list_t *)kmem_zalloc(
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China sizeof (iscsi_sess_list_t), KM_SLEEP);
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China last_sess->next->session = isp;
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China last_sess->next->next = NULL;
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China last_sess = last_sess->next;
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp = isp->sess_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China if (total > 0) {
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China time_stamp = ddi_get_time();
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China (void) snprintf(taskq_name, (ISCSI_TH_MAX_NAME_LEN - 1),
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China "login_queue.%lx", time_stamp);
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China login_taskq = ddi_taskq_create(ihp->hba_dip,
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China taskq_name, total, TASKQ_DEFAULTPRI, 0);
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China if (login_taskq == NULL) {
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China while (isp_list != NULL) {
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China cur_sess = isp_list;
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China isp_list = isp_list->next;
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China kmem_free(cur_sess, sizeof (iscsi_sess_list_t));
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China }
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China rtn = B_FALSE;
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China rw_exit(&ihp->hba_sess_list_rwlock);
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China return (rtn);
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China }
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China for (cur_sess = isp_list; cur_sess != NULL;
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China cur_sess = cur_sess->next) {
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China if (ddi_taskq_dispatch(login_taskq,
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China iscsi_sess_online, (void *)cur_sess->session,
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China DDI_SLEEP) != DDI_SUCCESS) {
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China cmn_err(CE_NOTE, "Can't dispatch the task "
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China "for login to the target: %s",
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China cur_sess->session->sess_name);
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China }
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China }
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China ddi_taskq_wait(login_taskq);
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China ddi_taskq_destroy(login_taskq);
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China while (isp_list != NULL) {
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China cur_sess = isp_list;
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China isp_list = isp_list->next;
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China kmem_free(cur_sess, sizeof (iscsi_sess_list_t));
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China }
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China }
a9ccff55d0a73a9d1d9011f705b910fba0f6e989bing zhao - Sun Microsystems - Beijing China
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&ihp->hba_sess_list_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rtn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * +--------------------------------------------------------------------+
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * | Local Helper Functions |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * +--------------------------------------------------------------------+
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsid_init_config -- initialize configuration parameters of iSCSI initiator
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic boolean_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsid_init_config(iscsi_hba_t *ihp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_param_set_t ips;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *v = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *name;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *initiatorName;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte persistent_param_t pp;
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China persistent_tunable_param_t pparam;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t param_id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* allocate memory to hold initiator names */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte initiatorName = kmem_zalloc(ISCSI_MAX_NAME_LEN, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * initialize iSCSI initiator name
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&ips, sizeof (ips));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (persistent_initiator_name_get(initiatorName,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISCSI_MAX_NAME_LEN) == B_TRUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ips.s_vers = ISCSI_INTERFACE_VERSION;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ips.s_param = ISCSI_LOGIN_PARAM_INITIATOR_NAME;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (iscsiboot_prop && !iscsi_cmp_boot_ini_name(initiatorName)) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (void) strncpy(initiatorName,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (const char *)iscsiboot_prop->boot_init.ini_name,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng ISCSI_MAX_NAME_LEN);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (void) strncpy((char *)ips.s_value.v_name,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (const char *)iscsiboot_prop->boot_init.ini_name,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng sizeof (ips.s_value.v_name));
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (void) iscsi_set_params(&ips, ihp, B_TRUE);
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China /* use default tunable value */
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China ihp->hba_tunable_params.recv_login_rsp_timeout =
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China ISCSI_DEFAULT_RX_TIMEOUT_VALUE;
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China ihp->hba_tunable_params.polling_login_delay =
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China ISCSI_DEFAULT_LOGIN_POLLING_DELAY;
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China ihp->hba_tunable_params.conn_login_max =
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China ISCSI_DEFAULT_CONN_DEFAULT_LOGIN_MAX;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng cmn_err(CE_NOTE, "Set initiator's name"
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng " from firmware");
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng } else {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (void) strncpy((char *)ips.s_value.v_name,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng initiatorName, sizeof (ips.s_value.v_name));
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (void) iscsi_set_params(&ips, ihp, B_FALSE);
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China if (persistent_get_tunable_param(initiatorName,
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China &pparam) == B_FALSE) {
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China /* use default value */
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China pparam.p_params.recv_login_rsp_timeout =
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China ISCSI_DEFAULT_RX_TIMEOUT_VALUE;
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China pparam.p_params.polling_login_delay =
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China ISCSI_DEFAULT_LOGIN_POLLING_DELAY;
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China pparam.p_params.conn_login_max =
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China ISCSI_DEFAULT_CONN_DEFAULT_LOGIN_MAX;
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China }
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China bcopy(&pparam.p_params, &ihp->hba_tunable_params,
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China sizeof (iscsi_tunable_params_t));
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * if no initiator-node name available it is most
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * likely due to a fresh install, or the persistent
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * store is not working correctly. Set
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * a default initiator name so that the initiator can
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * be brought up properly.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
329c9e3ded64bba19a3bbac9ee1a0124f04dc044Jack Meng iscsid_set_default_initiator_node_settings(ihp, B_FALSE);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (void) strncpy(initiatorName, (const char *)ihp->hba_name,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng ISCSI_MAX_NAME_LEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * initialize iSCSI initiator alias (if any)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&ips, sizeof (ips));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (persistent_alias_name_get((char *)ips.s_value.v_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (ips.s_value.v_name)) == B_TRUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ips.s_param = ISCSI_LOGIN_PARAM_INITIATOR_ALIAS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) iscsi_set_params(&ips, ihp, B_FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* EMPTY */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* No alias defined - not a problem. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * load up the overriden iSCSI initiator parameters
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte name = kmem_zalloc(ISCSI_MAX_NAME_LEN, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte persistent_param_lock();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte v = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (persistent_param_next(&v, name, &pp) == B_TRUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(name, initiatorName, ISCSI_MAX_NAME_LEN) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ips.s_oid = ihp->hba_oid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ips.s_vers = ISCSI_INTERFACE_VERSION;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (param_id = 0; param_id < ISCSI_NUM_LOGIN_PARAM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte param_id++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pp.p_bitmap & (1 << param_id)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = iscsid_copyto_param_set(param_id,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &pp.p_params, &ips);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = iscsi_set_params(&ips,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ihp, B_FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* note error but continue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Failed to set "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "param %d for OID %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ips.s_param, ips.s_oid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* END for() */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (iscsiboot_prop &&
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsi_chk_bootlun_mpxio(ihp)) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (void) iscsi_reconfig_boot_sess(ihp);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* END while() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte persistent_param_unlock();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(initiatorName, ISCSI_MAX_NAME_LEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(name, ISCSI_MAX_NAME_LEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (B_TRUE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsid_init_targets -- Load up the driver with known static targets and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * targets whose parameters have been modified.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This is done so that the CLI can find a list of targets the driver
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * currently knows about.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The driver doesn't need to log into these targets. Log in is done based
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * upon the enabled discovery methods.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic boolean_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsid_init_targets(iscsi_hba_t *ihp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *v = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *name;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_param_set_t ips;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte persistent_param_t pp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *iname;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t param_id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ihp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* allocate memory to hold target names */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte name = kmem_zalloc(ISCSI_MAX_NAME_LEN, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * load up targets whose parameters have been overriden
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* ---- only need to be set once ---- */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&ips, sizeof (ips));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ips.s_vers = ISCSI_INTERFACE_VERSION;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* allocate memory to hold initiator name */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iname = kmem_zalloc(ISCSI_MAX_NAME_LEN, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) persistent_initiator_name_get(iname, ISCSI_MAX_NAME_LEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte persistent_param_lock();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte v = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (persistent_param_next(&v, name, &pp) == B_TRUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(iname, name, ISCSI_MAX_NAME_LEN) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * target name matched initiator's name so,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * continue to next target. Initiator's
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * parmeters have already been set.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (iscsiboot_prop && iscsi_cmp_boot_tgt_name(name) &&
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng !iscsi_chk_bootlun_mpxio(ihp)) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /*
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * boot target is not mpxio enabled
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * simply ignore these overriden parameters
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng continue;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ips.s_oid = iscsi_targetparam_get_oid((unsigned char *)name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (param_id = 0; param_id < ISCSI_NUM_LOGIN_PARAM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte param_id++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pp.p_bitmap & (1 << param_id)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = iscsid_copyto_param_set(param_id,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &pp.p_params, &ips);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = iscsi_set_params(&ips,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ihp, B_FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* note error but continue ---- */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE, "Failed to set "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "param %d for OID %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ips.s_param, ips.s_oid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* END for() */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (iscsiboot_prop && iscsi_cmp_boot_tgt_name(name) &&
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsi_chk_bootlun_mpxio(ihp)) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (void) iscsi_reconfig_boot_sess(ihp);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* END while() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte persistent_param_unlock();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(iname, ISCSI_MAX_NAME_LEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(name, ISCSI_MAX_NAME_LEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (B_TRUE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsid_thread_static -- If static discovery is enabled, this routine obtains
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * all statically configured targets from the peristent store and issues a
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * login request to the driver.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsid_thread_static(iscsi_thread_t *thread, void *p)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iSCSIDiscoveryMethod_t dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte entry_t entry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char name[ISCSI_MAX_NAME_LEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *v = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_hba_t *ihp = (iscsi_hba_t *)p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (iscsi_thread_wait(thread, -1) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_discovery_event(ihp, iSCSIDiscoveryMethodStatic, B_TRUE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* ---- ensure static target discovery is enabled ---- */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dm = persistent_disc_meth_get();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((dm & iSCSIDiscoveryMethodStatic) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "iscsi discovery failure - "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "StaticTargets method is not enabled");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_discovery_event(ihp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iSCSIDiscoveryMethodStatic, B_FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * walk list of the statically configured targets from the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * persistent store
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte v = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte persistent_static_addr_lock();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (persistent_static_addr_next(&v, name, &entry) ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte B_TRUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sockaddr_t addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsid_addr_to_sockaddr(entry.e_insize,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &(entry.e_u), entry.e_port, &addr.sin);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) iscsid_add(ihp, iSCSIDiscoveryMethodStatic,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &addr.sin, name, entry.e_tpgt, &addr.sin);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte persistent_static_addr_unlock();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_discovery_event(ihp, iSCSIDiscoveryMethodStatic, B_FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsid_thread_sendtgts -- If SendTargets discovery is enabled, this routine
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * obtains all target discovery addresses configured from the peristent store
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and probe the IP/port addresses for possible targets. It will then issue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * a login request to the driver for all discoveryed targets.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsid_thread_sendtgts(iscsi_thread_t *thread, void *p)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_hba_t *ihp = (iscsi_hba_t *)p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iSCSIDiscoveryMethod_t dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte entry_t entry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *v = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (iscsi_thread_wait(thread, -1) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_discovery_event(ihp, iSCSIDiscoveryMethodSendTargets,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte B_TRUE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* ---- ensure SendTargets discovery is enabled ---- */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dm = persistent_disc_meth_get();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((dm & iSCSIDiscoveryMethodSendTargets) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "iscsi discovery failure - "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "SendTargets method is not enabled");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_discovery_event(ihp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iSCSIDiscoveryMethodSendTargets, B_FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * walk list of the SendTarget discovery addresses from the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * persistent store
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte v = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte persistent_disc_addr_lock();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (persistent_disc_addr_next(&v, &entry) == B_TRUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsid_do_sendtgts(&entry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte persistent_disc_addr_unlock();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_discovery_event(ihp, iSCSIDiscoveryMethodSendTargets,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte B_FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsid_thread_slp -- If SLP discovery is enabled, this routine provides
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the SLP discovery service.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsid_thread_slp(iscsi_thread_t *thread, void *p)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_hba_t *ihp = (iscsi_hba_t *)p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Even though we don't have support for SLP at this point
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we'll send the events if someone has enabled this thread.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If this is not done the daemon waiting for discovery to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * complete will pause forever holding up the boot process.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_discovery_event(ihp, iSCSIDiscoveryMethodSLP, B_TRUE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_discovery_event(ihp, iSCSIDiscoveryMethodSLP, B_FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (iscsi_thread_wait(thread, -1) != 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsid_thread_isns --
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsid_thread_isns(iscsi_thread_t *thread, void *ptr)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_hba_t *ihp = (iscsi_hba_t *)ptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iSCSIDiscoveryMethod_t dm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (iscsi_thread_wait(thread, -1) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_discovery_event(ihp, iSCSIDiscoveryMethodISNS, B_TRUE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* ---- ensure iSNS discovery is enabled ---- */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dm = persistent_disc_meth_get();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((dm & iSCSIDiscoveryMethodISNS) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "iscsi discovery failure - "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "iSNS method is not enabled");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_discovery_event(ihp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iSCSIDiscoveryMethodISNS, B_FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) isns_reg(ihp->hba_isid,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ihp->hba_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISCSI_MAX_NAME_LEN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ihp->hba_alias,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISCSI_MAX_NAME_LEN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_INITIATOR_NODE_TYPE,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_scn_callback);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsid_do_isns_query(ihp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_discovery_event(ihp, iSCSIDiscoveryMethodISNS, B_FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Thread stopped. Deregister from iSNS servers(s). */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) isns_dereg(ihp->hba_isid, ihp->hba_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsid_threads_create -- Creates all the discovery threads.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsid_threads_create(iscsi_hba_t *ihp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsid_thr_table *t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * start a thread for each discovery method
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (t = &iscsid_thr[0]; t->method != iSCSIDiscoveryMethodUnknown;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (t->thr_id == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t->thr_id = iscsi_thread_create(ihp->hba_dip, t->name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t->func_start, ihp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsid_threads_destroy -- Destroys all the discovery threads.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsid_threads_destroy(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsid_thr_table *t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (t = &iscsid_thr[0]; t->method != iSCSIDiscoveryMethodUnknown;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (t->thr_id != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_thread_destroy(t->thr_id);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t->thr_id = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsid_copyto_param_set - helper function for iscsid_init_params.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsid_copyto_param_set(uint32_t param_id, iscsi_login_params_t *params,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_param_set_t *ipsp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rtn = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (param_id >= ISCSI_NUM_LOGIN_PARAM) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (param_id) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Boolean parameters
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_DATA_SEQUENCE_IN_ORDER:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipsp->s_value.v_bool = params->data_pdu_in_order;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_IMMEDIATE_DATA:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipsp->s_value.v_bool = params->immediate_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_INITIAL_R2T:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipsp->s_value.v_bool = params->initial_r2t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_DATA_PDU_IN_ORDER:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipsp->s_value.v_bool = params->data_pdu_in_order;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Integer parameters
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_HEADER_DIGEST:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipsp->s_value.v_integer = params->header_digest;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_DATA_DIGEST:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipsp->s_value.v_integer = params->data_digest;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_DEFAULT_TIME_2_RETAIN:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipsp->s_value.v_integer = params->default_time_to_retain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_DEFAULT_TIME_2_WAIT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipsp->s_value.v_integer = params->default_time_to_wait;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_MAX_RECV_DATA_SEGMENT_LENGTH:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipsp->s_value.v_integer = params->max_recv_data_seg_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_FIRST_BURST_LENGTH:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipsp->s_value.v_integer = params->first_burst_length;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_MAX_BURST_LENGTH:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipsp->s_value.v_integer = params->max_burst_length;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Integer parameters which currently are unsettable
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_MAX_CONNECTIONS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_OUTSTANDING_R2T:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_ERROR_RECOVERY_LEVEL:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* ---- drop through to default case ---- */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* if all is well, set the parameter identifier */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rtn == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipsp->s_param = param_id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rtn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsid_add_pg_list_to_cache - Add portal groups in the list to the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * discovery cache.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsid_add_pg_list_to_cache(iscsi_hba_t *ihp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_portal_group_list_t *pg_list)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < pg_list->pg_out_cnt; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sockaddr_t addr_dsc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sockaddr_t addr_tgt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsid_addr_to_sockaddr(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pg_list->pg_list[i].isns_server_ip.i_insize,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &pg_list->pg_list[i].isns_server_ip.i_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pg_list->pg_list[i].isns_server_port,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &addr_dsc.sin);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsid_addr_to_sockaddr(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pg_list->pg_list[i].insize,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &pg_list->pg_list[i].pg_ip_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pg_list->pg_list[i].pg_port,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &addr_tgt.sin);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) iscsid_add(ihp, iSCSIDiscoveryMethodISNS, &addr_dsc.sin,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (char *)pg_list->pg_list[i].pg_iscsi_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pg_list->pg_list[i].pg_tag, &addr_tgt.sin);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * set_initiator_name - set default initiator name and alias.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This sets the default initiator name and alias. The
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * initiator name is composed of sun's reverse domain name
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and registration followed and a unique classifier. This
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * classifier is the mac address of the first NIC in the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * host and a timestamp to make sure the classifier is
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * unique if the NIC is moved between hosts. The alias
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is just the hostname.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
329c9e3ded64bba19a3bbac9ee1a0124f04dc044Jack Mengvoid
329c9e3ded64bba19a3bbac9ee1a0124f04dc044Jack Mengiscsid_set_default_initiator_node_settings(iscsi_hba_t *ihp, boolean_t minimal)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte time_t x;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct ether_addr eaddr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char val[10];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_chap_props_t *chap = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Set default initiator-node name */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (iscsiboot_prop && iscsiboot_prop->boot_init.ini_name != NULL) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (void) strncpy((char *)ihp->hba_name,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (const char *)iscsiboot_prop->boot_init.ini_name,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng ISCSI_MAX_NAME_LEN);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng } else {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (void) snprintf((char *)ihp->hba_name,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng ISCSI_MAX_NAME_LEN,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng "iqn.1986-03.com.sun:01:");
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (void) localetheraddr(NULL, &eaddr);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng for (i = 0; i < ETHERADDRL; i++) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (void) snprintf(val, sizeof (val), "%02x",
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng eaddr.ether_addr_octet[i]);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (void) strncat((char *)ihp->hba_name, val,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng ISCSI_MAX_NAME_LEN);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /* Set default initiator-node alias */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng x = ddi_get_time();
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (void) snprintf(val, sizeof (val), ".%lx", x);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncat((char *)ihp->hba_name, val, ISCSI_MAX_NAME_LEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (ihp->hba_alias[0] == '\0') {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (void) strncpy((char *)ihp->hba_alias,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng utsname.nodename, ISCSI_MAX_NAME_LEN);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng ihp->hba_alias_length = strlen((char *)ihp->hba_alias);
329c9e3ded64bba19a3bbac9ee1a0124f04dc044Jack Meng if (minimal == B_FALSE) {
329c9e3ded64bba19a3bbac9ee1a0124f04dc044Jack Meng (void) persistent_alias_name_set(
329c9e3ded64bba19a3bbac9ee1a0124f04dc044Jack Meng (char *)ihp->hba_alias);
329c9e3ded64bba19a3bbac9ee1a0124f04dc044Jack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
329c9e3ded64bba19a3bbac9ee1a0124f04dc044Jack Meng
329c9e3ded64bba19a3bbac9ee1a0124f04dc044Jack Meng if (minimal == B_TRUE) {
329c9e3ded64bba19a3bbac9ee1a0124f04dc044Jack Meng return;
329c9e3ded64bba19a3bbac9ee1a0124f04dc044Jack Meng }
329c9e3ded64bba19a3bbac9ee1a0124f04dc044Jack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (void) persistent_initiator_name_set((char *)ihp->hba_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Set default initiator-node CHAP settings */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (persistent_initiator_name_get((char *)ihp->hba_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISCSI_MAX_NAME_LEN) == B_TRUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte chap = (iscsi_chap_props_t *)kmem_zalloc(sizeof (*chap),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (persistent_chap_get((char *)ihp->hba_name, chap) ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy((char *)ihp->hba_name, chap->c_user,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strlen((char *)ihp->hba_name));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte chap->c_user_len = strlen((char *)ihp->hba_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) persistent_chap_set((char *)ihp->hba_name, chap);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(chap, sizeof (*chap));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsid_remove_target_param(char *name)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte persistent_param_t *pparam;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t t_oid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_config_sess_t *ics;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(name != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Remove target-param <-> target mapping.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Only remove if there is not any overridden
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * parameters in the persistent store
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pparam = (persistent_param_t *)kmem_zalloc(sizeof (*pparam), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * setup initial buffer for configured session
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ics = (iscsi_config_sess_t *)kmem_zalloc(sizeof (*ics), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ics->ics_in = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((persistent_param_get(name, pparam) == B_FALSE) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (persistent_get_config_session(name, ics) == B_FALSE)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t_oid = iscsi_targetparam_get_oid((uchar_t *)name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) iscsi_targetparam_remove_target(t_oid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pparam, sizeof (*pparam));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pparam = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ics, sizeof (*ics));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ics = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsid_addr_to_sockaddr - convert other types to struct sockaddr
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsid_addr_to_sockaddr(int src_insize, void *src_addr, int src_port,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct sockaddr *dst_addr)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT((src_insize == sizeof (struct in_addr)) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (src_insize == sizeof (struct in6_addr)));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(src_addr != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(dst_addr != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(dst_addr, sizeof (*dst_addr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* translate discovery information */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (src_insize == sizeof (struct in_addr)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct sockaddr_in *addr_in =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (struct sockaddr_in *)dst_addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte addr_in->sin_family = AF_INET;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(src_addr, &addr_in->sin_addr.s_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (struct in_addr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte addr_in->sin_port = htons(src_port);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct sockaddr_in6 *addr_in6 =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (struct sockaddr_in6 *)dst_addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte addr_in6->sin6_family = AF_INET6;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(src_addr, &addr_in6->sin6_addr.s6_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (struct in6_addr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte addr_in6->sin6_port = htons(src_port);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_discovery_event -- send event associated with discovery operations
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Each discovery event has a start and end event. Which is sent is based
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * on the boolean argument start with the obvious results.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_discovery_event(iscsi_hba_t *ihp, iSCSIDiscoveryMethod_t m,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte boolean_t start)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *subclass = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&ihp->hba_discovery_events_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (m) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case iSCSIDiscoveryMethodStatic:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (start == B_TRUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte subclass = ESC_ISCSI_STATIC_START;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ihp->hba_discovery_events |= iSCSIDiscoveryMethodStatic;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte subclass = ESC_ISCSI_STATIC_END;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case iSCSIDiscoveryMethodSendTargets:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (start == B_TRUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte subclass = ESC_ISCSI_SEND_TARGETS_START;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ihp->hba_discovery_events |=
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iSCSIDiscoveryMethodSendTargets;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte subclass = ESC_ISCSI_SEND_TARGETS_END;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case iSCSIDiscoveryMethodSLP:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (start == B_TRUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte subclass = ESC_ISCSI_SLP_START;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ihp->hba_discovery_events |= iSCSIDiscoveryMethodSLP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte subclass = ESC_ISCSI_SLP_END;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case iSCSIDiscoveryMethodISNS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (start == B_TRUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte subclass = ESC_ISCSI_ISNS_START;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ihp->hba_discovery_events |= iSCSIDiscoveryMethodISNS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte subclass = ESC_ISCSI_ISNS_END;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&ihp->hba_discovery_events_mutex);
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China iscsi_send_sysevent(ihp, EC_ISCSI, subclass, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China * iscsi_send_sysevent -- send sysevent using specified class
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing Chinavoid
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing Chinaiscsi_send_sysevent(
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China iscsi_hba_t *ihp,
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China char *eventclass,
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China char *subclass,
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China nvlist_t *np)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China (void) ddi_log_sysevent(ihp->hba_dip, DDI_VENDOR_SUNW, eventclass,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte subclass, np, NULL, DDI_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Mengstatic boolean_t
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Mengiscsid_boot_init_config(iscsi_hba_t *ihp)
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng{
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (strlen((const char *)iscsiboot_prop->boot_init.ini_name) != 0) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng bcopy(iscsiboot_prop->boot_init.ini_name,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng ihp->hba_name,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng strlen((const char *)iscsiboot_prop->boot_init.ini_name));
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /* or using default login param for boot session */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng return (B_TRUE);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng}
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Mengboolean_t
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Mengiscsi_reconfig_boot_sess(iscsi_hba_t *ihp)
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng{
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsi_config_sess_t *ics;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng int idx;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsi_sess_t *isp, *t_isp;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng int isid, size;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng char *name;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng boolean_t rtn = B_TRUE;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng uint32_t event_count;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (iscsiboot_prop == NULL) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng return (B_FALSE);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng size = sizeof (*ics);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng ics = kmem_zalloc(size, KM_SLEEP);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng ics->ics_in = 1;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /* get information of number of sessions to be configured */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng name = (char *)iscsiboot_prop->boot_tgt.tgt_name;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (persistent_get_config_session(name, ics) == B_FALSE) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /*
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * No target information available to check
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * initiator information. Assume one session
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * by default.
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng name = (char *)iscsiboot_prop->boot_init.ini_name;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (persistent_get_config_session(name, ics) == B_FALSE) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng ics->ics_out = 1;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng ics->ics_bound = B_TRUE;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /* get necessary information */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (ics->ics_out > 1) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng idx = ics->ics_out;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng size = ISCSI_SESSION_CONFIG_SIZE(ics->ics_out);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng kmem_free(ics, sizeof (*ics));
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng ics = kmem_zalloc(size, KM_SLEEP);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng ics->ics_in = idx;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /* get configured sessions information */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (persistent_get_config_session((char *)name,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng ics) != B_TRUE) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng cmn_err(CE_NOTE, "session(%s) - "
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng "failed to setup multiple sessions",
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng name);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng kmem_free(ics, size);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng return (B_FALSE);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /* create a temporary session to keep boot session connective */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng t_isp = iscsi_add_boot_sess(ihp, ISCSI_MAX_CONFIG_SESSIONS);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (t_isp == NULL) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng cmn_err(CE_NOTE, "session(%s) - "
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng "failed to setup multiple sessions", name);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng rw_exit(&ihp->hba_sess_list_rwlock);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng kmem_free(ics, size);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng return (B_FALSE);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /* destroy all old boot sessions */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng rw_enter(&ihp->hba_sess_list_rwlock, RW_WRITER);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng isp = ihp->hba_sess_list;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng while (isp != NULL) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (iscsi_chk_bootlun_mpxio(ihp) && isp->sess_boot) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (isp->sess_isid[5] != ISCSI_MAX_CONFIG_SESSIONS) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /*
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * destroy all stale sessions
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * except temporary boot session
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (ISCSI_SUCCESS(iscsi_sess_destroy(
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng isp))) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng isp = ihp->hba_sess_list;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng } else {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /*
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * couldn't destroy stale sessions
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * at least poke it to disconnect
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng */
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng event_count = atomic_inc_32_nv(
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng &isp->sess_state_event_count);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_enter_state_zone(isp);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsi_sess_state_machine(isp,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng ISCSI_SESS_EVENT_N7, event_count);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_exit_state_zone(isp);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng isp = isp->sess_next;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng cmn_err(CE_NOTE, "session(%s) - "
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng "failed to setup multiple"
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng " sessions", name);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng } else {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng isp = isp->sess_next;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng } else {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng isp = isp->sess_next;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng rw_exit(&ihp->hba_sess_list_rwlock);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng for (isid = 0; isid < ics->ics_out; isid++) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng isp = iscsi_add_boot_sess(ihp, isid);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (isp == NULL) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng cmn_err(CE_NOTE, "session(%s) - failed to setup"
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng " multiple sessions", name);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng rtn = B_FALSE;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng break;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (!rtn && (isid == 0)) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /*
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * fail to create any new boot session
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * so only the temporary session is alive
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * quit without destroying it
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng kmem_free(ics, size);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng return (rtn);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng rw_enter(&ihp->hba_sess_list_rwlock, RW_WRITER);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (!ISCSI_SUCCESS(iscsi_sess_destroy(t_isp))) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /* couldn't destroy temp boot session */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng cmn_err(CE_NOTE, "session(%s) - "
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng "failed to setup multiple sessions", name);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng rw_exit(&ihp->hba_sess_list_rwlock);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng rtn = B_FALSE;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng rw_exit(&ihp->hba_sess_list_rwlock);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng kmem_free(ics, size);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng return (rtn);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng}
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Mengstatic iscsi_sess_t *
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Mengiscsi_add_boot_sess(iscsi_hba_t *ihp, int isid)
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng{
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsi_sess_t *isp;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsi_conn_t *icp;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng uint_t oid;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsi_sockaddr_t addr_dst;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng addr_dst.sin.sa_family = iscsiboot_prop->boot_tgt.sin_family;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (addr_dst.sin.sa_family == AF_INET) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng bcopy(&iscsiboot_prop->boot_tgt.tgt_ip_u.u_in4.s_addr,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng &addr_dst.sin4.sin_addr.s_addr, sizeof (struct in_addr));
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng addr_dst.sin4.sin_port =
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng htons(iscsiboot_prop->boot_tgt.tgt_port);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng } else {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng bcopy(&iscsiboot_prop->boot_tgt.tgt_ip_u.u_in6.s6_addr,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng &addr_dst.sin6.sin6_addr.s6_addr,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng sizeof (struct in6_addr));
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng addr_dst.sin6.sin6_port =
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng htons(iscsiboot_prop->boot_tgt.tgt_port);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng rw_enter(&ihp->hba_sess_list_rwlock, RW_WRITER);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng isp = iscsi_sess_create(ihp,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iSCSIDiscoveryMethodBoot|iSCSIDiscoveryMethodStatic,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (struct sockaddr *)&addr_dst,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (char *)iscsiboot_prop->boot_tgt.tgt_name,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng ISCSI_DEFAULT_TPGT, isid, ISCSI_SESS_TYPE_NORMAL, &oid);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (isp == NULL) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /* create temp booting session failed */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng rw_exit(&ihp->hba_sess_list_rwlock);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng return (NULL);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng isp->sess_boot = B_TRUE;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (!ISCSI_SUCCESS(iscsi_conn_create((struct sockaddr *)&addr_dst,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng isp, &icp))) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng rw_exit(&ihp->hba_sess_list_rwlock);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng return (NULL);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng rw_exit(&ihp->hba_sess_list_rwlock);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /* now online created session */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (iscsid_login_tgt(ihp, (char *)iscsiboot_prop->boot_tgt.tgt_name,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iSCSIDiscoveryMethodBoot|iSCSIDiscoveryMethodStatic,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (struct sockaddr *)&addr_dst) == B_FALSE) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng return (NULL);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng return (isp);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng}
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Mengstatic void
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Mengiscsid_thread_boot_wd(iscsi_thread_t *thread, void *p)
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng{
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng int rc = 1;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsi_hba_t *ihp = (iscsi_hba_t *)p;
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng boolean_t reconfigured = B_FALSE;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng while (rc != 0) {
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng if (iscsiboot_prop && (modrootloaded == 1)) {
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng if (ihp->hba_persistent_loaded == B_FALSE) {
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng if (persistent_load() == B_TRUE) {
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng ihp->hba_persistent_loaded = B_TRUE;
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng }
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng }
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng if ((ihp->hba_persistent_loaded == B_TRUE) &&
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng (reconfigured == B_FALSE)) {
169c6dc41c606ed05ea28b904d8c46238686b206Jack Meng if (iscsi_chk_bootlun_mpxio(ihp) == B_TRUE) {
169c6dc41c606ed05ea28b904d8c46238686b206Jack Meng (void) iscsi_reconfig_boot_sess(ihp);
169c6dc41c606ed05ea28b904d8c46238686b206Jack Meng iscsid_poke_discovery(ihp,
169c6dc41c606ed05ea28b904d8c46238686b206Jack Meng iSCSIDiscoveryMethodUnknown);
169c6dc41c606ed05ea28b904d8c46238686b206Jack Meng (void) iscsid_login_tgt(ihp, NULL,
169c6dc41c606ed05ea28b904d8c46238686b206Jack Meng iSCSIDiscoveryMethodUnknown, NULL);
169c6dc41c606ed05ea28b904d8c46238686b206Jack Meng }
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng reconfigured = B_TRUE;
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng break;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng rc = iscsi_thread_wait(thread, SEC_TO_TICK(1));
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng}
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Mengboolean_t
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Mengiscsi_cmp_boot_tgt_name(char *name)
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng{
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (iscsiboot_prop && (strncmp((const char *)name,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (const char *)iscsiboot_prop->boot_tgt.tgt_name,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng ISCSI_MAX_NAME_LEN) == 0)) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng return (B_TRUE);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng } else {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng return (B_FALSE);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng}
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Mengboolean_t
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Mengiscsi_cmp_boot_ini_name(char *name)
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng{
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (iscsiboot_prop && (strncmp((const char *)name,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (const char *)iscsiboot_prop->boot_init.ini_name,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng ISCSI_MAX_NAME_LEN) == 0)) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng return (B_TRUE);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng } else {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng return (B_FALSE);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng}
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Mengboolean_t
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Mengiscsi_chk_bootlun_mpxio(iscsi_hba_t *ihp)
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng{
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsi_sess_t *isp;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsi_lun_t *ilp;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng isp = ihp->hba_sess_list;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng boolean_t tgt_mpxio_enabled = B_FALSE;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng boolean_t bootlun_found = B_FALSE;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng uint16_t lun_num;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (iscsiboot_prop == NULL) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng return (B_FALSE);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (!ihp->hba_mpxio_enabled) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng return (B_FALSE);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng lun_num = *((uint64_t *)(iscsiboot_prop->boot_tgt.tgt_boot_lun));
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng while (isp != NULL) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if ((strncmp((char *)isp->sess_name,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (const char *)iscsiboot_prop->boot_tgt.tgt_name,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng ISCSI_MAX_NAME_LEN) == 0) &&
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (isp->sess_boot == B_TRUE)) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /*
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * found boot session.
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * check its mdi path info is null or not
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng ilp = isp->sess_lun_list;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng while (ilp != NULL) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (lun_num == ilp->lun_num) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (ilp->lun_pip) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng tgt_mpxio_enabled = B_TRUE;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng bootlun_found = B_TRUE;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng ilp = ilp->lun_next;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng isp = isp->sess_next;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (bootlun_found) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng return (tgt_mpxio_enabled);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng } else {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /*
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * iscsiboot_prop not NULL while no boot lun found
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * in most cases this is none iscsi boot while iscsiboot_prop
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * is not NULL, in this scenario return iscsi HBA's mpxio config
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng return (ihp->hba_mpxio_enabled);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng}
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Mengstatic boolean_t
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Mengiscsid_check_active_boot_conn(iscsi_hba_t *ihp)
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng{
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng iscsi_sess_t *isp = NULL;
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng iscsi_conn_t *icp = NULL;
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng rw_enter(&ihp->hba_sess_list_rwlock, RW_READER);
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng isp = ihp->hba_sess_list;
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng while (isp != NULL) {
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng if (isp->sess_boot == B_TRUE) {
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng rw_enter(&isp->sess_conn_list_rwlock, RW_READER);
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng icp = isp->sess_conn_list;
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng while (icp != NULL) {
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng if (icp->conn_state ==
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng ISCSI_CONN_STATE_LOGGED_IN) {
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng rw_exit(&isp->sess_conn_list_rwlock);
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng rw_exit(&ihp->hba_sess_list_rwlock);
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng return (B_TRUE);
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng }
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng icp = icp->conn_next;
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng }
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng rw_exit(&isp->sess_conn_list_rwlock);
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng }
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng isp = isp->sess_next;
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng }
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng rw_exit(&ihp->hba_sess_list_rwlock);
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng return (B_FALSE);
f53e1f190fa4dbfc4440b8598a0d6925192bdc54Jack Meng}