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