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