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/*
5295a27a4fa085a76d771898093c66c844868fc1Jack Meng * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iSCSI logical unit interfaces
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "iscsi.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/fs/dv_node.h> /* devfs_clean */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng#include <sys/bootprops.h>
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China#include <sys/sysevent/eventdefs.h>
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China#include <sys/sysevent/dev.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* tpgt bytes in string form */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define TPGT_EXT_SIZE 5
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* logical unit number bytes in string form */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define LUN_EXT_SIZE 10
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Addition addr size of size of ',' + max str form of tpgt (2 bytes) +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ',' + max str form of logical unit number (4 bytes).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define ADDR_EXT_SIZE (1 + TPGT_EXT_SIZE + 1 + LUN_EXT_SIZE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* internal interfaces */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic iscsi_status_t iscsi_lun_virt_create(iscsi_sess_t *isp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t lun_num, iscsi_lun_t *ilp, struct scsi_inquiry *inq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic iscsi_status_t iscsi_lun_phys_create(iscsi_sess_t *isp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t lun_num, iscsi_lun_t *ilp, struct scsi_inquiry *inq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern dev_info_t *scsi_vhci_dip;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Mengextern ib_boot_prop_t *iscsiboot_prop;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * +--------------------------------------------------------------------+
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * | External Connection Interfaces |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * +--------------------------------------------------------------------+
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_lun_create - This function will create a lun mapping.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * logic specific to MPxIO vs. NDI node creation is switched
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * out to a helper function.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_lun_create(iscsi_sess_t *isp, uint16_t lun_num, uint8_t lun_addr_type,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct scsi_inquiry *inq, char *guid)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_status_t rtn = ISCSI_STATUS_INTERNAL_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_hba_t *ihp = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_lun_t *ilp = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_lun_t *ilp_tmp = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *addr = NULL;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng uint16_t boot_lun_num = 0;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng uint64_t *lun_num_ptr = NULL;
b7a3828569701cd12060a582d45fff67c3ef4fa2bing zhao - Sun Microsystems - Beijing China uint32_t oid_tmp = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(isp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ihp = isp->sess_hba;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ihp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
b7a3828569701cd12060a582d45fff67c3ef4fa2bing zhao - Sun Microsystems - Beijing China mutex_enter(&iscsi_oid_mutex);
b7a3828569701cd12060a582d45fff67c3ef4fa2bing zhao - Sun Microsystems - Beijing China oid_tmp = iscsi_oid++;
b7a3828569701cd12060a582d45fff67c3ef4fa2bing zhao - Sun Microsystems - Beijing China mutex_exit(&iscsi_oid_mutex);
b7a3828569701cd12060a582d45fff67c3ef4fa2bing zhao - Sun Microsystems - Beijing China
b7a3828569701cd12060a582d45fff67c3ef4fa2bing zhao - Sun Microsystems - Beijing China rw_enter(&isp->sess_lun_list_rwlock, RW_WRITER);
b7a3828569701cd12060a582d45fff67c3ef4fa2bing zhao - Sun Microsystems - Beijing China /*
b7a3828569701cd12060a582d45fff67c3ef4fa2bing zhao - Sun Microsystems - Beijing China * Check whether it has already existed in the list.
b7a3828569701cd12060a582d45fff67c3ef4fa2bing zhao - Sun Microsystems - Beijing China */
b7a3828569701cd12060a582d45fff67c3ef4fa2bing zhao - Sun Microsystems - Beijing China for (ilp_tmp = isp->sess_lun_list; ilp_tmp != NULL;
b7a3828569701cd12060a582d45fff67c3ef4fa2bing zhao - Sun Microsystems - Beijing China ilp_tmp = ilp_tmp->lun_next) {
b7a3828569701cd12060a582d45fff67c3ef4fa2bing zhao - Sun Microsystems - Beijing China if (ilp_tmp->lun_num == lun_num) {
b7a3828569701cd12060a582d45fff67c3ef4fa2bing zhao - Sun Microsystems - Beijing China /*
b7a3828569701cd12060a582d45fff67c3ef4fa2bing zhao - Sun Microsystems - Beijing China * The logic unit has already existed in the list,
b7a3828569701cd12060a582d45fff67c3ef4fa2bing zhao - Sun Microsystems - Beijing China * return with success.
b7a3828569701cd12060a582d45fff67c3ef4fa2bing zhao - Sun Microsystems - Beijing China */
b7a3828569701cd12060a582d45fff67c3ef4fa2bing zhao - Sun Microsystems - Beijing China rw_exit(&isp->sess_lun_list_rwlock);
b7a3828569701cd12060a582d45fff67c3ef4fa2bing zhao - Sun Microsystems - Beijing China return (ISCSI_STATUS_SUCCESS);
b7a3828569701cd12060a582d45fff67c3ef4fa2bing zhao - Sun Microsystems - Beijing China }
b7a3828569701cd12060a582d45fff67c3ef4fa2bing zhao - Sun Microsystems - Beijing China }
b7a3828569701cd12060a582d45fff67c3ef4fa2bing zhao - Sun Microsystems - Beijing China
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte addr = kmem_zalloc((strlen((char *)isp->sess_name) +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ADDR_EXT_SIZE + 1), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) snprintf(addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (strlen((char *)isp->sess_name) +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ADDR_EXT_SIZE + 1),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "%02X%02X%s%04X,%d", isp->sess_isid[4],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_isid[5], isp->sess_name,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng isp->sess_tpgt_nego & 0xFFFF, lun_num);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* allocate space for lun struct */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp = kmem_zalloc(sizeof (iscsi_lun_t), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->lun_sig = ISCSI_SIG_LUN;
91dae09ce7f46c6f5f967f47a96f652d2c5f9bb4bing zhao - Sun Microsystems - Beijing China ilp->lun_state &= ISCSI_LUN_STATE_CLEAR;
91dae09ce7f46c6f5f967f47a96f652d2c5f9bb4bing zhao - Sun Microsystems - Beijing China ilp->lun_state |= ISCSI_LUN_STATE_OFFLINE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* initialize common LU information */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->lun_num = lun_num;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->lun_addr_type = lun_addr_type;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->lun_sess = isp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->lun_addr = addr;
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China ilp->lun_type = inq->inq_dtype & DTYPE_MASK;
b7a3828569701cd12060a582d45fff67c3ef4fa2bing zhao - Sun Microsystems - Beijing China ilp->lun_oid = oid_tmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(inq->inq_vid, ilp->lun_vid, sizeof (inq->inq_vid));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(inq->inq_pid, ilp->lun_pid, sizeof (inq->inq_pid));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* store GUID if valid one exists */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (guid != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->lun_guid_size = strlen(guid) + 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->lun_guid = kmem_zalloc(ilp->lun_guid_size, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(ilp->lun_guid, guid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->lun_guid_size = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->lun_guid = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We need to add the lun to our lists now because during the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * lun creation we will get called back into multiple times
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * depending on the createion type. These callbacks will
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * occur via our tran_init_lun, tran_get_name, tran_get_bus_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * tran_init_pkt, tran_start.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isp->sess_lun_list == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_lun_list = ilp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->lun_next = isp->sess_lun_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_lun_list = ilp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Attempt to create a scsi_vhci binding if GUID is available */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ihp->hba_mpxio_enabled == B_TRUE) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (guid != NULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = iscsi_lun_virt_create(isp, lun_num, ilp, inq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!ISCSI_SUCCESS(rtn)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* unable to bind under scsi_vhci, failback to ndi */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = iscsi_lun_phys_create(isp, lun_num, ilp, inq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If NOT successful we need to remove the lun from the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * session and free any related resources.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!ISCSI_SUCCESS(rtn)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilp == isp->sess_lun_list) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* if head, set head to our next */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_lun_list = ilp->lun_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* if not head, set prev lun's next to our next */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ilp_tmp = isp->sess_lun_list; ilp_tmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp_tmp = ilp_tmp->lun_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilp_tmp->lun_next == ilp) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp_tmp->lun_next = ilp->lun_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ilp->lun_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (strlen((char *)isp->sess_name) +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ADDR_EXT_SIZE + 1));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->lun_addr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilp->lun_guid != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ilp->lun_guid, ilp->lun_guid_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->lun_guid = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ilp, sizeof (iscsi_lun_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
91dae09ce7f46c6f5f967f47a96f652d2c5f9bb4bing zhao - Sun Microsystems - Beijing China ilp->lun_state &= ISCSI_LUN_STATE_CLEAR;
91dae09ce7f46c6f5f967f47a96f652d2c5f9bb4bing zhao - Sun Microsystems - Beijing China ilp->lun_state |= ISCSI_LUN_STATE_ONLINE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->lun_time_online = ddi_get_time();
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /* Check whether this is the required LUN for iscsi boot */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (iscsiboot_prop != NULL && isp->sess_boot == B_TRUE &&
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsiboot_prop->boot_tgt.lun_online == 0) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng lun_num_ptr =
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (uint64_t *)iscsiboot_prop->boot_tgt.tgt_boot_lun;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng boot_lun_num = (uint16_t)(*lun_num_ptr);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (boot_lun_num == ilp->lun_num) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /*
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * During iscsi boot, the boot lun has been
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * online, we should set the "online flag".
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsiboot_prop->boot_tgt.lun_online = 1;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&isp->sess_lun_list_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rtn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_lun_destroy - offline and remove lun
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This interface is called when a name service change has
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * occured and the storage is no longer available to this
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * initiator. This function will offline and free the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * solaris node resources. Then it will free all iscsi lun
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * resources.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function can fail with ISCSI_STATUS_BUSY if the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * logical unit is in use. The user should unmount or
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * close the device and perform the nameservice operation
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * again if this occurs.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_lun_destroy(iscsi_hba_t *ihp, iscsi_lun_t *ilp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_status_t status = ISCSI_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sess_t *isp = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_lun_t *t_ilp = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ilp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp = ilp->lun_sess;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(isp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* attempt to offline and free solaris node */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = iscsi_lun_offline(ihp, ilp, B_TRUE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* If we successfully unplumbed the lun remove it from our lists */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ISCSI_SUCCESS(status)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isp->sess_lun_list == ilp) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* target first item in list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_lun_list = ilp->lun_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * search session list for ilp pointing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to lun being removed. Then
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * update that luns next pointer.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t_ilp = isp->sess_lun_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (t_ilp->lun_next != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (t_ilp->lun_next == ilp) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t_ilp = t_ilp->lun_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (t_ilp->lun_next == ilp) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t_ilp->lun_next = ilp->lun_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* couldn't find session */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* release its memory */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ilp->lun_addr, (strlen((char *)isp->sess_name) +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ADDR_EXT_SIZE + 1));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->lun_addr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilp->lun_guid != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ilp->lun_guid, ilp->lun_guid_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->lun_guid = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ilp, sizeof (iscsi_lun_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * +--------------------------------------------------------------------+
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * | External Logical Unit Interfaces |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * +--------------------------------------------------------------------+
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_lun_virt_create - Creates solaris logical unit via MDI
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic iscsi_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_lun_virt_create(iscsi_sess_t *isp, uint16_t lun_num, iscsi_lun_t *ilp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct scsi_inquiry *inq)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_status_t rtn = ISCSI_STATUS_INTERNAL_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int mdi_rtn = MDI_FAILURE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_hba_t *ihp = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mdi_pathinfo_t *pip = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *nodename = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char **compatible = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ncompatible = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int circ = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(isp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ilp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ihp = isp->sess_hba;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ihp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Generate compatible property
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_hba_nodename_compatible_get(inq, "vhci",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte inq->inq_dtype, NULL, &nodename, &compatible, &ncompatible);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* if nodename can't be determined then print a message and skip it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nodename == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN, "iscsi driver found no compatible driver "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "for %s lun %d dtype:0x%02x", isp->sess_name, lun_num,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte inq->inq_dtype);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISCSI_STATUS_INTERNAL_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ndi_devi_enter(scsi_vhci_dip, &circ);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mdi_rtn = mdi_pi_alloc_compatible(ihp->hba_dip, nodename,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->lun_guid, ilp->lun_addr, compatible, ncompatible,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0, &pip);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mdi_rtn == MDI_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mdi_pi_set_phci_private(pip, (caddr_t)ilp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mdi_prop_update_string(pip, MDI_GUID,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->lun_guid) != DDI_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN, "iscsi driver unable to create "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "property for %s lun %d (MDI_GUID)",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_name, lun_num);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mdi_rtn = MDI_FAILURE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto virt_create_done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mdi_prop_update_int(pip, TARGET_PROP,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_oid) != DDI_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN, "iscsi driver unable to create "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "property for %s lun %d (TARGET_PROP)",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_name, lun_num);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mdi_rtn = MDI_FAILURE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto virt_create_done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mdi_prop_update_int(pip, LUN_PROP,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->lun_num) != DDI_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN, "iscsi driver unable to create "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "property for %s lun %d (LUN_PROP)",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_name, lun_num);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mdi_rtn = MDI_FAILURE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto virt_create_done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mdi_prop_update_string_array(pip, "compatible",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte compatible, ncompatible) !=
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DDI_PROP_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN, "iscsi driver unable to create "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "property for %s lun %d (COMPATIBLE)",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_name, lun_num);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mdi_rtn = MDI_FAILURE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto virt_create_done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mdi_rtn = mdi_pi_online(pip, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mdi_rtn == MDI_NOT_SUPPORTED) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mdi_rtn = MDI_FAILURE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto virt_create_done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->lun_pip = pip;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->lun_dip = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevirt_create_done:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pip && mdi_rtn != MDI_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->lun_pip = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->lun_dip = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) mdi_prop_remove(pip, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) mdi_pi_free(pip, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = ISCSI_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ndi_devi_exit(scsi_vhci_dip, circ);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_hba_nodename_compatible_free(nodename, compatible);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rtn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_lun_phys_create - creates solaris logical unit via NDI
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic iscsi_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_lun_phys_create(iscsi_sess_t *isp, uint16_t lun_num,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_lun_t *ilp, struct scsi_inquiry *inq)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_status_t rtn = ISCSI_STATUS_INTERNAL_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ndi_rtn = NDI_FAILURE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_hba_t *ihp = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dev_info_t *lun_dip = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *nodename = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char **compatible = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ncompatible = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *scsi_binding_set = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char instance[32];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int circ = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(isp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ilp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ihp = isp->sess_hba;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ihp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(inq != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get the 'scsi-binding-set' property */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_prop_lookup_string(DDI_DEV_T_ANY, isp->sess_hba->hba_dip,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DDI_PROP_NOTPROM | DDI_PROP_DONTPASS, "scsi-binding-set",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &scsi_binding_set) != DDI_PROP_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_binding_set = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* generate compatible property */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_hba_nodename_compatible_get(inq, scsi_binding_set,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte inq->inq_dtype, NULL, &nodename, &compatible, &ncompatible);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scsi_binding_set)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ddi_prop_free(scsi_binding_set);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* if nodename can't be determined then print a message and skip it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nodename == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN, "iscsi driver found no compatible driver "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "for %s lun %d", isp->sess_name, lun_num);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISCSI_STATUS_INTERNAL_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ndi_devi_enter(ihp->hba_dip, &circ);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ndi_rtn = ndi_devi_alloc(ihp->hba_dip, nodename,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DEVI_SID_NODEID, &lun_dip);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* if lun alloc success, set props */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ndi_rtn == NDI_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ndi_prop_update_int(DDI_DEV_T_NONE,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lun_dip, TARGET_PROP, (int)isp->sess_oid) !=
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DDI_PROP_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN, "iscsi driver unable to create "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "property for %s lun %d (TARGET_PROP)",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_name, lun_num);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ndi_rtn = NDI_FAILURE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto phys_create_done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ndi_prop_update_int(DDI_DEV_T_NONE,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lun_dip, LUN_PROP, (int)ilp->lun_num) !=
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DDI_PROP_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN, "iscsi driver unable to create "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "property for %s lun %d (LUN_PROP)",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_name, lun_num);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ndi_rtn = NDI_FAILURE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto phys_create_done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ndi_prop_update_string_array(DDI_DEV_T_NONE,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lun_dip, "compatible", compatible, ncompatible)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte != DDI_PROP_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN, "iscsi driver unable to create "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "property for %s lun %d (COMPATIBLE)",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_name, lun_num);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ndi_rtn = NDI_FAILURE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto phys_create_done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortephys_create_done:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* If props were setup ok, online the lun */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ndi_rtn == NDI_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Try to online the new node */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ndi_rtn = ndi_devi_online(lun_dip, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* If success set rtn flag, else unwire alloc'd lun */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ndi_rtn == NDI_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = ISCSI_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Assign the instance number for the dev_link
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * generator. This will ensure the link name is
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * unique and persistent across reboots.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) snprintf(instance, 32, "%d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ddi_get_instance(lun_dip));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ndi_prop_update_string(DDI_DEV_T_NONE,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lun_dip, NDI_GUID, instance);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN, "iscsi driver unable to online "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "%s lun %d", isp->sess_name, lun_num);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ndi_prop_remove_all(lun_dip);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ndi_devi_free(lun_dip);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ndi_devi_exit(ihp->hba_dip, circ);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->lun_dip = lun_dip;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->lun_pip = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_hba_nodename_compatible_free(nodename, compatible);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rtn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_lun_online - _di_online logical unit
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This is called after a path has recovered it will cause
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * an offline path to become online/active again.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_lun_online(iscsi_hba_t *ihp, iscsi_lun_t *ilp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng int circ = 0;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng int rval = 0;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng uint64_t *lun_num_ptr = NULL;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng uint16_t boot_lun_num = 0;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsi_sess_t *isp = NULL;
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China boolean_t online = B_FALSE;
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China nvlist_t *attr_list = NULL;
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China char *pathname = NULL;
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China dev_info_t *lun_dip = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ilp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT((ilp->lun_pip != NULL) || (ilp->lun_dip != NULL));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilp->lun_pip != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ndi_devi_enter(scsi_vhci_dip, &circ);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = mdi_pi_online(ilp->lun_pip, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ndi_devi_exit(scsi_vhci_dip, circ);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rval == MDI_SUCCESS) {
91dae09ce7f46c6f5f967f47a96f652d2c5f9bb4bing zhao - Sun Microsystems - Beijing China ilp->lun_state &= ISCSI_LUN_STATE_CLEAR;
91dae09ce7f46c6f5f967f47a96f652d2c5f9bb4bing zhao - Sun Microsystems - Beijing China ilp->lun_state |= ISCSI_LUN_STATE_ONLINE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->lun_time_online = ddi_get_time();
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China online = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (ilp->lun_dip != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ndi_devi_enter(ihp->hba_dip, &circ);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = ndi_devi_online(ilp->lun_dip, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ndi_devi_exit(ihp->hba_dip, circ);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rval == NDI_SUCCESS) {
91dae09ce7f46c6f5f967f47a96f652d2c5f9bb4bing zhao - Sun Microsystems - Beijing China ilp->lun_state &= ISCSI_LUN_STATE_CLEAR;
91dae09ce7f46c6f5f967f47a96f652d2c5f9bb4bing zhao - Sun Microsystems - Beijing China ilp->lun_state |= ISCSI_LUN_STATE_ONLINE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->lun_time_online = ddi_get_time();
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China online = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /* Check whether this is the required LUN for iscsi boot */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (iscsiboot_prop != NULL &&
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsiboot_prop->boot_tgt.lun_online == 0) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng isp = ilp->lun_sess;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (isp->sess_boot == B_TRUE) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng lun_num_ptr =
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng (uint64_t *)iscsiboot_prop->boot_tgt.tgt_boot_lun;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng boot_lun_num = (uint16_t)(*lun_num_ptr);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (boot_lun_num == ilp->lun_num) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /*
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * During iscsi boot, the boot lun has been
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * online, we should set the "online flag".
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsiboot_prop->boot_tgt.lun_online = 1;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China /*
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China * If the LUN has been online and it is a disk,
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China * send out a system event.
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China */
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China if (online == B_TRUE && ilp->lun_type == DTYPE_DIRECT) {
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China if (nvlist_alloc(&attr_list, NV_UNIQUE_NAME_TYPE, KM_SLEEP) !=
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China DDI_SUCCESS) {
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China return;
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China }
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China if (ilp->lun_pip != NULL) {
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China lun_dip = mdi_pi_get_client(ilp->lun_pip);
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China } else {
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China lun_dip = ilp->lun_dip;
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China }
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China pathname = kmem_zalloc(MAXNAMELEN + 1, KM_SLEEP);
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China (void) ddi_pathname(lun_dip, pathname);
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China if (nvlist_add_string(attr_list, DEV_PHYS_PATH, pathname) !=
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China DDI_SUCCESS) {
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China nvlist_free(attr_list);
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China kmem_free(pathname, MAXNAMELEN + 1);
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China return;
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China }
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China iscsi_send_sysevent(ihp, EC_DEV_ADD, ESC_DISK, attr_list);
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China kmem_free(pathname, MAXNAMELEN + 1);
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China nvlist_free(attr_list);
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_lun_offline - attempt _di_offline [and optional _di_free]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function is called via two paths. When a transport
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * path has failed it will be called to offline the logical
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * unit. When nameservice access has been removed it will
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * be called to both offline and free the logical unit.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * (This operates soley on the solaris node states.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_lun_destroy() should be called when attempting
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to free all iscsi lun resources.)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function can fail with ISCSI_STATUS_BUSY if the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * logical unit is in use. The user should unmount or
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * close the device and perform the nameservice operation
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * again if this occurs.
91dae09ce7f46c6f5f967f47a96f652d2c5f9bb4bing zhao - Sun Microsystems - Beijing China *
91dae09ce7f46c6f5f967f47a96f652d2c5f9bb4bing zhao - Sun Microsystems - Beijing China * If we fail to offline a LUN that we don't want to destroy,
91dae09ce7f46c6f5f967f47a96f652d2c5f9bb4bing zhao - Sun Microsystems - Beijing China * we will mark it with invalid state. If this LUN still
91dae09ce7f46c6f5f967f47a96f652d2c5f9bb4bing zhao - Sun Microsystems - Beijing China * exists on the target, we can have another chance to online
91dae09ce7f46c6f5f967f47a96f652d2c5f9bb4bing zhao - Sun Microsystems - Beijing China * it again when we do the LUN enumeration.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_lun_offline(iscsi_hba_t *ihp, iscsi_lun_t *ilp, boolean_t lun_free)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China iscsi_status_t status = ISCSI_STATUS_SUCCESS;
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China int circ = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dev_info_t *cdip, *pdip;
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China char *devname = NULL;
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China char *pathname = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rval;
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China boolean_t offline = B_FALSE;
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China nvlist_t *attr_list = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ilp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT((ilp->lun_pip != NULL) || (ilp->lun_dip != NULL));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Since we carry the logical units parent
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * lock across the offline call it will not
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * issue devfs_clean() and may fail with a
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * devi_ref count > 0.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilp->lun_pip == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdip = ilp->lun_dip;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdip = mdi_pi_get_client(ilp->lun_pip);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cdip != NULL) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (lun_free == B_TRUE) &&
91dae09ce7f46c6f5f967f47a96f652d2c5f9bb4bing zhao - Sun Microsystems - Beijing China (ilp->lun_state & ISCSI_LUN_STATE_ONLINE)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Make sure node is attached otherwise
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * it won't have related cache nodes to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * clean up. i_ddi_devi_attached is
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * similiar to i_ddi_node_state(cdip) >=
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * DS_ATTACHED. We should clean up only
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * when lun_free is set.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (i_ddi_devi_attached(cdip)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Get parent dip */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pdip = ddi_get_parent(cdip);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Get full devname */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte devname = kmem_alloc(MAXNAMELEN + 1, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ndi_devi_enter(pdip, &circ);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_deviname(cdip, devname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Release lock before devfs_clean() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ndi_devi_exit(pdip, circ);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Clean cache */
cfc3b49fd53fba13be205e2206e0ea3b36f5f2c7Yuri Pankov (void) devfs_clean(pdip, devname + 1, DV_CLEAN_FORCE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(devname, MAXNAMELEN + 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China if (cdip != NULL && ilp->lun_type == DTYPE_DIRECT) {
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China pathname = kmem_zalloc(MAXNAMELEN + 1, KM_SLEEP);
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China (void) ddi_pathname(cdip, pathname);
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China }
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Attempt to offline the logical units */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilp->lun_pip != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* virt/mdi */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ndi_devi_enter(scsi_vhci_dip, &circ);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((lun_free == B_TRUE) &&
91dae09ce7f46c6f5f967f47a96f652d2c5f9bb4bing zhao - Sun Microsystems - Beijing China (ilp->lun_state & ISCSI_LUN_STATE_ONLINE)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = mdi_pi_offline(ilp->lun_pip,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NDI_DEVI_REMOVE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = mdi_pi_offline(ilp->lun_pip, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rval == MDI_SUCCESS) {
91dae09ce7f46c6f5f967f47a96f652d2c5f9bb4bing zhao - Sun Microsystems - Beijing China ilp->lun_state &= ISCSI_LUN_STATE_CLEAR;
91dae09ce7f46c6f5f967f47a96f652d2c5f9bb4bing zhao - Sun Microsystems - Beijing China ilp->lun_state |= ISCSI_LUN_STATE_OFFLINE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lun_free == B_TRUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) mdi_prop_remove(ilp->lun_pip, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) mdi_pi_free(ilp->lun_pip, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China offline = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
5295a27a4fa085a76d771898093c66c844868fc1Jack Meng status = ISCSI_STATUS_BUSY;
91dae09ce7f46c6f5f967f47a96f652d2c5f9bb4bing zhao - Sun Microsystems - Beijing China if (lun_free == B_FALSE) {
91dae09ce7f46c6f5f967f47a96f652d2c5f9bb4bing zhao - Sun Microsystems - Beijing China ilp->lun_state |= ISCSI_LUN_STATE_INVALID;
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China offline = B_TRUE;
91dae09ce7f46c6f5f967f47a96f652d2c5f9bb4bing zhao - Sun Microsystems - Beijing China }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ndi_devi_exit(scsi_vhci_dip, circ);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* phys/ndi */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ndi_devi_enter(ihp->hba_dip, &circ);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((lun_free == B_TRUE) &&
91dae09ce7f46c6f5f967f47a96f652d2c5f9bb4bing zhao - Sun Microsystems - Beijing China (ilp->lun_state & ISCSI_LUN_STATE_ONLINE)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = ndi_devi_offline(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->lun_dip, NDI_DEVI_REMOVE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = ndi_devi_offline(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilp->lun_dip, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rval != NDI_SUCCESS) {
5295a27a4fa085a76d771898093c66c844868fc1Jack Meng status = ISCSI_STATUS_BUSY;
91dae09ce7f46c6f5f967f47a96f652d2c5f9bb4bing zhao - Sun Microsystems - Beijing China if (lun_free == B_FALSE) {
91dae09ce7f46c6f5f967f47a96f652d2c5f9bb4bing zhao - Sun Microsystems - Beijing China ilp->lun_state |= ISCSI_LUN_STATE_INVALID;
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China offline = B_TRUE;
91dae09ce7f46c6f5f967f47a96f652d2c5f9bb4bing zhao - Sun Microsystems - Beijing China }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
91dae09ce7f46c6f5f967f47a96f652d2c5f9bb4bing zhao - Sun Microsystems - Beijing China ilp->lun_state &= ISCSI_LUN_STATE_CLEAR;
91dae09ce7f46c6f5f967f47a96f652d2c5f9bb4bing zhao - Sun Microsystems - Beijing China ilp->lun_state |= ISCSI_LUN_STATE_OFFLINE;
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China offline = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ndi_devi_exit(ihp->hba_dip, circ);
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China }
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China if (offline == B_TRUE && pathname != NULL &&
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China ilp->lun_type == DTYPE_DIRECT) {
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China if (nvlist_alloc(&attr_list, NV_UNIQUE_NAME_TYPE, KM_SLEEP) !=
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China DDI_SUCCESS) {
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China kmem_free(pathname, MAXNAMELEN + 1);
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China return (status);
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China }
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China if (nvlist_add_string(attr_list, DEV_PHYS_PATH, pathname) !=
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China DDI_SUCCESS) {
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China nvlist_free(attr_list);
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China kmem_free(pathname, MAXNAMELEN + 1);
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China return (status);
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China iscsi_send_sysevent(ihp, EC_DEV_REMOVE, ESC_DISK, attr_list);
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China nvlist_free(attr_list);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China if (pathname != NULL) {
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China kmem_free(pathname, MAXNAMELEN + 1);
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China }
c60a6da3c3825f88388f3fba451c3dd975088f07bing zhao - Sun Microsystems - Beijing China
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}