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