1275c9da8Seschrock /*
2275c9da8Seschrock  * CDDL HEADER START
3275c9da8Seschrock  *
4275c9da8Seschrock  * The contents of this file are subject to the terms of the
5275c9da8Seschrock  * Common Development and Distribution License (the "License").
6275c9da8Seschrock  * You may not use this file except in compliance with the License.
7275c9da8Seschrock  *
8275c9da8Seschrock  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9275c9da8Seschrock  * or http://www.opensolaris.org/os/licensing.
10275c9da8Seschrock  * See the License for the specific language governing permissions
11275c9da8Seschrock  * and limitations under the License.
12275c9da8Seschrock  *
13275c9da8Seschrock  * When distributing Covered Code, include this CDDL HEADER in each
14275c9da8Seschrock  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15275c9da8Seschrock  * If applicable, add the following below this CDDL HEADER, with the
16275c9da8Seschrock  * fields enclosed by brackets "[]" replaced with your own identifying
17275c9da8Seschrock  * information: Portions Copyright [yyyy] [name of copyright owner]
18275c9da8Seschrock  *
19275c9da8Seschrock  * CDDL HEADER END
20275c9da8Seschrock  */
21275c9da8Seschrock 
22275c9da8Seschrock /*
23*ded93414SHyon Kim  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24275c9da8Seschrock  */
25275c9da8Seschrock 
26275c9da8Seschrock #ifndef	_LIBSES_H
27275c9da8Seschrock #define	_LIBSES_H
28275c9da8Seschrock 
29275c9da8Seschrock #ifdef	__cplusplus
30275c9da8Seschrock extern "C" {
31275c9da8Seschrock #endif
32275c9da8Seschrock 
33275c9da8Seschrock #include <sys/types.h>
34275c9da8Seschrock 
35275c9da8Seschrock #include <stdarg.h>
36275c9da8Seschrock #include <libnvpair.h>
37275c9da8Seschrock #include <pthread.h>
38275c9da8Seschrock 
39275c9da8Seschrock #include <scsi/libscsi.h>
40275c9da8Seschrock #include <scsi/plugins/ses/framework/ses2.h>
41275c9da8Seschrock #include <scsi/plugins/ses/framework/libses.h>
42275c9da8Seschrock 
43275c9da8Seschrock #define	LIBSES_VERSION	1
44275c9da8Seschrock 
45*ded93414SHyon Kim /*
46*ded93414SHyon Kim  * element type prop can be created by any plugin.  The ses2 plugin created
47*ded93414SHyon Kim  * SES-2 defined element types and SUN plugin defines vendor specific types.
48*ded93414SHyon Kim  */
49*ded93414SHyon Kim #define	SES_PROP_ELEMENT_TYPE	"ses-element-type"
50*ded93414SHyon Kim 
51275c9da8Seschrock typedef enum ses_node_type {
52275c9da8Seschrock 	SES_NODE_NONE = 0x0,
53275c9da8Seschrock 	SES_NODE_TARGET = 0x1,
54275c9da8Seschrock 	SES_NODE_ENCLOSURE = 0x2,
55275c9da8Seschrock 	SES_NODE_AGGREGATE = 0x4,
56275c9da8Seschrock 	SES_NODE_ELEMENT = 0x8
57275c9da8Seschrock } ses_node_type_t;
58275c9da8Seschrock 
59275c9da8Seschrock typedef enum ses_errno {
60275c9da8Seschrock 	ESES_NONE,		/* no error */
61275c9da8Seschrock 	ESES_NOMEM,		/* no memory */
62275c9da8Seschrock 	ESES_ZERO_LENGTH,	/* zero-length allocation requested */
63275c9da8Seschrock 	ESES_VERSION,		/* library version mismatch */
64275c9da8Seschrock 	ESES_NVL,		/* nvlist manipulation error */
65275c9da8Seschrock 	ESES_BAD_NODE,		/* bad node */
66275c9da8Seschrock 	ESES_INVALID_OP,	/* invalid operation */
67275c9da8Seschrock 	ESES_RANGE,		/* value out of range */
68275c9da8Seschrock 	ESES_INVALID_PROP,	/* nonexistent or immutable property */
69275c9da8Seschrock 	ESES_BAD_TYPE,		/* incorrect property type */
70275c9da8Seschrock 	ESES_BAD_PAGE,		/* bad page number */
71275c9da8Seschrock 	ESES_BAD_RESPONSE,	/* bad response from target */
72275c9da8Seschrock 	ESES_BUSY,		/* target busy */
73275c9da8Seschrock 	ESES_TOOMUCHCHANGE,	/* target configuration changing too rapidly */
74275c9da8Seschrock 	ESES_LIBSCSI,		/* SCSI error */
75275c9da8Seschrock 	ESES_NOTSUP,		/* operation not supported */
76275c9da8Seschrock 	ESES_UNKNOWN,		/* error of unknown type */
77275c9da8Seschrock 	ESES_CHANGED,		/* generation count has changed */
78275c9da8Seschrock 	ESES_PLUGIN,		/* invalid or missing plugin */
79275c9da8Seschrock 	ESES_MAX		/* maximum libses errno value */
80275c9da8Seschrock } ses_errno_t;
81275c9da8Seschrock 
82275c9da8Seschrock struct ses_target;
83275c9da8Seschrock typedef struct ses_target ses_target_t;
84275c9da8Seschrock 
85275c9da8Seschrock struct ses_snap;
86275c9da8Seschrock typedef struct ses_snap ses_snap_t;
87275c9da8Seschrock 
88275c9da8Seschrock struct ses_node;
89275c9da8Seschrock typedef struct ses_node ses_node_t;
90275c9da8Seschrock 
91275c9da8Seschrock extern ses_target_t *ses_open(uint_t, const char *);
92275c9da8Seschrock extern ses_target_t *ses_open_scsi(uint_t, libscsi_target_t *);
93275c9da8Seschrock extern void ses_close(ses_target_t *);
94275c9da8Seschrock 
95275c9da8Seschrock extern libscsi_target_t *ses_scsi_target(ses_target_t *);
96275c9da8Seschrock 
97275c9da8Seschrock typedef enum ses_walk_action {
98275c9da8Seschrock 	SES_WALK_ACTION_CONTINUE,
99275c9da8Seschrock 	SES_WALK_ACTION_PRUNE,
100275c9da8Seschrock 	SES_WALK_ACTION_TERMINATE
101275c9da8Seschrock } ses_walk_action_t;
102275c9da8Seschrock 
103275c9da8Seschrock typedef ses_walk_action_t (*ses_walk_f)(ses_node_t *, void *);
104275c9da8Seschrock 
105275c9da8Seschrock extern uint64_t ses_node_id(ses_node_t *);
106275c9da8Seschrock extern ses_node_t *ses_node_lookup(ses_snap_t *, uint64_t);
107275c9da8Seschrock 
108275c9da8Seschrock extern ses_node_t *ses_root_node(ses_snap_t *);
109275c9da8Seschrock extern ses_node_t *ses_node_sibling(ses_node_t *);
110275c9da8Seschrock extern ses_node_t *ses_node_prev_sibling(ses_node_t *);
111275c9da8Seschrock extern ses_node_t *ses_node_child(ses_node_t *);
112275c9da8Seschrock extern ses_node_t *ses_node_parent(ses_node_t *);
113275c9da8Seschrock extern int ses_walk(ses_snap_t *, ses_walk_f, void *);
114275c9da8Seschrock 
115275c9da8Seschrock extern ses_snap_t *ses_snap_hold(ses_target_t *);
116275c9da8Seschrock extern void ses_snap_rele(ses_snap_t *);
117275c9da8Seschrock extern ses_snap_t *ses_snap_new(ses_target_t *);
118275c9da8Seschrock extern uint32_t ses_snap_generation(ses_snap_t *);
119275c9da8Seschrock 
120275c9da8Seschrock extern ses_node_type_t ses_node_type(ses_node_t *);
121275c9da8Seschrock extern nvlist_t *ses_node_props(ses_node_t *);
122275c9da8Seschrock extern int ses_node_ctl(ses_node_t *, const char *, nvlist_t *);
123275c9da8Seschrock extern ses_snap_t *ses_node_snapshot(ses_node_t *);
124275c9da8Seschrock extern ses_target_t *ses_node_target(ses_node_t *);
125275c9da8Seschrock 
126275c9da8Seschrock extern ses_errno_t ses_errno(void);
127275c9da8Seschrock extern const char *ses_errmsg(void);
128275c9da8Seschrock extern const char *ses_strerror(ses_errno_t);
129275c9da8Seschrock extern const char *ses_nv_error_member(void);
130275c9da8Seschrock 
131c4800545Sjmcp extern ses_node_t *ses_snap_primary_enclosure(ses_snap_t *);
132c4800545Sjmcp 
133275c9da8Seschrock #ifdef	__cplusplus
134275c9da8Seschrock }
135275c9da8Seschrock #endif
136275c9da8Seschrock 
137275c9da8Seschrock #endif	/* _LIBSES_H */
138