xref: /titanic_41/usr/src/lib/libstmf/common/libstmf.h (revision b509e89b2befbaa42939abad9da1d7f5a8c6aaae)
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 
92 /* Failures for stmfCreateLu */
93 #define	STMF_ERROR_FILE_IN_USE		(STMF_STATUS_ERROR | 0x100)
94 #define	STMF_ERROR_INVALID_BLKSIZE	(STMF_STATUS_ERROR | 0x101)
95 #define	STMF_ERROR_GUID_IN_USE		(STMF_STATUS_ERROR | 0x102)
96 #define	STMF_ERROR_META_FILE_NAME	(STMF_STATUS_ERROR | 0x103)
97 #define	STMF_ERROR_DATA_FILE_NAME	(STMF_STATUS_ERROR | 0x104)
98 #define	STMF_ERROR_SIZE_OUT_OF_RANGE	(STMF_STATUS_ERROR | 0x105)
99 #define	STMF_ERROR_LU_BUSY		(STMF_STATUS_ERROR | 0x106)
100 #define	STMF_ERROR_META_CREATION	(STMF_STATUS_ERROR | 0x107)
101 #define	STMF_ERROR_FILE_SIZE_INVALID	(STMF_STATUS_ERROR | 0x108)
102 #define	STMF_ERROR_WRITE_CACHE_SET	(STMF_STATUS_ERROR | 0x109)
103 
104 /* Initiator Name Types */
105 #define	STMF_FC_PORT_WWN	    1
106 #define	STMF_ISCSI_NAME		    2
107 
108 
109 /* provider types */
110 #define	STMF_LU_PROVIDER_TYPE	1
111 #define	STMF_PORT_PROVIDER_TYPE	2
112 
113 /* LU Resource types */
114 #define	STMF_DISK   0
115 
116 /* Persistence methods */
117 #define	STMF_PERSIST_SMF	1
118 #define	STMF_PERSIST_NONE	2
119 
120 /*
121  * LU Disk Properties
122  */
123 
124 enum {
125 	STMF_LU_PROP_ALIAS = 1,
126 	STMF_LU_PROP_BLOCK_SIZE,
127 	STMF_LU_PROP_COMPANY_ID,
128 	STMF_LU_PROP_FILENAME,
129 	STMF_LU_PROP_GUID,
130 	STMF_LU_PROP_META_FILENAME,
131 	STMF_LU_PROP_NEW,
132 	STMF_LU_PROP_SIZE,
133 	STMF_LU_PROP_WRITE_PROTECT,
134 	STMF_LU_PROP_WRITE_CACHE_DISABLE,
135 	STMF_LU_PROP_VID,
136 	STMF_LU_PROP_PID,
137 	STMF_LU_PROP_SERIAL_NUM
138 };
139 
140 
141 /* devid code set and name types */
142 #define	EUI_64_TYPE	2
143 #define	NAA_TYPE	3
144 #define	SCSI_NAME_TYPE	8
145 
146 #define	BINARY_CODE_SET	1
147 #define	ASCII_CODE_SET	2
148 #define	UTF_8_CODE_SET	3
149 
150 typedef enum _stmfProtocol
151 {
152 	STMF_PROTOCOL_FIBRE_CHANNEL =	0,
153 	STMF_PROTOCOL_ISCSI =		1,
154 	STMF_PROTOCOL_SAS =		2
155 } stmfProtocol;
156 
157 
158 typedef struct _stmfGuid
159 {
160 	uchar_t	guid[16];
161 } stmfGuid;
162 
163 typedef struct _stmfGuidList
164 {
165 	uint32_t cnt;
166 	stmfGuid guid[1];
167 } stmfGuidList;
168 
169 typedef struct _stmfState
170 {
171 	int operationalState;
172 	int configState;
173 } stmfState;
174 
175 typedef struct _stmfDevid
176 {
177 	uint8_t identLength;	/* length of ident */
178 	uint8_t	ident[STMF_IDENT_LENGTH]; /* SCSI name string ident */
179 } stmfDevid;
180 
181 typedef struct _stmfDevidList
182 {
183 	uint32_t cnt;
184 	stmfDevid devid[1];
185 } stmfDevidList;
186 
187 typedef char stmfGroupName[256];
188 typedef char stmfProviderName[256];
189 
190 typedef struct _stmfGroupList
191 {
192 	uint32_t cnt;
193 	stmfGroupName name[1];
194 } stmfGroupList;
195 
196 typedef struct _stmfProvider
197 {
198 	int providerType;
199 	stmfProviderName name;
200 } stmfProvider;
201 
202 typedef struct _stmfProviderList
203 {
204 	uint32_t cnt;
205 	stmfProvider provider[1];
206 } stmfProviderList;
207 
208 typedef struct _stmfSession
209 {
210 	stmfDevid initiator;
211 	char alias[256];
212 	time_t creationTime;
213 } stmfSession;
214 
215 typedef struct _stmfSessionList
216 {
217 	uint32_t cnt;
218 	stmfSession session[1];
219 } stmfSessionList;
220 
221 
222 typedef struct _stmfViewEntry
223 {
224 	boolean_t	veIndexValid;	/* if B_TRUE, veIndex is valid value */
225 	uint32_t	veIndex;	/* View Entry index */
226 	boolean_t	allHosts;	/* all initiator ports */
227 	stmfGroupName   hostGroup;	/* Host Group Name */
228 	boolean_t	allTargets;	/* B_TRUE = targetGroup is invalid */
229 	stmfGroupName	targetGroup;	/* Target Group Name */
230 	boolean_t	luNbrValid;	/* if B_TRUE, luNbr is a valid value */
231 	uchar_t		luNbr[8];	/* LU number for this view entry */
232 } stmfViewEntry;
233 
234 typedef struct _stmfViewEntryList
235 {
236 	uint32_t cnt;
237 	stmfViewEntry ve[1];
238 } stmfViewEntryList;
239 
240 typedef struct _stmfViewEntryProperties
241 {
242 	stmfGuid	associatedLogicalUnitGuid;
243 	stmfViewEntry	viewEntry;
244 } stmfViewEntryProperties;
245 
246 typedef struct _stmfGroupProperties
247 {
248 	uint32_t	cnt;
249 	stmfDevid	name[1];
250 } stmfGroupProperties;
251 
252 typedef struct _stmfTargetProperties
253 {
254 	stmfProviderName providerName;
255 	char		 alias[256];
256 	uint16_t	 status;
257 	stmfProtocol	 protocol;
258 	stmfDevid	 devid;
259 } stmfTargetProperties;
260 
261 typedef struct _stmfLogicalUnitProperties
262 {
263 	char	    alias[256];
264 	uchar_t	    vendor[8];
265 	uchar_t	    product[16];
266 	uchar_t	    revision[4];
267 	uint32_t    status;
268 	char	    providerName[256];
269 	stmfGuid    luid;
270 } stmfLogicalUnitProperties;
271 
272 typedef void * luResource;
273 
274 typedef struct _stmfLogicalUnitProviderProperties
275 {
276 	char	    providerName[MAXPATHLEN];
277 	uint32_t    instance;
278 	uint32_t    status;
279 	uchar_t	    rsvd[64];
280 } stmfLogicalUnitProviderProperties;
281 
282 typedef struct _stmfLocalPortProviderProperties
283 {
284 	char	    providerName[MAXPATHLEN];
285 	uint32_t    instance;
286 	uint32_t    status;
287 	uchar_t	    rsvd[64];
288 } stmfLocalPortProviderProperties;
289 
290 
291 /* API prototypes */
292 int stmfAddToHostGroup(stmfGroupName *hostGroupName, stmfDevid *name);
293 int stmfAddToTargetGroup(stmfGroupName *targetGroupName, stmfDevid *targetName);
294 int stmfAddViewEntry(stmfGuid *lu, stmfViewEntry *viewEntry);
295 int stmfClearProviderData(char *providerName, int providerType);
296 int stmfCreateHostGroup(stmfGroupName *hostGroupName);
297 int stmfCreateLu(luResource hdl, stmfGuid *luGuid);
298 int stmfCreateLuResource(uint16_t dType, luResource *hdl);
299 int stmfCreateTargetGroup(stmfGroupName *targetGroupName);
300 int stmfDeleteHostGroup(stmfGroupName *hostGroupName);
301 int stmfDeleteLu(stmfGuid *luGuid);
302 int stmfDeleteTargetGroup(stmfGroupName *targetGroupName);
303 int stmfDevidFromIscsiName(char *iscsiName, stmfDevid *devid);
304 int stmfDevidFromWwn(uchar_t wwn[8], stmfDevid *devid);
305 int stmfFreeLuResource(luResource hdl);
306 void stmfFreeMemory(void *);
307 int stmfGetHostGroupList(stmfGroupList **initiatorGroupList);
308 int stmfGetHostGroupMembers(stmfGroupName *hostGroupName,
309     stmfGroupProperties **groupProperties);
310 int stmfGetLocalPortProviderList(stmfProviderList **localPortProviderList);
311 int stmfGetLocalPortProviderProperties(stmfProviderName *providerName,
312     stmfLocalPortProviderProperties *providerProperties);
313 int stmfGetLogicalUnitList(stmfGuidList **logicalUnitList);
314 int stmfGetLogicalUnitProperties(stmfGuid *logicalUnit,
315     stmfLogicalUnitProperties *logicalUnitProps);
316 int stmfGetLogicalUnitProviderList(stmfProviderList **logicalUnitProviderList);
317 int stmfGetLogicalUnitProviderProperties(stmfProviderName *providerName,
318     stmfLogicalUnitProviderProperties *providerProperties);
319 int stmfGetLuProp(luResource hdl, uint32_t propType, char *prop,
320     size_t *propLen);
321 int stmfGetLuResource(stmfGuid *luGuid, luResource *hdl);
322 int stmfGetPersistMethod(uint8_t *persistType, boolean_t serviceState);
323 int stmfGetProviderData(char *providerName, nvlist_t **nvl, int providerType);
324 int stmfGetProviderDataProt(char *providerName, nvlist_t **nvl,
325     int providerType, uint64_t *setToken);
326 int stmfGetSessionList(stmfDevid *target, stmfSessionList **sessionList);
327 int stmfGetState(stmfState *);
328 int stmfGetTargetGroupList(stmfGroupList **targetGroupList);
329 int stmfGetTargetGroupMembers(stmfGroupName *targetGroupName,
330     stmfGroupProperties **groupProperties);
331 int stmfGetTargetList(stmfDevidList **targetList);
332 int stmfGetTargetProperties(stmfDevid *target,
333     stmfTargetProperties *targetProps);
334 int stmfGetViewEntryList(stmfGuid *lu, stmfViewEntryList **viewEntryList);
335 int stmfImportLu(uint16_t dType, char *fname, stmfGuid *luGuid);
336 int stmfLoadConfig(void);
337 int stmfModifyLu(stmfGuid *luGuid, uint32_t prop, const char *propVal);
338 int stmfModifyLuByFname(uint16_t dType, const char *fname, uint32_t prop,
339     const char *propVal);
340 int stmfOffline(void);
341 int stmfOfflineTarget(stmfDevid *devid);
342 int stmfOfflineLogicalUnit(stmfGuid *logicalUnit);
343 int stmfOnline(void);
344 int stmfOnlineTarget(stmfDevid *devid);
345 int stmfOnlineLogicalUnit(stmfGuid *logicalUnit);
346 int stmfRemoveFromHostGroup(stmfGroupName *hostGroupName,
347     stmfDevid *initiatorName);
348 int stmfRemoveFromTargetGroup(stmfGroupName *targetGroupName,
349     stmfDevid *targetName);
350 int stmfRemoveViewEntry(stmfGuid *lu, uint32_t viewEntryIndex);
351 int stmfSetLuProp(luResource hdl, uint32_t propType, const char *propVal);
352 int stmfSetPersistMethod(uint8_t persistType, boolean_t serviceSet);
353 int stmfSetProviderData(char *providerName, nvlist_t *nvl, int providerType);
354 int stmfSetProviderDataProt(char *providerName, nvlist_t *nvl,
355     int providerType, uint64_t *setToken);
356 
357 #ifdef	__cplusplus
358 }
359 #endif
360 
361 #endif	/* _LIBSTMF_H */
362