xref: /titanic_44/usr/src/lib/libstmf/common/libstmf.h (revision e272e4c8df90e762ecb6a6564503bb2cb1e2027d)
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 
26 #ifndef	_LIBSTMF_H
27 #define	_LIBSTMF_H
28 
29 #include <time.h>
30 #include <sys/param.h>
31 #include <libnvpair.h>
32 
33 #ifdef	__cplusplus
34 extern "C" {
35 #endif
36 
37 /* Constants and Types */
38 
39 /* LU and Local Port states */
40 #define	STMF_LOGICAL_UNIT_OFFLINE	0
41 #define	STMF_LOGICAL_UNIT_OFFLINING	1
42 #define	STMF_LOGICAL_UNIT_ONLINE	2
43 #define	STMF_LOGICAL_UNIT_ONLINING	3
44 #define	STMF_LOGICAL_UNIT_UNREGISTERED	4
45 #define	STMF_TARGET_PORT_OFFLINE	5
46 #define	STMF_TARGET_PORT_OFFLINING	6
47 #define	STMF_TARGET_PORT_ONLINE		7
48 #define	STMF_TARGET_PORT_ONLINING	8
49 #define	STMF_SERVICE_STATE_ONLINE	9
50 #define	STMF_SERVICE_STATE_OFFLINE	10
51 #define	STMF_SERVICE_STATE_ONLINING	11
52 #define	STMF_SERVICE_STATE_OFFLINING	12
53 #define	STMF_SERVICE_STATE_UNKNOWN	13
54 #define	STMF_CONFIG_STATE_NONE		14
55 #define	STMF_CONFIG_STATE_INIT		15
56 #define	STMF_CONFIG_STATE_INIT_DONE	16
57 #define	STMF_CONFIG_STATE_UNKNOWN	17
58 
59 #define	STMF_IDENT_LENGTH   255
60 
61 /* API status return values */
62 #define	STMF_STATUS_SUCCESS	    0x0000
63 #define	STMF_STATUS_ERROR	    0x8000
64 #define	STMF_ERROR_BUSY			(STMF_STATUS_ERROR | 0x01)
65 #define	STMF_ERROR_NOT_FOUND		(STMF_STATUS_ERROR | 0x02)
66 #define	STMF_ERROR_MEMBER_NOT_FOUND	(STMF_STATUS_ERROR | 0x03)
67 #define	STMF_ERROR_GROUP_NOT_FOUND	(STMF_STATUS_ERROR | 0x04)
68 #define	STMF_ERROR_PERM			(STMF_STATUS_ERROR | 0x05)
69 #define	STMF_ERROR_NOMEM		(STMF_STATUS_ERROR | 0x06)
70 #define	STMF_ERROR_INVALID_ARG		(STMF_STATUS_ERROR | 0x07)
71 #define	STMF_ERROR_EXISTS		(STMF_STATUS_ERROR | 0x08)
72 #define	STMF_ERROR_SERVICE_NOT_FOUND	(STMF_STATUS_ERROR | 0x09)
73 #define	STMF_ERROR_SERVICE_ONLINE	(STMF_STATUS_ERROR | 0x0a)
74 #define	STMF_ERROR_SERVICE_OFFLINE	(STMF_STATUS_ERROR | 0x0b)
75 #define	STMF_ERROR_GROUP_IN_USE		(STMF_STATUS_ERROR | 0x0c)
76 #define	STMF_ERROR_LUN_IN_USE		(STMF_STATUS_ERROR | 0x0d)
77 #define	STMF_ERROR_VE_CONFLICT		(STMF_STATUS_ERROR | 0x0e)
78 #define	STMF_ERROR_CONFIG_NONE		(STMF_STATUS_ERROR | 0x0f)
79 #define	STMF_ERROR_SERVICE_DATA_VERSION (STMF_STATUS_ERROR | 0x10)
80 #define	STMF_ERROR_INVALID_HG		(STMF_STATUS_ERROR | 0x11)
81 #define	STMF_ERROR_INVALID_TG		(STMF_STATUS_ERROR | 0x12)
82 #define	STMF_ERROR_PROV_DATA_STALE	(STMF_STATUS_ERROR | 0x13)
83 #define	STMF_ERROR_NO_PROP		(STMF_STATUS_ERROR | 0x14)
84 #define	STMF_ERROR_NO_PROP_VAL		(STMF_STATUS_ERROR | 0x15)
85 #define	STMF_ERROR_MISSING_PROP_VAL	(STMF_STATUS_ERROR | 0x16)
86 #define	STMF_ERROR_INVALID_BLOCKSIZE	(STMF_STATUS_ERROR | 0x17)
87 #define	STMF_ERROR_FILE_ALREADY		(STMF_STATUS_ERROR | 0x18)
88 #define	STMF_ERROR_INVALID_PROPSIZE	(STMF_STATUS_ERROR | 0x19)
89 #define	STMF_ERROR_INVALID_PROP		(STMF_STATUS_ERROR | 0x20)
90 #define	STMF_ERROR_PERSIST_TYPE		(STMF_STATUS_ERROR | 0x21)
91 #define	STMF_ERROR_TG_ONLINE		(STMF_STATUS_ERROR | 0x22)
92 
93 /* Failures for stmfCreateLu */
94 #define	STMF_ERROR_FILE_IN_USE		(STMF_STATUS_ERROR | 0x100)
95 #define	STMF_ERROR_INVALID_BLKSIZE	(STMF_STATUS_ERROR | 0x101)
96 #define	STMF_ERROR_GUID_IN_USE		(STMF_STATUS_ERROR | 0x102)
97 #define	STMF_ERROR_META_FILE_NAME	(STMF_STATUS_ERROR | 0x103)
98 #define	STMF_ERROR_DATA_FILE_NAME	(STMF_STATUS_ERROR | 0x104)
99 #define	STMF_ERROR_SIZE_OUT_OF_RANGE	(STMF_STATUS_ERROR | 0x105)
100 #define	STMF_ERROR_LU_BUSY		(STMF_STATUS_ERROR | 0x106)
101 #define	STMF_ERROR_META_CREATION	(STMF_STATUS_ERROR | 0x107)
102 #define	STMF_ERROR_FILE_SIZE_INVALID	(STMF_STATUS_ERROR | 0x108)
103 #define	STMF_ERROR_WRITE_CACHE_SET	(STMF_STATUS_ERROR | 0x109)
104 
105 /* Initiator Name Types */
106 #define	STMF_FC_PORT_WWN	    1
107 #define	STMF_ISCSI_NAME		    2
108 
109 
110 /* provider types */
111 #define	STMF_LU_PROVIDER_TYPE	1
112 #define	STMF_PORT_PROVIDER_TYPE	2
113 
114 /* LU Resource types */
115 #define	STMF_DISK   0
116 
117 /* Persistence methods */
118 #define	STMF_PERSIST_SMF	1
119 #define	STMF_PERSIST_NONE	2
120 
121 /*
122  * LU Disk Properties
123  */
124 
125 enum {
126 	STMF_LU_PROP_ALIAS = 1,
127 	STMF_LU_PROP_BLOCK_SIZE,
128 	STMF_LU_PROP_COMPANY_ID,
129 	STMF_LU_PROP_FILENAME,
130 	STMF_LU_PROP_GUID,
131 	STMF_LU_PROP_META_FILENAME,
132 	STMF_LU_PROP_MGMT_URL,
133 	STMF_LU_PROP_NEW,
134 	STMF_LU_PROP_SIZE,
135 	STMF_LU_PROP_WRITE_PROTECT,
136 	STMF_LU_PROP_WRITE_CACHE_DISABLE,
137 	STMF_LU_PROP_VID,
138 	STMF_LU_PROP_PID,
139 	STMF_LU_PROP_SERIAL_NUM
140 };
141 
142 
143 /* devid code set and name types */
144 #define	EUI_64_TYPE	2
145 #define	NAA_TYPE	3
146 #define	SCSI_NAME_TYPE	8
147 
148 #define	BINARY_CODE_SET	1
149 #define	ASCII_CODE_SET	2
150 #define	UTF_8_CODE_SET	3
151 
152 typedef enum _stmfProtocol
153 {
154 	STMF_PROTOCOL_FIBRE_CHANNEL =	0,
155 	STMF_PROTOCOL_ISCSI =		1,
156 	STMF_PROTOCOL_SAS =		2
157 } stmfProtocol;
158 
159 
160 typedef struct _stmfGuid
161 {
162 	uchar_t	guid[16];
163 } stmfGuid;
164 
165 typedef struct _stmfGuidList
166 {
167 	uint32_t cnt;
168 	stmfGuid guid[1];
169 } stmfGuidList;
170 
171 typedef struct _stmfState
172 {
173 	int operationalState;
174 	int configState;
175 } stmfState;
176 
177 typedef struct _stmfDevid
178 {
179 	uint8_t identLength;	/* length of ident */
180 	uint8_t	ident[STMF_IDENT_LENGTH]; /* SCSI name string ident */
181 } stmfDevid;
182 
183 typedef struct _stmfDevidList
184 {
185 	uint32_t cnt;
186 	stmfDevid devid[1];
187 } stmfDevidList;
188 
189 typedef char stmfGroupName[256];
190 typedef char stmfProviderName[256];
191 
192 typedef struct _stmfGroupList
193 {
194 	uint32_t cnt;
195 	stmfGroupName name[1];
196 } stmfGroupList;
197 
198 typedef struct _stmfProvider
199 {
200 	int providerType;
201 	stmfProviderName name;
202 } stmfProvider;
203 
204 typedef struct _stmfProviderList
205 {
206 	uint32_t cnt;
207 	stmfProvider provider[1];
208 } stmfProviderList;
209 
210 typedef struct _stmfSession
211 {
212 	stmfDevid initiator;
213 	char alias[256];
214 	time_t creationTime;
215 } stmfSession;
216 
217 typedef struct _stmfSessionList
218 {
219 	uint32_t cnt;
220 	stmfSession session[1];
221 } stmfSessionList;
222 
223 
224 typedef struct _stmfViewEntry
225 {
226 	boolean_t	veIndexValid;	/* if B_TRUE, veIndex is valid value */
227 	uint32_t	veIndex;	/* View Entry index */
228 	boolean_t	allHosts;	/* all initiator ports */
229 	stmfGroupName   hostGroup;	/* Host Group Name */
230 	boolean_t	allTargets;	/* B_TRUE = targetGroup is invalid */
231 	stmfGroupName	targetGroup;	/* Target Group Name */
232 	boolean_t	luNbrValid;	/* if B_TRUE, luNbr is a valid value */
233 	uchar_t		luNbr[8];	/* LU number for this view entry */
234 } stmfViewEntry;
235 
236 typedef struct _stmfViewEntryList
237 {
238 	uint32_t cnt;
239 	stmfViewEntry ve[1];
240 } stmfViewEntryList;
241 
242 typedef struct _stmfViewEntryProperties
243 {
244 	stmfGuid	associatedLogicalUnitGuid;
245 	stmfViewEntry	viewEntry;
246 } stmfViewEntryProperties;
247 
248 typedef struct _stmfGroupProperties
249 {
250 	uint32_t	cnt;
251 	stmfDevid	name[1];
252 } stmfGroupProperties;
253 
254 typedef struct _stmfTargetProperties
255 {
256 	stmfProviderName providerName;
257 	char		 alias[256];
258 	uint16_t	 status;
259 	stmfProtocol	 protocol;
260 	stmfDevid	 devid;
261 } stmfTargetProperties;
262 
263 typedef struct _stmfLogicalUnitProperties
264 {
265 	char	    alias[256];
266 	uchar_t	    vendor[8];
267 	uchar_t	    product[16];
268 	uchar_t	    revision[4];
269 	uint32_t    status;
270 	char	    providerName[256];
271 	stmfGuid    luid;
272 } stmfLogicalUnitProperties;
273 
274 typedef void * luResource;
275 
276 typedef struct _stmfLogicalUnitProviderProperties
277 {
278 	char	    providerName[MAXPATHLEN];
279 	uint32_t    instance;
280 	uint32_t    status;
281 	uchar_t	    rsvd[64];
282 } stmfLogicalUnitProviderProperties;
283 
284 typedef struct _stmfLocalPortProviderProperties
285 {
286 	char	    providerName[MAXPATHLEN];
287 	uint32_t    instance;
288 	uint32_t    status;
289 	uchar_t	    rsvd[64];
290 } stmfLocalPortProviderProperties;
291 
292 
293 /* API prototypes */
294 int stmfAddToHostGroup(stmfGroupName *hostGroupName, stmfDevid *name);
295 int stmfAddToTargetGroup(stmfGroupName *targetGroupName, stmfDevid *targetName);
296 int stmfAddViewEntry(stmfGuid *lu, stmfViewEntry *viewEntry);
297 int stmfClearProviderData(char *providerName, int providerType);
298 int stmfCreateHostGroup(stmfGroupName *hostGroupName);
299 int stmfCreateLu(luResource hdl, stmfGuid *luGuid);
300 int stmfCreateLuResource(uint16_t dType, luResource *hdl);
301 int stmfCreateTargetGroup(stmfGroupName *targetGroupName);
302 int stmfDeleteHostGroup(stmfGroupName *hostGroupName);
303 int stmfDeleteLu(stmfGuid *luGuid);
304 int stmfDeleteTargetGroup(stmfGroupName *targetGroupName);
305 int stmfDevidFromIscsiName(char *iscsiName, stmfDevid *devid);
306 int stmfDevidFromWwn(uchar_t wwn[8], stmfDevid *devid);
307 int stmfFreeLuResource(luResource hdl);
308 void stmfFreeMemory(void *);
309 int stmfGetHostGroupList(stmfGroupList **initiatorGroupList);
310 int stmfGetHostGroupMembers(stmfGroupName *hostGroupName,
311     stmfGroupProperties **groupProperties);
312 int stmfGetLocalPortProviderList(stmfProviderList **localPortProviderList);
313 int stmfGetLocalPortProviderProperties(stmfProviderName *providerName,
314     stmfLocalPortProviderProperties *providerProperties);
315 int stmfGetLogicalUnitList(stmfGuidList **logicalUnitList);
316 int stmfGetLogicalUnitProperties(stmfGuid *logicalUnit,
317     stmfLogicalUnitProperties *logicalUnitProps);
318 int stmfGetLogicalUnitProviderList(stmfProviderList **logicalUnitProviderList);
319 int stmfGetLogicalUnitProviderProperties(stmfProviderName *providerName,
320     stmfLogicalUnitProviderProperties *providerProperties);
321 int stmfGetLuProp(luResource hdl, uint32_t propType, char *prop,
322     size_t *propLen);
323 int stmfGetLuResource(stmfGuid *luGuid, luResource *hdl);
324 int stmfGetPersistMethod(uint8_t *persistType, boolean_t serviceState);
325 int stmfGetProviderData(char *providerName, nvlist_t **nvl, int providerType);
326 int stmfGetProviderDataProt(char *providerName, nvlist_t **nvl,
327     int providerType, uint64_t *setToken);
328 int stmfGetSessionList(stmfDevid *target, stmfSessionList **sessionList);
329 int stmfGetState(stmfState *);
330 int stmfGetTargetGroupList(stmfGroupList **targetGroupList);
331 int stmfGetTargetGroupMembers(stmfGroupName *targetGroupName,
332     stmfGroupProperties **groupProperties);
333 int stmfGetTargetList(stmfDevidList **targetList);
334 int stmfGetTargetProperties(stmfDevid *target,
335     stmfTargetProperties *targetProps);
336 int stmfGetViewEntryList(stmfGuid *lu, stmfViewEntryList **viewEntryList);
337 int stmfImportLu(uint16_t dType, char *fname, stmfGuid *luGuid);
338 int stmfLoadConfig(void);
339 int stmfModifyLu(stmfGuid *luGuid, uint32_t prop, const char *propVal);
340 int stmfModifyLuByFname(uint16_t dType, const char *fname, uint32_t prop,
341     const char *propVal);
342 int stmfOffline(void);
343 int stmfOfflineTarget(stmfDevid *devid);
344 int stmfOfflineLogicalUnit(stmfGuid *logicalUnit);
345 int stmfOnline(void);
346 int stmfOnlineTarget(stmfDevid *devid);
347 int stmfOnlineLogicalUnit(stmfGuid *logicalUnit);
348 int stmfRemoveFromHostGroup(stmfGroupName *hostGroupName,
349     stmfDevid *initiatorName);
350 int stmfRemoveFromTargetGroup(stmfGroupName *targetGroupName,
351     stmfDevid *targetName);
352 int stmfRemoveViewEntry(stmfGuid *lu, uint32_t viewEntryIndex);
353 int stmfSetLuProp(luResource hdl, uint32_t propType, const char *propVal);
354 int stmfSetPersistMethod(uint8_t persistType, boolean_t serviceSet);
355 int stmfSetProviderData(char *providerName, nvlist_t *nvl, int providerType);
356 int stmfSetProviderDataProt(char *providerName, nvlist_t *nvl,
357     int providerType, uint64_t *setToken);
358 
359 #ifdef	__cplusplus
360 }
361 #endif
362 
363 #endif	/* _LIBSTMF_H */
364