xref: /titanic_41/usr/src/lib/scsi/libses/common/libses.h (revision 9e39c5ba00a55fa05777cc94b148296af305e135)
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 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_LIBSES_H
28 #define	_LIBSES_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/types.h>
37 
38 #include <stdarg.h>
39 #include <libnvpair.h>
40 #include <pthread.h>
41 
42 #include <scsi/libscsi.h>
43 #include <scsi/plugins/ses/framework/ses2.h>
44 #include <scsi/plugins/ses/framework/libses.h>
45 
46 #define	LIBSES_VERSION	1
47 
48 typedef enum ses_node_type {
49 	SES_NODE_NONE = 0x0,
50 	SES_NODE_TARGET = 0x1,
51 	SES_NODE_ENCLOSURE = 0x2,
52 	SES_NODE_AGGREGATE = 0x4,
53 	SES_NODE_ELEMENT = 0x8
54 } ses_node_type_t;
55 
56 typedef enum ses_errno {
57 	ESES_NONE,		/* no error */
58 	ESES_NOMEM,		/* no memory */
59 	ESES_ZERO_LENGTH,	/* zero-length allocation requested */
60 	ESES_VERSION,		/* library version mismatch */
61 	ESES_NVL,		/* nvlist manipulation error */
62 	ESES_BAD_NODE,		/* bad node */
63 	ESES_INVALID_OP,	/* invalid operation */
64 	ESES_RANGE,		/* value out of range */
65 	ESES_INVALID_PROP,	/* nonexistent or immutable property */
66 	ESES_BAD_TYPE,		/* incorrect property type */
67 	ESES_BAD_PAGE,		/* bad page number */
68 	ESES_BAD_RESPONSE,	/* bad response from target */
69 	ESES_BUSY,		/* target busy */
70 	ESES_TOOMUCHCHANGE,	/* target configuration changing too rapidly */
71 	ESES_LIBSCSI,		/* SCSI error */
72 	ESES_NOTSUP,		/* operation not supported */
73 	ESES_UNKNOWN,		/* error of unknown type */
74 	ESES_CHANGED,		/* generation count has changed */
75 	ESES_PLUGIN,		/* invalid or missing plugin */
76 	ESES_MAX		/* maximum libses errno value */
77 } ses_errno_t;
78 
79 struct ses_target;
80 typedef struct ses_target ses_target_t;
81 
82 struct ses_snap;
83 typedef struct ses_snap ses_snap_t;
84 
85 struct ses_node;
86 typedef struct ses_node ses_node_t;
87 
88 extern ses_target_t *ses_open(uint_t, const char *);
89 extern ses_target_t *ses_open_scsi(uint_t, libscsi_target_t *);
90 extern void ses_close(ses_target_t *);
91 
92 extern libscsi_target_t *ses_scsi_target(ses_target_t *);
93 
94 typedef enum ses_walk_action {
95 	SES_WALK_ACTION_CONTINUE,
96 	SES_WALK_ACTION_PRUNE,
97 	SES_WALK_ACTION_TERMINATE
98 } ses_walk_action_t;
99 
100 typedef ses_walk_action_t (*ses_walk_f)(ses_node_t *, void *);
101 
102 extern uint64_t ses_node_id(ses_node_t *);
103 extern ses_node_t *ses_node_lookup(ses_snap_t *, uint64_t);
104 
105 extern ses_node_t *ses_root_node(ses_snap_t *);
106 extern ses_node_t *ses_node_sibling(ses_node_t *);
107 extern ses_node_t *ses_node_prev_sibling(ses_node_t *);
108 extern ses_node_t *ses_node_child(ses_node_t *);
109 extern ses_node_t *ses_node_parent(ses_node_t *);
110 extern int ses_walk(ses_snap_t *, ses_walk_f, void *);
111 
112 extern ses_snap_t *ses_snap_hold(ses_target_t *);
113 extern void ses_snap_rele(ses_snap_t *);
114 extern ses_snap_t *ses_snap_new(ses_target_t *);
115 extern uint32_t ses_snap_generation(ses_snap_t *);
116 
117 extern ses_node_type_t ses_node_type(ses_node_t *);
118 extern nvlist_t *ses_node_props(ses_node_t *);
119 extern int ses_node_ctl(ses_node_t *, const char *, nvlist_t *);
120 extern ses_snap_t *ses_node_snapshot(ses_node_t *);
121 extern ses_target_t *ses_node_target(ses_node_t *);
122 
123 extern ses_errno_t ses_errno(void);
124 extern const char *ses_errmsg(void);
125 extern const char *ses_strerror(ses_errno_t);
126 extern const char *ses_nv_error_member(void);
127 
128 extern ses_node_t *ses_snap_primary_enclosure(ses_snap_t *);
129 
130 #ifdef	__cplusplus
131 }
132 #endif
133 
134 #endif	/* _LIBSES_H */
135