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