lun_map.c revision 780c822c86101e82568fa9e357d13965b9f0cf81
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
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 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
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 * CDDL HEADER END
780c822c86101e82568fa9e357d13965b9f0cf81tim szeto * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid stmf_update_sessions_per_ve(stmf_view_entry_t *ve,
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 Fortestmf_status_t stmf_add_hg(uint8_t *hg_name, uint16_t hg_name_size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_i_local_port_t *stmf_targetident_to_ilport(uint8_t *target_ident,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_i_scsi_session_t *stmf_lookup_session_for_hostident(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_local_port_t *ilport, uint8_t *host_ident,
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 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 Forte * Init the view
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Clear config database here
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_id_data_t *idgrp, *idgrp_next, *idmemb, *idmemb_next;
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 sizeof (void *));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* clear the views for lus */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (idmemb = stmf_state.stmf_luid_list.idl_head;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ve = (stmf_view_entry_t *)idmemb->id_impl_specific;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* free all the host group */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte idlist = (stmf_id_list_t *)(idgrp->id_impl_specific);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* free all the target group */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte idlist = (stmf_id_list_t *)(idgrp->id_impl_specific);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ilport = stmf_state.stmf_ilportlist; ilport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Create luns map for session based on the view
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_session_create_lun_map(stmf_i_local_port_t *ilport,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hg = stmf_lookup_group_for_host(iss->iss_ss->ss_rport_id->ident,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * get the view entry map,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * take all host/target group into consideration
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (vertg = stmf_state.stmf_ver_tg_head; vertg != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (verhg = vertg->vert_verh_list; verhg != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) stmf_merge_ve_map(&verhg->verh_ve_map, ve_map,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_add_lus_to_session_per_vemap(ilport, iss, ve_map);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* not configured, cannot access any luns for now */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * destroy lun map for session
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_session_destroy_lun_map(stmf_i_local_port_t *ilport,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to avoid conflict with updating session's map,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * which only grab stmf_lock
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (stmf_lun_map_ent_t *) * sm->lm_nentries);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Expects the session lock to be held.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_session_prepare_report_lun_data(stmf_lun_map_t *sm)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte alloc_size = data_size + sizeof (stmf_xfer_data_t) - 4;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xd = (stmf_xfer_data_t *)kmem_zalloc(alloc_size, KM_NOSLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; ((i < sm->lm_nentries) && (ent < nluns)); i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Fill in the entry */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xd->buf[8 + (ent << 3) + 0] = ((uchar_t)(i >> 8));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Add a lu to active sessions based on LUN inventory.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Only invoked when the lu is onlined
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte luid = ((stmf_i_lu_t *)lu->lu_stmf_private)->ilu_luid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* we did not configure view for this lun, so just return */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ve = (stmf_view_entry_t *)luid->id_impl_specific;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Unmap a lun from all sessions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte luid = ((stmf_i_lu_t *)lu->lu_stmf_private)->ilu_luid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we did not configure view for this lun, this should be
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ve = (stmf_view_entry_t *)luid->id_impl_specific;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * add lu to a session, stmf_lock is already held
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_add_lu_to_session(stmf_i_local_port_t *ilport,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_i_lu_t *ilu = (stmf_i_lu_t *)lu->lu_stmf_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((uint16_t)lu_nbr[1] | (((uint16_t)(lu_nbr[0] & 0x3F)) << 8));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte atomic_or_32(&ilport->ilport_flags, ILPORT_SS_GOT_INITIAL_LUNS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_zalloc(sizeof (stmf_lun_map_ent_t), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = stmf_add_ent_to_map(sm, (void *)lun_map_ent, lu_nbr);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * do not set lun inventory flag for standby port
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * as this would be handled from peer
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * remvoe lu from a session, stmf_lock is already held
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_remove_lu_from_session(stmf_i_local_port_t *ilport,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((uint16_t)lu_nbr[1] | (((uint16_t)(lu_nbr[0] & 0x3F)) << 8));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(lun_map_ent && lun_map_ent->ent_lu == lu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_do_itl_dereg(lu, lun_map_ent->ent_itl_datap,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free((void *)lun_map_ent, sizeof (stmf_lun_map_ent_t));
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 Fortestmf_update_sessions_per_ve(stmf_view_entry_t *ve,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilu_tmp = (stmf_i_lu_t *)ve->ve_luid->id_pt_to_object;
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 /* No sessions to be updated */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ilport = stmf_state.stmf_ilportlist; ilport != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* This ilport belongs to the target group */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* This host belongs to the host group */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * add luns in view entry map to a session,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and stmf_lock is already held
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_add_lus_to_session_per_vemap(stmf_i_local_port_t *ilport,
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/* remove luns in view entry map from a session */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_remove_lus_from_session_per_vemap(stmf_i_local_port_t *ilport,
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 (void) stmf_remove_lu_from_session(ilport, iss, lu,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_alloc_id(uint16_t id_size, uint16_t type, uint8_t *id_data,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte total_size = ((additional_size + 7) & (~7)) + struct_size +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id = (stmf_id_data_t *)kmem_zalloc(total_size, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id->id_impl_specific = ((uint8_t *)id) + struct_size +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_lookup_id(stmf_id_list_t *idlist, uint16_t id_size, uint8_t *data)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (id = idlist->idl_head; id != NULL; id = id->id_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* Return the target group which a target belong to */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_lookup_group_for_target(uint8_t *ident, uint16_t ident_size)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (tgid = stmf_state.stmf_tg_list.idl_head; tgid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* Return the host group which a host belong to */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_lookup_group_for_host(uint8_t *ident, uint16_t ident_size)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (hgid = stmf_state.stmf_hg_list.idl_head; hgid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_append_id(stmf_id_list_t *idlist, stmf_id_data_t *id)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_remove_id(stmf_id_list_t *idlist, stmf_id_data_t *id)
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 dst = (stmf_lun_map_t *)kmem_zalloc(sizeof (*dst), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (void *), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(dst->lm_plus, dst->lm_nentries * sizeof (void *));
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 nentries = max(dst->lm_nentries, src->lm_nentries);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* If there is not enough space in dst map */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p = (void **)kmem_zalloc(nentries * sizeof (void *), KM_SLEEP);
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 Fortestmf_add_hg(uint8_t *hg_name, uint16_t hg_name_size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id = stmf_alloc_id(hg_name_size, STMF_ID_TYPE_HOST_GROUP,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* add target group */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_add_tg(uint8_t *tg_name, uint16_t tg_name_size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_lookup_id(&stmf_state.stmf_tg_list, tg_name_size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id = stmf_alloc_id(tg_name_size, STMF_ID_TYPE_TARGET_GROUP,
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 Fortestmf_add_ve_to_luid(stmf_id_data_t *luid, stmf_view_entry_t *ve)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ve_tmp = (stmf_view_entry_t *)luid->id_impl_specific;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* search the smallest available veid */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* insert before ve_tmp if it exist */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* stmf_lock is already held, err_detail may be assigned if error happens */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_add_view_entry(stmf_id_data_t *hg, stmf_id_data_t *tg,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_view_entry_t **conflicting, uint32_t *err_detail)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lun_num = ((uint16_t)lun[1] | (((uint16_t)(lun[0] & 0x3F)) << 8));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte luid = stmf_lookup_id(&stmf_state.stmf_luid_list, 16, lu_guid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte luid = stmf_alloc_id(16, STMF_ID_TYPE_LU_GUID, lu_guid, 0);
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 if (((phg[0] == '*') || (ve->ve_hg->id_data[0] == '*') ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (ve->ve_tg->id_data[0] == '*') || (tg == ve->ve_tg))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (vertg = stmf_state.stmf_ver_tg_head; vertg != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ptg[0] != '*') && (tg->id_data[0] != '*') &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (verhg = vertg->vert_verh_list; verhg != NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((phg[0] != '*') && (hg->id_data[0] != '*') &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((vertg_ex == vertg) && (verhg->verh_hg_ref == hg))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) stmf_merge_ve_map(&verhg->verh_ve_map, ve_map,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Pick a LUN number */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((*conflicting = stmf_get_ent_from_map(ve_map, lun_num))
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 if ((ret = stmf_add_ve_to_luid(luid, ve)) != STMF_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_append_id(&stmf_state.stmf_luid_list, luid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vertg_ex = (stmf_ver_tg_t *)kmem_zalloc(sizeof (stmf_ver_tg_t),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vertg_ex->vert_next = stmf_state.stmf_ver_tg_head;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (stmf_ver_hg_t *)kmem_zalloc(sizeof (stmf_ver_hg_t),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte verhg_ex = (stmf_ver_hg_t *)kmem_zalloc(sizeof (stmf_ver_hg_t),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = stmf_add_ent_to_map(&verhg_ex->verh_ve_map, ve, ve->ve_lun);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* we need to update the affected session */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_add_ent_to_map(stmf_lun_map_t *lm, void *ent, uint8_t *lun)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte n = (uint16_t)lun[1] | (((uint16_t)(lun[0] & 0x3F)) << 8);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pplu = (void **)kmem_zalloc(m * sizeof (void *), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(lm->lm_plus, lm->lm_nentries * sizeof (void *));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_remove_ent_from_map(stmf_lun_map_t *lm, uint8_t *lun)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte n = (uint16_t)lun[1] | (((uint16_t)(lun[0] & 0x3F)) << 8);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lm->lm_plus[lm->lm_nentries - 1 - i] != NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (i >= 16) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pplu = (void **)kmem_zalloc(m * sizeof (void *), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(lm->lm_plus, lm->lm_nentries * sizeof (void *));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_get_next_free_lun(stmf_lun_map_t *sm, uint8_t *lun)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (luNbr = 0; luNbr < sm->lm_nentries; luNbr++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0xFFFF);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_get_ent_from_map(stmf_lun_map_t *sm, uint16_t lun_num)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_add_ve(uint8_t *hgname, uint16_t hgname_size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hg = stmf_lookup_id(&stmf_state.stmf_hg_list, hgname_size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tg = stmf_lookup_id(&stmf_state.stmf_tg_list, tgname_size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = stmf_add_view_entry(hg, tg, lu_guid, ve_id, luNbr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_remove_ve_by_id(uint8_t *guid, uint32_t veid, uint32_t *err_detail)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte luid = stmf_lookup_id(&stmf_state.stmf_luid_list, 16, guid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ve = (stmf_view_entry_t *)luid->id_impl_specific;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* remove the ve */
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 /* 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 for (vhg = vtg->vert_verh_list; vhg; vhg = vhg->verh_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) stmf_remove_ent_from_map(&vhg->verh_ve_map, ve->ve_lun);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* free verhg if it don't have any ve entries related */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* we don't have any view entry related */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Free entries in case the map still has memory */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (void *));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* we don't have any ve related */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_add_group(uint8_t *grpname, uint16_t grpname_size,
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 * Group can only be removed only when it does not have
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * any view entry related
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_remove_group(uint8_t *grpname, uint16_t grpname_size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if (group_type == STMF_ID_TYPE_TARGET_GROUP)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *err_detail = (group_type == STMF_ID_TYPE_HOST_GROUP)?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* fail, still have viewentry related to it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *err_detail = (group_type == STMF_ID_TYPE_HOST_GROUP)?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grp_memblist = (stmf_id_list_t *)id->id_impl_specific;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((idmemb = grp_memblist->idl_head) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ilport = stmf_state.stmf_ilportlist; ilport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ilport = stmf_state.stmf_ilportlist; ilport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_add_group_member(uint8_t *grpname, uint16_t grpname_size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id_grp = stmf_lookup_id(&stmf_state.stmf_hg_list,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id_grp_tmp = stmf_lookup_group_for_host(entry_ident,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id_grp = stmf_lookup_id(&stmf_state.stmf_tg_list,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id_grp_tmp = stmf_lookup_group_for_target(entry_ident,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check whether this member already bound to a group */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EEXIST); /* already added into another grp */
f80ea9bbe1103fdcfafa9f1b139df1e2f42ad5c1tim szeto /* verify target is offline */
f80ea9bbe1103fdcfafa9f1b139df1e2f42ad5c1tim szeto ilport = stmf_targetident_to_ilport(entry_ident, entry_size);
f80ea9bbe1103fdcfafa9f1b139df1e2f42ad5c1tim szeto if (ilport && ilport->ilport_state != STMF_STATE_OFFLINE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id_member = stmf_alloc_id(entry_size, entry_type,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_append_id((stmf_id_list_t *)id_grp->id_impl_specific, id_member);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport = stmf_targetident_to_ilport(entry_ident, entry_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* For host group member, update the session if needed */
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 vemap_alltgt = stmf_get_ve_map_per_ids(id_alltgt, id_grp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* check whether there are sessions may be affected */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ilport = stmf_state.stmf_ilportlist; ilport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_remove_group_member(uint8_t *grpname, uint16_t grpname_size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id_grp = stmf_lookup_id(&stmf_state.stmf_hg_list,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id_grp = stmf_lookup_id(&stmf_state.stmf_tg_list,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte id_member = stmf_lookup_id((stmf_id_list_t *)id_grp->id_impl_specific,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_IOCERR_INVALID_HG_ENTRY:STMF_IOCERR_INVALID_TG_ENTRY;
5c8cac22647b12e79982cf052e5df46dc7402bd5tim szeto /* verify target is offline */
5c8cac22647b12e79982cf052e5df46dc7402bd5tim szeto ilport = stmf_targetident_to_ilport(entry_ident, entry_size);
5c8cac22647b12e79982cf052e5df46dc7402bd5tim szeto if (ilport && ilport->ilport_state != STMF_STATE_OFFLINE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_remove_id((stmf_id_list_t *)id_grp->id_impl_specific, id_member);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilport = stmf_targetident_to_ilport(entry_ident, entry_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* For host group member, update the session */
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 vemap_alltgt = stmf_get_ve_map_per_ids(id_alltgt, id_grp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* check if there are session related, if so, update it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ilport = stmf_state.stmf_ilportlist; ilport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* Assert stmf_lock is already held */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_targetident_to_ilport(uint8_t *target_ident, uint16_t ident_size)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ilport = stmf_state.stmf_ilportlist; ilport;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_lookup_session_for_hostident(stmf_i_local_port_t *ilport,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (iss = ilport->ilport_ss_list; iss; iss = iss->iss_next) {
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 * 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 Fortestmf_get_ve_map_per_ids(stmf_id_data_t *tgid, stmf_id_data_t *hgid)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (verhg = vertg->vert_verh_list; verhg; verhg = verhg->verh_next) {
63ed874a56e20df7e4ec98ba42582352d87386c5tim szetostmf_validate_lun_view_entry(stmf_id_data_t *hg, stmf_id_data_t *tg,
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto for (vertg = stmf_state.stmf_ver_tg_head; vertg != NULL;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto for (verhg = vertg->vert_verh_list; verhg != NULL;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto (void) stmf_merge_ve_map(&verhg->verh_ve_map, ve_map,
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto /* Return an available lun number */
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto /* Pick a LUN number */
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 szetostmf_validate_lun_ve(uint8_t *hgname, uint16_t hgname_size,
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto hg = stmf_lookup_id(&stmf_state.stmf_hg_list, hgname_size,
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto tg = stmf_lookup_id(&stmf_state.stmf_tg_list, tgname_size,