xref: /illumos-gate/usr/src/uts/common/io/comstar/stmf/lun_map.h (revision 8a2b682e57a046b828f37bcde1776f131ef4629f)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 #ifndef	_LUN_MAP_H
26 #define	_LUN_MAP_H
27 
28 #include <sys/stmf_defines.h>
29 
30 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 typedef struct stmf_lun_map {
35 	uint32_t	lm_nluns;
36 	uint32_t	lm_nentries;
37 	void		**lm_plus; /* this can be lun or view entry */
38 } stmf_lun_map_t;
39 
40 struct stmf_itl_data;
41 
42 typedef struct stmf_lun_map_ent {
43 	struct stmf_lu		*ent_lu;
44 	struct stmf_itl_data	*ent_itl_datap;
45 } stmf_lun_map_ent_t;
46 
47 void stmf_view_init();
48 void stmf_view_clear_config();
49 stmf_status_t stmf_session_create_lun_map(stmf_i_local_port_t *ilport,
50 		stmf_i_scsi_session_t *iss);
51 stmf_xfer_data_t *stmf_session_prepare_report_lun_data(stmf_lun_map_t *sm);
52 void stmf_add_lu_to_active_sessions(stmf_lu_t *lu);
53 void stmf_session_lu_unmapall(stmf_lu_t *lu);
54 void *stmf_get_ent_from_map(stmf_lun_map_t *sm, uint16_t lun_num);
55 
56 
57 /*
58  * Common struct used to maintain an Identifer's data. That Identifier
59  * can be a Host group, Target group or LU GUID data. Note that a LU is
60  * different from LU GUID data because either can be there without
61  * its counterpart being present in the system.
62  * id_impl_specific pointer to:
63  * case LUID, a list of stmf_view_entry
64  * case initiator group, a list of initiators
65  * case target group, a list of targets
66  * id_pt_to_object pointer to stmf_i_lu_t instance for LU.
67  */
68 typedef struct stmf_id_data {
69 	struct stmf_id_data		*id_next;
70 	struct stmf_id_data		*id_prev;
71 	uint32_t			id_refcnt;
72 	uint16_t			id_type;
73 	uint16_t			id_data_size;
74 	uint8_t				*id_data;
75 	uint32_t			id_total_alloc_size;
76 	uint32_t			id_rsvd;
77 	void				*id_pt_to_object;
78 	void				*id_impl_specific;
79 } stmf_id_data_t;
80 
81 typedef enum {
82 	STMF_ID_TYPE_HOST,
83 	STMF_ID_TYPE_TARGET,
84 	STMF_ID_TYPE_LU_GUID,
85 	STMF_ID_TYPE_HOST_GROUP,
86 	STMF_ID_TYPE_TARGET_GROUP
87 } stmf_id_type_t;
88 
89 typedef struct stmf_id_list {
90 	stmf_id_data_t		*idl_head;
91 	stmf_id_data_t		*idl_tail;
92 	uint32_t		id_count;
93 } stmf_id_list_t;
94 
95 typedef struct stmf_view_entry {
96 	struct stmf_view_entry	*ve_next;
97 	struct stmf_view_entry	*ve_prev;
98 	uint32_t		ve_id;
99 	stmf_id_data_t		*ve_hg;
100 	stmf_id_data_t		*ve_tg;
101 	stmf_id_data_t		*ve_luid;
102 	uint8_t			ve_lun[8];
103 } stmf_view_entry_t;
104 
105 /*
106  * Following structs are used as an alternate representation of view entries
107  * in a LU ID.
108  * ver_tg_root--->ver_tg_t    +-> ver_tg_t ....
109  *                   |        |
110  *                  vert_next-+
111  *                   |
112  *                   vert_verh_list --> ver_hg_t  +-> ver_hg_t ....
113  *                                        |       |
114  *                                      verh_next-+
115  *                                        |
116  *                                      verh_ve_map (view entry map for this
117  *                                             target group + host group )
118  */
119 
120 typedef struct ver_hg {
121 	struct ver_hg		*verh_next;
122 	stmf_id_data_t		*verh_hg_ref;	/* ref. to the host group */
123 	stmf_lun_map_t		verh_ve_map;
124 } stmf_ver_hg_t;
125 
126 typedef struct ver_tg {
127 	struct ver_tg		*vert_next;
128 	stmf_id_data_t		*vert_tg_ref;	/* ref to target group */
129 	stmf_ver_hg_t		*vert_verh_list;
130 } stmf_ver_tg_t;
131 
132 /*
133  * flag which define how the merging of maps is to be done.
134  */
135 typedef enum {
136 	MERGE_FLAG_NO_DUPLICATE		= 0x01, /* fail upon duplicate */
137 	MERGE_FLAG_RETURN_NEW_MAP	= 0x02, /* Does not modify dst */
138 	MERGE_FLAG_NONE			= 0
139 } stmf_merge_flags_t;
140 
141 int stmf_add_group_member(uint8_t *grpname, uint16_t grpname_size,
142 		uint8_t	*entry_ident, uint16_t entry_size,
143 		stmf_id_type_t entry_type, uint32_t *err_detail);
144 int stmf_remove_group_member(uint8_t *grpname, uint16_t grpname_size,
145 		uint8_t *entry_ident, uint16_t entry_size,
146 		stmf_id_type_t entry_type, uint32_t *err_detail);
147 int stmf_remove_group(uint8_t *grpname, uint16_t grpname_size,
148 		stmf_id_type_t group_type, uint32_t *err_detail);
149 int stmf_add_group(uint8_t *grpname, uint16_t grpname_size,
150 		stmf_id_type_t group_type, uint32_t *err_detail);
151 int stmf_add_ve(uint8_t *hgname, uint16_t hgname_size, uint8_t *tgname,
152 		uint16_t tgname_size, uint8_t *lu_guid, uint32_t *ve_id,
153 		uint8_t *luNbr, uint32_t *err_detail);
154 int stmf_validate_lun_ve(uint8_t *hgname, uint16_t hgname_size, uint8_t *tgname,
155 		uint16_t tgname_size, uint8_t *luNbr, uint32_t *err_detail);
156 int stmf_remove_ve_by_id(uint8_t *guid, uint32_t veid, uint32_t *err_detail);
157 stmf_id_data_t *stmf_lookup_id(stmf_id_list_t *idlist, uint16_t id_size,
158 		uint8_t *data);
159 stmf_id_data_t *stmf_lookup_group_for_target(uint8_t *ident,
160 		uint16_t ident_size);
161 
162 #ifdef	__cplusplus
163 }
164 #endif
165 
166 #endif /* _LUN_MAP_H */
167