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/*
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/conf.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/file.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/ddi.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/sunddi.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/modctl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/scsi/scsi.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/scsi/impl/scsi_reset_notify.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/disp.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/byteorder.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/atomic.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan#include <sys/stmf.h>
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan#include <sys/lpif.h>
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan#include <sys/portif.h>
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan#include <sys/stmf_ioctl.h>
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "stmf_impl.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "lun_map.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "stmf_state.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid stmf_update_sessions_per_ve(stmf_view_entry_t *ve,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lu_t *lu, int action);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid stmf_add_lus_to_session_per_vemap(stmf_i_local_port_t *ilport,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_session_t *iss, stmf_lun_map_t *vemap);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_id_data_t *stmf_lookup_group_for_host(uint8_t *ident, uint16_t ident_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t stmf_add_ent_to_map(stmf_lun_map_t *sm, void *ent, uint8_t *lun);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t stmf_remove_ent_from_map(stmf_lun_map_t *sm, uint8_t *lun);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteuint16_t stmf_get_next_free_lun(stmf_lun_map_t *sm, uint8_t *lun);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t stmf_add_tg(uint8_t *tg_name, uint16_t tg_name_size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int allow_special, uint32_t *err_detail);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t stmf_add_hg(uint8_t *hg_name, uint16_t hg_name_size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int allow_special, uint32_t *err_detail);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_i_local_port_t *stmf_targetident_to_ilport(uint8_t *target_ident,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t ident_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_i_scsi_session_t *stmf_lookup_session_for_hostident(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_local_port_t *ilport, uint8_t *host_ident,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t ident_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_i_lu_t *stmf_luident_to_ilu(uint8_t *lu_ident);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_lun_map_t *stmf_get_ve_map_per_ids(stmf_id_data_t *tgid,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_data_t *hgid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_lun_map_t *stmf_duplicate_ve_map(stmf_lun_map_t *src);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint stmf_merge_ve_map(stmf_lun_map_t *src, stmf_lun_map_t *dst,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lun_map_t **pp_ret_map, stmf_merge_flags_t mf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid stmf_destroy_ve_map(stmf_lun_map_t *dst);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid stmf_free_id(stmf_id_data_t *id);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Init the view
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_view_init()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t grpname_forall = '*';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) stmf_add_hg(&grpname_forall, 1, 1, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) stmf_add_tg(&grpname_forall, 1, 1, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Clear config database here
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_view_clear_config()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_data_t *idgrp, *idgrp_next, *idmemb, *idmemb_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_ver_tg_t *vtg, *vtg_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_ver_hg_t *vhg, *vhg_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_view_entry_t *ve, *ve_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_list_t *idlist;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_local_port_t *ilport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (vtg = stmf_state.stmf_ver_tg_head; vtg; vtg = vtg_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (vhg = vtg->vert_verh_list; vhg; vhg = vhg_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (vhg->verh_ve_map.lm_nentries) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(vhg->verh_ve_map.lm_plus,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vhg->verh_ve_map.lm_nentries *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (void *));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vhg_next = vhg->verh_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(vhg, sizeof (stmf_ver_hg_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vtg_next = vtg->vert_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(vtg, sizeof (stmf_ver_tg_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_ver_tg_head = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_state.stmf_luid_list.id_count) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* clear the views for lus */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (idmemb = stmf_state.stmf_luid_list.idl_head;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte idmemb; idmemb = idmemb_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ve = (stmf_view_entry_t *)idmemb->id_impl_specific;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve; ve = ve_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve_next = ve->ve_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve->ve_hg->id_refcnt--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve->ve_tg->id_refcnt--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ve, sizeof (stmf_view_entry_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (idmemb->id_pt_to_object) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu = (stmf_i_lu_t *)(idmemb->id_pt_to_object);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_luid = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte idmemb_next = idmemb->id_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_free_id(idmemb);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_luid_list.id_count = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_luid_list.idl_head =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_luid_list.idl_tail = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_state.stmf_hg_list.id_count) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* free all the host group */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (idgrp = stmf_state.stmf_hg_list.idl_head;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte idgrp; idgrp = idgrp_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte idlist = (stmf_id_list_t *)(idgrp->id_impl_specific);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (idlist->id_count) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (idmemb = idlist->idl_head; idmemb;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte idmemb = idmemb_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte idmemb_next = idmemb->id_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_free_id(idmemb);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte idgrp_next = idgrp->id_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_free_id(idgrp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_hg_list.id_count = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_hg_list.idl_head =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_hg_list.idl_tail = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_state.stmf_tg_list.id_count) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* free all the target group */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (idgrp = stmf_state.stmf_tg_list.idl_head;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte idgrp; idgrp = idgrp_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte idlist = (stmf_id_list_t *)(idgrp->id_impl_specific);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (idlist->id_count) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (idmemb = idlist->idl_head; idmemb;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte idmemb = idmemb_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte idmemb_next = idmemb->id_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_free_id(idmemb);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte idgrp_next = idgrp->id_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_free_id(idgrp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_tg_list.id_count = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_tg_list.idl_head =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_tg_list.idl_tail = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ilport = stmf_state.stmf_ilportlist; ilport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport = ilport->ilport_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport->ilport_tg = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Create luns map for session based on the view
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_session_create_lun_map(stmf_i_local_port_t *ilport,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_session_t *iss)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_data_t *tg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_data_t *hg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_ver_tg_t *vertg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *phg_data, *ptg_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_ver_hg_t *verhg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lun_map_t *ve_map;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
780c822c86101e82568fa9e357d13965b9f0cf81tim szeto ASSERT(mutex_owned(&stmf_state.stmf_lock));
780c822c86101e82568fa9e357d13965b9f0cf81tim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tg = ilport->ilport_tg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hg = stmf_lookup_group_for_host(iss->iss_ss->ss_rport_id->ident,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iss->iss_ss->ss_rport_id->ident_length);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iss->iss_hg = hg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * get the view entry map,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * take all host/target group into consideration
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve_map = stmf_duplicate_ve_map(0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (vertg = stmf_state.stmf_ver_tg_head; vertg != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vertg = vertg->vert_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ptg_data = (char *)vertg->vert_tg_ref->id_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ptg_data[0] != '*') && (!tg ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((tg->id_data[0] != '*') &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (vertg->vert_tg_ref != tg)))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (verhg = vertg->vert_verh_list; verhg != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte verhg = verhg->verh_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte phg_data = (char *)verhg->verh_hg_ref->id_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((phg_data[0] != '*') && (!hg ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((hg->id_data[0] != '*') &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (verhg->verh_hg_ref != hg)))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) stmf_merge_ve_map(&verhg->verh_ve_map, ve_map,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &ve_map, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ve_map->lm_nluns) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_add_lus_to_session_per_vemap(ilport, iss, ve_map);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* not configured, cannot access any luns for now */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_destroy_ve_map(ve_map);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * destroy lun map for session
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_session_destroy_lun_map(stmf_i_local_port_t *ilport,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_session_t *iss)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lun_map_t *sm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t n;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lun_map_ent_t *ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
780c822c86101e82568fa9e357d13965b9f0cf81tim szeto ASSERT(mutex_owned(&stmf_state.stmf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to avoid conflict with updating session's map,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * which only grab stmf_lock
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sm = iss->iss_sm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iss->iss_sm = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iss->iss_hg = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sm->lm_nentries) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (n = 0; n < sm->lm_nentries; n++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ent = (stmf_lun_map_ent_t *)sm->lm_plus[n])
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ent->ent_itl_datap) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_do_itl_dereg(ent->ent_lu,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ent->ent_itl_datap,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_ITL_REASON_IT_NEXUS_LOSS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu = (stmf_i_lu_t *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ent->ent_lu->lu_stmf_private;
1a5e258f5471356ca102c7176637cdce45bac147Josef 'Jeff' Sipek atomic_dec_32(&ilu->ilu_ref_cnt);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(sm->lm_plus[n],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (stmf_lun_map_ent_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(sm->lm_plus,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (stmf_lun_map_ent_t *) * sm->lm_nentries);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(sm, sizeof (*sm));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Expects the session lock to be held.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_xfer_data_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_session_prepare_report_lun_data(stmf_lun_map_t *sm)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_xfer_data_t *xd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t nluns, ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t alloc_size, data_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nluns = sm->lm_nluns;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data_size = 8 + (((uint32_t)nluns) << 3);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nluns == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data_size += 8;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte alloc_size = data_size + sizeof (stmf_xfer_data_t) - 4;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xd = (stmf_xfer_data_t *)kmem_zalloc(alloc_size, KM_NOSLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (xd == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xd->alloc_size = alloc_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xd->size_left = data_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *((uint32_t *)xd->buf) = BE_32(data_size - 8);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nluns == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (xd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ent = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; ((i < sm->lm_nentries) && (ent < nluns)); i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sm->lm_plus[i] == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Fill in the entry */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xd->buf[8 + (ent << 3) + 1] = (uchar_t)i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xd->buf[8 + (ent << 3) + 0] = ((uchar_t)(i >> 8));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ent++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ent == nluns);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (xd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Add a lu to active sessions based on LUN inventory.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Only invoked when the lu is onlined
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_add_lu_to_active_sessions(stmf_lu_t *lu)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_data_t *luid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_view_entry_t *ve;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(mutex_owned(&stmf_state.stmf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu = (stmf_i_lu_t *)lu->lu_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ilu->ilu_state == STMF_STATE_ONLINE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte luid = ((stmf_i_lu_t *)lu->lu_stmf_private)->ilu_luid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!luid) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* we did not configure view for this lun, so just return */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ve = (stmf_view_entry_t *)luid->id_impl_specific;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve; ve = ve->ve_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_update_sessions_per_ve(ve, lu, 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Unmap a lun from all sessions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_session_lu_unmapall(stmf_lu_t *lu)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_data_t *luid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_view_entry_t *ve;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(mutex_owned(&stmf_state.stmf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu = (stmf_i_lu_t *)lu->lu_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu->ilu_ref_cnt == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte luid = ((stmf_i_lu_t *)lu->lu_stmf_private)->ilu_luid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!luid) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we did not configure view for this lun, this should be
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * an error
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ve = (stmf_view_entry_t *)luid->id_impl_specific;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve; ve = ve->ve_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_update_sessions_per_ve(ve, lu, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu->ilu_ref_cnt == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * add lu to a session, stmf_lock is already held
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_add_lu_to_session(stmf_i_local_port_t *ilport,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_session_t *iss,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lu_t *lu,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *lu_nbr)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lun_map_t *sm = iss->iss_sm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_status_t ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu = (stmf_i_lu_t *)lu->lu_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lun_map_ent_t *lun_map_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t new_flags = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t luNbr =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((uint16_t)lu_nbr[1] | (((uint16_t)(lu_nbr[0] & 0x3F)) << 8));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(mutex_owned(&stmf_state.stmf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(!stmf_get_ent_from_map(sm, luNbr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((sm->lm_nluns == 0) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((iss->iss_flags & ISS_BEING_CREATED) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte new_flags = ISS_GOT_INITIAL_LUNS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte atomic_or_32(&ilport->ilport_flags, ILPORT_SS_GOT_INITIAL_LUNS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_process_initial_luns = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lun_map_ent = (stmf_lun_map_ent_t *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_zalloc(sizeof (stmf_lun_map_ent_t), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lun_map_ent->ent_lu = lu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = stmf_add_ent_to_map(sm, (void *)lun_map_ent, lu_nbr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ret == STMF_SUCCESS);
1a5e258f5471356ca102c7176637cdce45bac147Josef 'Jeff' Sipek atomic_inc_32(&ilu->ilu_ref_cnt);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * do not set lun inventory flag for standby port
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * as this would be handled from peer
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ilport->ilport_standby == 0) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte new_flags |= ISS_LUN_INVENTORY_CHANGED;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte atomic_or_32(&iss->iss_flags, new_flags);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * remvoe lu from a session, stmf_lock is already held
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_remove_lu_from_session(stmf_i_local_port_t *ilport,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_session_t *iss,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lu_t *lu,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *lu_nbr)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_status_t ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lun_map_t *sm = iss->iss_sm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lun_map_ent_t *lun_map_ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t luNbr =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((uint16_t)lu_nbr[1] | (((uint16_t)(lu_nbr[0] & 0x3F)) << 8));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(mutex_owned(&stmf_state.stmf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lun_map_ent = stmf_get_ent_from_map(sm, luNbr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(lun_map_ent && lun_map_ent->ent_lu == lu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu = (stmf_i_lu_t *)lu->lu_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = stmf_remove_ent_from_map(sm, lu_nbr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ret == STMF_SUCCESS);
1a5e258f5471356ca102c7176637cdce45bac147Josef 'Jeff' Sipek atomic_dec_32(&ilu->ilu_ref_cnt);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iss->iss_flags |= ISS_LUN_INVENTORY_CHANGED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lun_map_ent->ent_itl_datap) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_do_itl_dereg(lu, lun_map_ent->ent_itl_datap,
5c8cac22647b12e79982cf052e5df46dc7402bd5tim szeto STMF_ITL_REASON_USER_REQUEST);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free((void *)lun_map_ent, sizeof (stmf_lun_map_ent_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * add or remove lu from all related sessions based on view entry,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * action is 0 for delete, 1 for add
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_update_sessions_per_ve(stmf_view_entry_t *ve,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lu_t *lu, int action)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu_tmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lu_t *lu_to_add;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_local_port_t *ilport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_session_t *iss;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_list_t *hostlist;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_list_t *targetlist;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int all_hg = 0, all_tg = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(mutex_owned(&stmf_state.stmf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!lu) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu_tmp = (stmf_i_lu_t *)ve->ve_luid->id_pt_to_object;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!ilu_tmp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lu_to_add = ilu_tmp->ilu_lu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lu_to_add = lu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu_tmp = (stmf_i_lu_t *)lu->lu_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ve->ve_hg->id_data[0] == '*')
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte all_hg = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ve->ve_tg->id_data[0] == '*')
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte all_tg = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hostlist = (stmf_id_list_t *)ve->ve_hg->id_impl_specific;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte targetlist = (stmf_id_list_t *)ve->ve_tg->id_impl_specific;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((!all_hg && !hostlist->idl_head) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (!all_tg && !targetlist->idl_head))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* No sessions to be updated */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ilport = stmf_state.stmf_ilportlist; ilport != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport = ilport->ilport_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!all_tg && ilport->ilport_tg != ve->ve_tg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* This ilport belongs to the target group */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&ilport->ilport_lock, RW_WRITER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (iss = ilport->ilport_ss_list; iss != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iss = iss->iss_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!all_hg && iss->iss_hg != ve->ve_hg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* This host belongs to the host group */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (action == 0) { /* to remove */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) stmf_remove_lu_from_session(ilport, iss,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lu_to_add, ve->ve_lun);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu_tmp->ilu_ref_cnt == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&ilport->ilport_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) stmf_add_lu_to_session(ilport, iss,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lu_to_add, ve->ve_lun);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&ilport->ilport_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * add luns in view entry map to a session,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and stmf_lock is already held
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_add_lus_to_session_per_vemap(stmf_i_local_port_t *ilport,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_session_t *iss,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lun_map_t *vemap)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lu_t *lu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_view_entry_t *ve;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(mutex_owned(&stmf_state.stmf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < vemap->lm_nentries; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve = (stmf_view_entry_t *)vemap->lm_plus[i];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!ve)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu = (stmf_i_lu_t *)ve->ve_luid->id_pt_to_object;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu && ilu->ilu_state == STMF_STATE_ONLINE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lu = ilu->ilu_lu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) stmf_add_lu_to_session(ilport, iss, lu,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve->ve_lun);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* remove luns in view entry map from a session */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_remove_lus_from_session_per_vemap(stmf_i_local_port_t *ilport,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_session_t *iss,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lun_map_t *vemap)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lu_t *lu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_view_entry_t *ve;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(mutex_owned(&stmf_state.stmf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < vemap->lm_nentries; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve = (stmf_view_entry_t *)vemap->lm_plus[i];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!ve)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu = (stmf_i_lu_t *)ve->ve_luid->id_pt_to_object;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu && ilu->ilu_state == STMF_STATE_ONLINE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lu = ilu->ilu_lu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) stmf_remove_lu_from_session(ilport, iss, lu,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve->ve_lun);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_id_data_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_alloc_id(uint16_t id_size, uint16_t type, uint8_t *id_data,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t additional_size)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_data_t *id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int struct_size, total_size, real_id_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte real_id_size = ((uint32_t)id_size + 7) & (~7);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct_size = (sizeof (*id) + 7) & (~7);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte total_size = ((additional_size + 7) & (~7)) + struct_size +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte real_id_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id = (stmf_id_data_t *)kmem_zalloc(total_size, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id->id_type = type;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id->id_data_size = id_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id->id_data = ((uint8_t *)id) + struct_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id->id_total_alloc_size = total_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (additional_size) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id->id_impl_specific = ((uint8_t *)id) + struct_size +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte real_id_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(id_data, id->id_data, id_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (id);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_free_id(stmf_id_data_t *id)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(id, id->id_total_alloc_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_id_data_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_lookup_id(stmf_id_list_t *idlist, uint16_t id_size, uint8_t *data)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_data_t *id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (id = idlist->idl_head; id != NULL; id = id->id_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((id->id_data_size == id_size) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (bcmp(id->id_data, data, id_size) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (id);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* Return the target group which a target belong to */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_id_data_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_lookup_group_for_target(uint8_t *ident, uint16_t ident_size)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_data_t *tgid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_data_t *target;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(mutex_owned(&stmf_state.stmf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (tgid = stmf_state.stmf_tg_list.idl_head; tgid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tgid = tgid->id_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte target = stmf_lookup_id(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (stmf_id_list_t *)tgid->id_impl_specific,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ident_size, ident);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (target)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (tgid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* Return the host group which a host belong to */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_id_data_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_lookup_group_for_host(uint8_t *ident, uint16_t ident_size)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_data_t *hgid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_data_t *host;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(mutex_owned(&stmf_state.stmf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (hgid = stmf_state.stmf_hg_list.idl_head; hgid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hgid = hgid->id_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte host = stmf_lookup_id(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (stmf_id_list_t *)hgid->id_impl_specific,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ident_size, ident);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (host)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (hgid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_append_id(stmf_id_list_t *idlist, stmf_id_data_t *id)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id->id_next = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((id->id_prev = idlist->idl_tail) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte idlist->idl_head = idlist->idl_tail = id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte idlist->idl_tail->id_next = id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte idlist->idl_tail = id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
1a5e258f5471356ca102c7176637cdce45bac147Josef 'Jeff' Sipek atomic_inc_32(&idlist->id_count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_remove_id(stmf_id_list_t *idlist, stmf_id_data_t *id)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (id->id_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id->id_next->id_prev = id->id_prev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte idlist->idl_tail = id->id_prev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (id->id_prev) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id->id_prev->id_next = id->id_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte idlist->idl_head = id->id_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
1a5e258f5471356ca102c7176637cdce45bac147Josef 'Jeff' Sipek atomic_dec_32(&idlist->id_count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The refcnts of objects in a view entry are updated when then entry
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is successfully added. ve_map is just another representation of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * view enrtries in a LU. Duplicating or merging a ve map does not
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * affect any refcnts.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_lun_map_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_duplicate_ve_map(stmf_lun_map_t *src)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lun_map_t *dst;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dst = (stmf_lun_map_t *)kmem_zalloc(sizeof (*dst), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (src == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (dst);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (src->lm_nentries) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dst->lm_plus = kmem_zalloc(dst->lm_nentries *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (void *), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < dst->lm_nentries; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dst->lm_plus[i] = src->lm_plus[i];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (dst);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_destroy_ve_map(stmf_lun_map_t *dst)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dst->lm_nentries) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(dst->lm_plus, dst->lm_nentries * sizeof (void *));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(dst, sizeof (*dst));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_merge_ve_map(stmf_lun_map_t *src, stmf_lun_map_t *dst,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lun_map_t **pp_ret_map, stmf_merge_flags_t mf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int nentries;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int to_create_space = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dst == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *pp_ret_map = stmf_duplicate_ve_map(src);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (src == NULL || src->lm_nluns == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mf & MERGE_FLAG_RETURN_NEW_MAP)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *pp_ret_map = stmf_duplicate_ve_map(dst);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *pp_ret_map = dst;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mf & MERGE_FLAG_RETURN_NEW_MAP) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *pp_ret_map = stmf_duplicate_ve_map(NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nentries = max(dst->lm_nentries, src->lm_nentries);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte to_create_space = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *pp_ret_map = dst;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* If there is not enough space in dst map */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dst->lm_nentries < src->lm_nentries) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nentries = src->lm_nentries;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte to_create_space = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (to_create_space) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void **p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p = (void **)kmem_zalloc(nentries * sizeof (void *), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dst->lm_nentries) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(dst->lm_plus, p,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dst->lm_nentries * sizeof (void *));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mf & (MERGE_FLAG_RETURN_NEW_MAP == 0))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(dst->lm_plus,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dst->lm_nentries * sizeof (void *));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*pp_ret_map)->lm_plus = p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*pp_ret_map)->lm_nentries = nentries;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < src->lm_nentries; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (src->lm_plus[i] == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dst->lm_plus[i] != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mf & MERGE_FLAG_NO_DUPLICATE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mf & MERGE_FLAG_RETURN_NEW_MAP) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_destroy_ve_map(*pp_ret_map);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *pp_ret_map = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dst->lm_plus[i] = src->lm_plus[i];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dst->lm_nluns++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * add host group, id_impl_specific point to a list of hosts,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * on return, if error happened, err_detail may be assigned if
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the pointer is not NULL
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_add_hg(uint8_t *hg_name, uint16_t hg_name_size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int allow_special, uint32_t *err_detail)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_data_t *id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!allow_special) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (hg_name[0] == '*')
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_lookup_id(&stmf_state.stmf_hg_list,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hg_name_size, (uint8_t *)hg_name)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err_detail)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *err_detail = STMF_IOCERR_HG_EXISTS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ALREADY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id = stmf_alloc_id(hg_name_size, STMF_ID_TYPE_HOST_GROUP,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (uint8_t *)hg_name, sizeof (stmf_id_list_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_append_id(&stmf_state.stmf_hg_list, id);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* add target group */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_add_tg(uint8_t *tg_name, uint16_t tg_name_size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int allow_special, uint32_t *err_detail)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_data_t *id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!allow_special) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (tg_name[0] == '*')
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_lookup_id(&stmf_state.stmf_tg_list, tg_name_size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (uint8_t *)tg_name)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (err_detail)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *err_detail = STMF_IOCERR_TG_EXISTS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ALREADY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id = stmf_alloc_id(tg_name_size, STMF_ID_TYPE_TARGET_GROUP,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (uint8_t *)tg_name, sizeof (stmf_id_list_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_append_id(&stmf_state.stmf_tg_list, id);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * insert view entry into list for a luid, if ve->ve_id is 0xffffffff,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * pick up a smallest available veid for it, and return the veid in ve->ve_id.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The view entries list is sorted based on veid.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_add_ve_to_luid(stmf_id_data_t *luid, stmf_view_entry_t *ve)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_view_entry_t *ve_tmp = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_view_entry_t *ve_prev = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(mutex_owned(&stmf_state.stmf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve_tmp = (stmf_view_entry_t *)luid->id_impl_specific;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ve->ve_id != 0xffffffff) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (; ve_tmp; ve_tmp = ve_tmp->ve_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ve_tmp->ve_id > ve->ve_id) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (ve_tmp->ve_id == ve->ve_id) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ALREADY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve_prev = ve_tmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t veid = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* search the smallest available veid */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (; ve_tmp; ve_tmp = ve_tmp->ve_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ve_tmp->ve_id >= veid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ve_tmp->ve_id != veid)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte veid++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (veid == 0xffffffff)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_NOT_SUPPORTED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve_prev = ve_tmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve->ve_id = veid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* insert before ve_tmp if it exist */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve->ve_next = ve_tmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve->ve_prev = ve_prev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ve_tmp) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve_tmp->ve_prev = ve;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ve_prev) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve_prev->ve_next = ve;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte luid->id_impl_specific = (void *)ve;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* stmf_lock is already held, err_detail may be assigned if error happens */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_add_view_entry(stmf_id_data_t *hg, stmf_id_data_t *tg,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *lu_guid, uint32_t *ve_id, uint8_t *lun,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_view_entry_t **conflicting, uint32_t *err_detail)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_data_t *luid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_view_entry_t *ve;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *phg, *ptg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lun_map_t *ve_map = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_ver_hg_t *verhg = NULL, *verhg_ex = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_ver_tg_t *vertg = NULL, *vertg_ex = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char luid_new;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t lun_num;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_status_t ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(mutex_owned(&stmf_state.stmf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lun_num = ((uint16_t)lun[1] | (((uint16_t)(lun[0] & 0x3F)) << 8));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte luid = stmf_lookup_id(&stmf_state.stmf_luid_list, 16, lu_guid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (luid == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte luid = stmf_alloc_id(16, STMF_ID_TYPE_LU_GUID, lu_guid, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu = stmf_luident_to_ilu(lu_guid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_luid = luid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte luid->id_pt_to_object = (void *)ilu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte luid_new = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte luid_new = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu = (stmf_i_lu_t *)luid->id_pt_to_object;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* The view entry won't be added if there is any confilict */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte phg = (char *)hg->id_data; ptg = (char *)tg->id_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ve = (stmf_view_entry_t *)luid->id_impl_specific; ve != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve = ve->ve_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((phg[0] == '*') || (ve->ve_hg->id_data[0] == '*') ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (hg == ve->ve_hg)) && ((ptg[0] == '*') ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (ve->ve_tg->id_data[0] == '*') || (tg == ve->ve_tg))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *conflicting = ve;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *err_detail = STMF_IOCERR_VIEW_ENTRY_CONFLICT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ALREADY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto add_ve_err_ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve_map = stmf_duplicate_ve_map(0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (vertg = stmf_state.stmf_ver_tg_head; vertg != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vertg = vertg->vert_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ptg = (char *)vertg->vert_tg_ref->id_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ptg[0] != '*') && (tg->id_data[0] != '*') &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (vertg->vert_tg_ref != tg)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (vertg->vert_tg_ref == tg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vertg_ex = vertg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (verhg = vertg->vert_verh_list; verhg != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte verhg = verhg->verh_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte phg = (char *)verhg->verh_hg_ref->id_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((phg[0] != '*') && (hg->id_data[0] != '*') &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (verhg->verh_hg_ref != hg)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((vertg_ex == vertg) && (verhg->verh_hg_ref == hg))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte verhg_ex = verhg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) stmf_merge_ve_map(&verhg->verh_ve_map, ve_map,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &ve_map, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lun[2] == 0xFF) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Pick a LUN number */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lun_num = stmf_get_next_free_lun(ve_map, lun);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lun_num > 0x3FFF) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_destroy_ve_map(ve_map);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_NOT_SUPPORTED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto add_ve_err_ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((*conflicting = stmf_get_ent_from_map(ve_map, lun_num))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_destroy_ve_map(ve_map);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *err_detail = STMF_IOCERR_LU_NUMBER_IN_USE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_LUN_TAKEN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto add_ve_err_ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_destroy_ve_map(ve_map);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* All is well, do the actual addition now */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve = (stmf_view_entry_t *)kmem_zalloc(sizeof (*ve), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve->ve_id = *ve_id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve->ve_lun[0] = lun[0];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve->ve_lun[1] = lun[1];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = stmf_add_ve_to_luid(luid, ve)) != STMF_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ve, sizeof (stmf_view_entry_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto add_ve_err_ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve->ve_hg = hg; hg->id_refcnt++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve->ve_tg = tg; tg->id_refcnt++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve->ve_luid = luid; luid->id_refcnt++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *ve_id = ve->ve_id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (luid_new) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_append_id(&stmf_state.stmf_luid_list, luid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (vertg_ex == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vertg_ex = (stmf_ver_tg_t *)kmem_zalloc(sizeof (stmf_ver_tg_t),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vertg_ex->vert_next = stmf_state.stmf_ver_tg_head;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_ver_tg_head = vertg_ex;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vertg_ex->vert_tg_ref = tg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte verhg_ex = vertg_ex->vert_verh_list =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (stmf_ver_hg_t *)kmem_zalloc(sizeof (stmf_ver_hg_t),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte verhg_ex->verh_hg_ref = hg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (verhg_ex == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte verhg_ex = (stmf_ver_hg_t *)kmem_zalloc(sizeof (stmf_ver_hg_t),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte verhg_ex->verh_next = vertg_ex->vert_verh_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vertg_ex->vert_verh_list = verhg_ex;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte verhg_ex->verh_hg_ref = hg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = stmf_add_ent_to_map(&verhg_ex->verh_ve_map, ve, ve->ve_lun);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ret == STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* we need to update the affected session */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_state.stmf_service_running) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu && ilu->ilu_state == STMF_STATE_ONLINE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_update_sessions_per_ve(ve, ilu->ilu_lu, 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteadd_ve_err_ret:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (luid_new) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_luid = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_free_id(luid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_add_ent_to_map(stmf_lun_map_t *lm, void *ent, uint8_t *lun)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t n;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((lun[0] & 0xc0) >> 6) != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_FAILURE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte n = (uint16_t)lun[1] | (((uint16_t)(lun[0] & 0x3F)) << 8);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetry_again_to_add:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lm->lm_nentries && (n < lm->lm_nentries)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lm->lm_plus[n] == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lm->lm_plus[n] = ent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lm->lm_nluns++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_LUN_TAKEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void **pplu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t m = n + 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte m = ((m + 7) & ~7) & 0x7FFF;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pplu = (void **)kmem_zalloc(m * sizeof (void *), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(lm->lm_plus, pplu,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lm->lm_nentries * sizeof (void *));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(lm->lm_plus, lm->lm_nentries * sizeof (void *));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lm->lm_plus = pplu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lm->lm_nentries = m;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto try_again_to_add;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_remove_ent_from_map(stmf_lun_map_t *lm, uint8_t *lun)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t n, i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t lutype = (lun[0] & 0xc0) >> 6;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lutype != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_FAILURE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte n = (uint16_t)lun[1] | (((uint16_t)(lun[0] & 0x3F)) << 8);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (n >= lm->lm_nentries)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_NOT_FOUND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lm->lm_plus[n] == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_NOT_FOUND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lm->lm_plus[n] = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lm->lm_nluns--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < lm->lm_nentries; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lm->lm_plus[lm->lm_nentries - 1 - i] != NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte i &= ~15;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (i >= 16) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void **pplu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t m;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte m = lm->lm_nentries - i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pplu = (void **)kmem_zalloc(m * sizeof (void *), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(lm->lm_plus, pplu, m * sizeof (void *));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(lm->lm_plus, lm->lm_nentries * sizeof (void *));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lm->lm_plus = pplu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lm->lm_nentries = m;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteuint16_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_get_next_free_lun(stmf_lun_map_t *sm, uint8_t *lun)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t luNbr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sm->lm_nluns < 0x4000) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (luNbr = 0; luNbr < sm->lm_nentries; luNbr++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sm->lm_plus[luNbr] == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0xFFFF);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lun) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(lun, 8);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lun[1] = luNbr & 0xff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lun[0] = (luNbr >> 8) & 0xff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (luNbr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_get_ent_from_map(stmf_lun_map_t *sm, uint16_t lun_num)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((lun_num & 0xC000) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sm->lm_nentries > lun_num)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (sm->lm_plus[lun_num & 0x3FFF]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_add_ve(uint8_t *hgname, uint16_t hgname_size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *tgname, uint16_t tgname_size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *lu_guid, uint32_t *ve_id,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *luNbr, uint32_t *err_detail)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_data_t *hg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_data_t *tg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_view_entry_t *conflictve;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_status_t ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(mutex_owned(&stmf_state.stmf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hg = stmf_lookup_id(&stmf_state.stmf_hg_list, hgname_size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (uint8_t *)hgname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!hg) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *err_detail = STMF_IOCERR_INVALID_HG;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ENOENT); /* could not find group */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tg = stmf_lookup_id(&stmf_state.stmf_tg_list, tgname_size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (uint8_t *)tgname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!tg) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *err_detail = STMF_IOCERR_INVALID_TG;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ENOENT); /* could not find group */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = stmf_add_view_entry(hg, tg, lu_guid, ve_id, luNbr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &conflictve, err_detail);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret == STMF_ALREADY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EALREADY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (ret == STMF_LUN_TAKEN) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EEXIST);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (ret == STMF_NOT_SUPPORTED) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (E2BIG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (ret != STMF_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_remove_ve_by_id(uint8_t *guid, uint32_t veid, uint32_t *err_detail)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_data_t *luid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_view_entry_t *ve;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_ver_tg_t *vtg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_ver_hg_t *vhg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_ver_tg_t *prev_vtg = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_ver_hg_t *prev_vhg = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int found = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(mutex_owned(&stmf_state.stmf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte luid = stmf_lookup_id(&stmf_state.stmf_luid_list, 16, guid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (luid == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *err_detail = STMF_IOCERR_INVALID_LU_ID;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ENODEV);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu = (stmf_i_lu_t *)luid->id_pt_to_object;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ve = (stmf_view_entry_t *)luid->id_impl_specific;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve; ve = ve->ve_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ve->ve_id == veid) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!ve) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *err_detail = STMF_IOCERR_INVALID_VE_ID;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ENODEV);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* remove the ve */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ve->ve_next)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve->ve_next->ve_prev = ve->ve_prev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ve->ve_prev)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve->ve_prev->ve_next = ve->ve_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte luid->id_impl_specific = (void *)ve->ve_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!luid->id_impl_specific) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* don't have any view entries related to this lu */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_remove_id(&stmf_state.stmf_luid_list, luid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilu)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_luid = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_free_id(luid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* we need to update ver_hg->verh_ve_map */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (vtg = stmf_state.stmf_ver_tg_head; vtg; vtg = vtg->vert_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (vtg->vert_tg_ref == ve->ve_tg) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte found = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prev_vtg = vtg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(found);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte found = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (vhg = vtg->vert_verh_list; vhg; vhg = vhg->verh_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (vhg->verh_hg_ref == ve->ve_hg) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte found = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prev_vhg = vhg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(found);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) stmf_remove_ent_from_map(&vhg->verh_ve_map, ve->ve_lun);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* free verhg if it don't have any ve entries related */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!vhg->verh_ve_map.lm_nluns) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* we don't have any view entry related */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (prev_vhg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prev_vhg->verh_next = vhg->verh_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vtg->vert_verh_list = vhg->verh_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Free entries in case the map still has memory */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (vhg->verh_ve_map.lm_nentries) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(vhg->verh_ve_map.lm_plus,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vhg->verh_ve_map.lm_nentries *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (void *));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(vhg, sizeof (stmf_ver_hg_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!vtg->vert_verh_list) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* we don't have any ve related */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (prev_vtg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prev_vtg->vert_next = vtg->vert_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state.stmf_ver_tg_head = vtg->vert_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(vtg, sizeof (stmf_ver_tg_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_state.stmf_service_running && ilu &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu->ilu_state == STMF_STATE_ONLINE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_update_sessions_per_ve(ve, ilu->ilu_lu, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve->ve_hg->id_refcnt--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve->ve_tg->id_refcnt--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ve, sizeof (stmf_view_entry_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_add_group(uint8_t *grpname, uint16_t grpname_size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_type_t group_type, uint32_t *err_detail)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_status_t status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(mutex_owned(&stmf_state.stmf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (group_type == STMF_ID_TYPE_HOST_GROUP)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = stmf_add_hg(grpname, grpname_size, 0, err_detail);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if (group_type == STMF_ID_TYPE_TARGET_GROUP)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = stmf_add_tg(grpname, grpname_size, 0, err_detail);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (status) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_SUCCESS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_INVALID_ARG:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_ALREADY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EEXIST);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EIO);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Group can only be removed only when it does not have
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * any view entry related
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_remove_group(uint8_t *grpname, uint16_t grpname_size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_type_t group_type, uint32_t *err_detail)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_data_t *id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_data_t *idmemb;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_list_t *grp_memblist;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_session_t *iss;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_local_port_t *ilport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (grpname[0] == '*')
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(mutex_owned(&stmf_state.stmf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (group_type == STMF_ID_TYPE_HOST_GROUP)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id = stmf_lookup_id(&stmf_state.stmf_hg_list,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grpname_size, grpname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if (group_type == STMF_ID_TYPE_TARGET_GROUP)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id = stmf_lookup_id(&stmf_state.stmf_tg_list,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grpname_size, grpname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!id) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *err_detail = (group_type == STMF_ID_TYPE_HOST_GROUP)?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_IOCERR_INVALID_HG:STMF_IOCERR_INVALID_TG;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ENODEV); /* no such grp */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (id->id_refcnt) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* fail, still have viewentry related to it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *err_detail = (group_type == STMF_ID_TYPE_HOST_GROUP)?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_IOCERR_HG_IN_USE:STMF_IOCERR_TG_IN_USE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EBUSY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grp_memblist = (stmf_id_list_t *)id->id_impl_specific;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((idmemb = grp_memblist->idl_head) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_remove_id(grp_memblist, idmemb);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_free_id(idmemb);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(!grp_memblist->id_count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (id->id_type == STMF_ID_TYPE_TARGET_GROUP) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ilport = stmf_state.stmf_ilportlist; ilport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport = ilport->ilport_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilport->ilport_tg == (void *)id) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport->ilport_tg = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_remove_id(&stmf_state.stmf_tg_list, id);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ilport = stmf_state.stmf_ilportlist; ilport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport = ilport->ilport_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (iss = ilport->ilport_ss_list; iss;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iss = iss->iss_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (iss->iss_hg == (void *)id)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iss->iss_hg = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_remove_id(&stmf_state.stmf_hg_list, id);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_free_id(id);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_add_group_member(uint8_t *grpname, uint16_t grpname_size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *entry_ident, uint16_t entry_size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_type_t entry_type, uint32_t *err_detail)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_data_t *id_grp, *id_alltgt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_data_t *id_member;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_data_t *id_grp_tmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_session_t *iss;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_local_port_t *ilport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lun_map_t *vemap, *vemap_alltgt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t grpname_forall = '*';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(mutex_owned(&stmf_state.stmf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(grpname[0] != '*');
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (entry_type == STMF_ID_TYPE_HOST) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id_grp = stmf_lookup_id(&stmf_state.stmf_hg_list,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grpname_size, grpname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id_grp_tmp = stmf_lookup_group_for_host(entry_ident,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte entry_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id_grp = stmf_lookup_id(&stmf_state.stmf_tg_list,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grpname_size, grpname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id_grp_tmp = stmf_lookup_group_for_target(entry_ident,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte entry_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (id_grp == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *err_detail = (entry_type == STMF_ID_TYPE_HOST)?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_IOCERR_INVALID_HG:STMF_IOCERR_INVALID_TG;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ENODEV); /* not found */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check whether this member already bound to a group */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (id_grp_tmp) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (id_grp_tmp != id_grp) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *err_detail = (entry_type == STMF_ID_TYPE_HOST)?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_IOCERR_HG_ENTRY_EXISTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_IOCERR_TG_ENTRY_EXISTS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EEXIST); /* already added into another grp */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
f80ea9bbe1103fdcfafa9f1b139df1e2f42ad5c1tim szeto
f80ea9bbe1103fdcfafa9f1b139df1e2f42ad5c1tim szeto /* verify target is offline */
f80ea9bbe1103fdcfafa9f1b139df1e2f42ad5c1tim szeto if (entry_type == STMF_ID_TYPE_TARGET) {
f80ea9bbe1103fdcfafa9f1b139df1e2f42ad5c1tim szeto ilport = stmf_targetident_to_ilport(entry_ident, entry_size);
f80ea9bbe1103fdcfafa9f1b139df1e2f42ad5c1tim szeto if (ilport && ilport->ilport_state != STMF_STATE_OFFLINE) {
f80ea9bbe1103fdcfafa9f1b139df1e2f42ad5c1tim szeto *err_detail = STMF_IOCERR_TG_NEED_TG_OFFLINE;
f80ea9bbe1103fdcfafa9f1b139df1e2f42ad5c1tim szeto return (EBUSY);
f80ea9bbe1103fdcfafa9f1b139df1e2f42ad5c1tim szeto }
f80ea9bbe1103fdcfafa9f1b139df1e2f42ad5c1tim szeto }
f80ea9bbe1103fdcfafa9f1b139df1e2f42ad5c1tim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id_member = stmf_alloc_id(entry_size, entry_type,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte entry_ident, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_append_id((stmf_id_list_t *)id_grp->id_impl_specific, id_member);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (entry_type == STMF_ID_TYPE_TARGET) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport = stmf_targetident_to_ilport(entry_ident, entry_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilport)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport->ilport_tg = (void *)id_grp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* For host group member, update the session if needed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!stmf_state.stmf_service_running)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Need to consider all target group + this host group */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id_alltgt = stmf_lookup_id(&stmf_state.stmf_tg_list,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 1, &grpname_forall);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vemap_alltgt = stmf_get_ve_map_per_ids(id_alltgt, id_grp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* check whether there are sessions may be affected */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ilport = stmf_state.stmf_ilportlist; ilport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport = ilport->ilport_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilport->ilport_state != STMF_STATE_ONLINE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iss = stmf_lookup_session_for_hostident(ilport,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte entry_ident, entry_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (iss) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_data_t *tgid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iss->iss_hg = (void *)id_grp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tgid = ilport->ilport_tg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (tgid) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vemap = stmf_get_ve_map_per_ids(tgid, id_grp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (vemap)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_add_lus_to_session_per_vemap(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport, iss, vemap);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (vemap_alltgt)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_add_lus_to_session_per_vemap(ilport,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iss, vemap_alltgt);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_remove_group_member(uint8_t *grpname, uint16_t grpname_size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *entry_ident, uint16_t entry_size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_type_t entry_type, uint32_t *err_detail)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_data_t *id_grp, *id_alltgt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_data_t *id_member;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_lun_map_t *vemap, *vemap_alltgt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t grpname_forall = '*';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_local_port_t *ilport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_session_t *iss;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(mutex_owned(&stmf_state.stmf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(grpname[0] != '*');
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (entry_type == STMF_ID_TYPE_HOST) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id_grp = stmf_lookup_id(&stmf_state.stmf_hg_list,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grpname_size, grpname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id_grp = stmf_lookup_id(&stmf_state.stmf_tg_list,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grpname_size, grpname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (id_grp == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *err_detail = (entry_type == STMF_ID_TYPE_HOST)?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_IOCERR_INVALID_HG:STMF_IOCERR_INVALID_TG;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ENODEV); /* no such group */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id_member = stmf_lookup_id((stmf_id_list_t *)id_grp->id_impl_specific,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte entry_size, entry_ident);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!id_member) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *err_detail = (entry_type == STMF_ID_TYPE_HOST)?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_IOCERR_INVALID_HG_ENTRY:STMF_IOCERR_INVALID_TG_ENTRY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ENODEV); /* no such member */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
5c8cac22647b12e79982cf052e5df46dc7402bd5tim szeto /* verify target is offline */
5c8cac22647b12e79982cf052e5df46dc7402bd5tim szeto if (entry_type == STMF_ID_TYPE_TARGET) {
5c8cac22647b12e79982cf052e5df46dc7402bd5tim szeto ilport = stmf_targetident_to_ilport(entry_ident, entry_size);
5c8cac22647b12e79982cf052e5df46dc7402bd5tim szeto if (ilport && ilport->ilport_state != STMF_STATE_OFFLINE) {
5c8cac22647b12e79982cf052e5df46dc7402bd5tim szeto *err_detail = STMF_IOCERR_TG_NEED_TG_OFFLINE;
5c8cac22647b12e79982cf052e5df46dc7402bd5tim szeto return (EBUSY);
5c8cac22647b12e79982cf052e5df46dc7402bd5tim szeto }
5c8cac22647b12e79982cf052e5df46dc7402bd5tim szeto }
5c8cac22647b12e79982cf052e5df46dc7402bd5tim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_remove_id((stmf_id_list_t *)id_grp->id_impl_specific, id_member);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_free_id(id_member);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (entry_type == STMF_ID_TYPE_TARGET) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport = stmf_targetident_to_ilport(entry_ident, entry_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilport)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport->ilport_tg = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* For host group member, update the session */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!stmf_state.stmf_service_running)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Need to consider all target group + this host group */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id_alltgt = stmf_lookup_id(&stmf_state.stmf_tg_list,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 1, &grpname_forall);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vemap_alltgt = stmf_get_ve_map_per_ids(id_alltgt, id_grp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* check if there are session related, if so, update it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ilport = stmf_state.stmf_ilportlist; ilport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport = ilport->ilport_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ilport->ilport_state != STMF_STATE_ONLINE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iss = stmf_lookup_session_for_hostident(ilport,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte entry_ident, entry_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (iss) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_data_t *tgid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iss->iss_hg = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tgid = ilport->ilport_tg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (tgid) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vemap = stmf_get_ve_map_per_ids(tgid, id_grp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (vemap)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_remove_lus_from_session_per_vemap(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport, iss, vemap);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (vemap_alltgt)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_remove_lus_from_session_per_vemap(ilport,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iss, vemap_alltgt);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* Assert stmf_lock is already held */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_i_local_port_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_targetident_to_ilport(uint8_t *target_ident, uint16_t ident_size)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_local_port_t *ilport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(mutex_owned(&stmf_state.stmf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ilport = stmf_state.stmf_ilportlist; ilport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport = ilport->ilport_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id = (uint8_t *)ilport->ilport_lport->lport_id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((id[3] == ident_size) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcmp(id + 4, target_ident, ident_size) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ilport);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_i_scsi_session_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_lookup_session_for_hostident(stmf_i_local_port_t *ilport,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *host_ident, uint16_t ident_size)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_scsi_session_t *iss;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(mutex_owned(&stmf_state.stmf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (iss = ilport->ilport_ss_list; iss; iss = iss->iss_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id = (uint8_t *)iss->iss_ss->ss_rport_id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((id[3] == ident_size) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcmp(id + 4, host_ident, ident_size) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (iss);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_i_lu_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_luident_to_ilu(uint8_t *lu_ident)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(mutex_owned(&stmf_state.stmf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ilu = stmf_state.stmf_ilulist; ilu; ilu = ilu->ilu_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (bcmp(&ilu->ilu_lu->lu_id->ident[0], lu_ident, 16) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ilu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Assert stmf_lock is already held,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Just get the view map for the specific target group and host group
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * tgid and hgid can not be NULL
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_lun_map_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_get_ve_map_per_ids(stmf_id_data_t *tgid, stmf_id_data_t *hgid)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int found = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_ver_tg_t *vertg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_ver_hg_t *verhg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(mutex_owned(&stmf_state.stmf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (vertg = stmf_state.stmf_ver_tg_head;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vertg; vertg = vertg->vert_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (vertg->vert_tg_ref == tgid) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte found = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!found)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (verhg = vertg->vert_verh_list; verhg; verhg = verhg->verh_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (verhg->verh_hg_ref == hgid) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (&verhg->verh_ve_map);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto
63ed874a56e20df7e4ec98ba42582352d87386c5tim szetostmf_status_t
63ed874a56e20df7e4ec98ba42582352d87386c5tim szetostmf_validate_lun_view_entry(stmf_id_data_t *hg, stmf_id_data_t *tg,
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto uint8_t *lun, uint32_t *err_detail)
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto{
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto char *phg, *ptg;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto stmf_lun_map_t *ve_map = NULL;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto stmf_ver_hg_t *verhg = NULL;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto stmf_ver_tg_t *vertg = NULL;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto uint16_t lun_num;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto stmf_status_t ret = STMF_SUCCESS;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ASSERT(mutex_owned(&stmf_state.stmf_lock));
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ve_map = stmf_duplicate_ve_map(0);
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto for (vertg = stmf_state.stmf_ver_tg_head; vertg != NULL;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto vertg = vertg->vert_next) {
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ptg = (char *)vertg->vert_tg_ref->id_data;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto if ((ptg[0] != '*') && (tg->id_data[0] != '*') &&
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto (vertg->vert_tg_ref != tg)) {
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto continue;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto }
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto for (verhg = vertg->vert_verh_list; verhg != NULL;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto verhg = verhg->verh_next) {
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto phg = (char *)verhg->verh_hg_ref->id_data;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto if ((phg[0] != '*') && (hg->id_data[0] != '*') &&
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto (verhg->verh_hg_ref != hg)) {
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto continue;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto }
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto (void) stmf_merge_ve_map(&verhg->verh_ve_map, ve_map,
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto &ve_map, 0);
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto }
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto }
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ret = STMF_SUCCESS;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto /* Return an available lun number */
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto if (lun[2] == 0xFF) {
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto /* Pick a LUN number */
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto lun_num = stmf_get_next_free_lun(ve_map, lun);
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto if (lun_num > 0x3FFF)
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ret = STMF_NOT_SUPPORTED;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto } else {
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto lun_num = (uint16_t)lun[1] | (((uint16_t)(lun[0] & 0x3F)) << 8);
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto if (stmf_get_ent_from_map(ve_map, lun_num) != NULL) {
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto *err_detail = STMF_IOCERR_LU_NUMBER_IN_USE;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ret = STMF_LUN_TAKEN;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto }
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto }
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto stmf_destroy_ve_map(ve_map);
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto return (ret);
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto}
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto
63ed874a56e20df7e4ec98ba42582352d87386c5tim szetoint
63ed874a56e20df7e4ec98ba42582352d87386c5tim szetostmf_validate_lun_ve(uint8_t *hgname, uint16_t hgname_size,
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto uint8_t *tgname, uint16_t tgname_size,
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto uint8_t *luNbr, uint32_t *err_detail)
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto{
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto stmf_id_data_t *hg;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto stmf_id_data_t *tg;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto stmf_status_t ret;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ASSERT(mutex_owned(&stmf_state.stmf_lock));
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto hg = stmf_lookup_id(&stmf_state.stmf_hg_list, hgname_size,
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto (uint8_t *)hgname);
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto if (!hg) {
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto *err_detail = STMF_IOCERR_INVALID_HG;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto return (ENOENT); /* could not find group */
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto }
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto tg = stmf_lookup_id(&stmf_state.stmf_tg_list, tgname_size,
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto (uint8_t *)tgname);
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto if (!tg) {
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto *err_detail = STMF_IOCERR_INVALID_TG;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto return (ENOENT); /* could not find group */
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto }
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ret = stmf_validate_lun_view_entry(hg, tg, luNbr, err_detail);
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto if (ret == STMF_LUN_TAKEN) {
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto return (EEXIST);
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto } else if (ret == STMF_NOT_SUPPORTED) {
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto return (E2BIG);
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto } else if (ret != STMF_SUCCESS) {
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto return (EINVAL);
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto }
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto return (0);
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto}