xref: /illumos-gate/usr/src/lib/libpool/common/pool.h (revision 7a6d80f1660abd4755c68cbd094d4a914681d26e)
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 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  *  NOTE
28  *
29  *  The following contents of this file are private to the
30  *  implementation of the Solaris system and are subject to change at
31  *  any time without notice.  Applications using these interfaces may
32  *  fail to run on future releases.
33  */
34 
35 #ifndef	_POOL_H
36 #define	_POOL_H
37 
38 #include <sys/procset.h>
39 #include <sys/types.h>
40 #include <sys/pool.h>
41 
42 #ifdef	__cplusplus
43 extern "C" {
44 #endif
45 
46 /*
47  * Library versioning support (c.f. elf_version(3e)).
48  *
49  * You can enquire about the version number of the library
50  * by passing POOL_VER_NONE.  POOL_VER_CURRENT is the current
51  * (most capable) version.
52  *
53  * You can set the version used by the library by passing the
54  * required version number.  If this is not possible, the version
55  * returned will be POOL_VER_NONE.
56  */
57 #define	POOL_VER_CURRENT	1
58 #define	POOL_VER_NONE		0
59 
60 extern uint_t pool_version(uint_t ver);
61 
62 #ifndef PO_TRUE
63 #define	PO_TRUE	1
64 #endif
65 
66 #ifndef PO_FALSE
67 #define	PO_FALSE	0
68 #endif
69 
70 #ifndef PO_SUCCESS
71 #define	PO_SUCCESS	0
72 #endif
73 
74 #ifndef PO_FAIL
75 #define	PO_FAIL	-1
76 #endif
77 
78 /* Error codes */
79 #define	POE_OK			0
80 #define	POE_BAD_PROP_TYPE	1
81 #define	POE_INVALID_CONF	2
82 #define	POE_NOTSUP		3
83 #define	POE_INVALID_SEARCH    	4
84 #define	POE_BADPARAM    	5
85 #define	POE_PUTPROP    		6
86 #define	POE_DATASTORE		7
87 #define	POE_SYSTEM		8
88 #define	POE_ACCESS		9
89 
90 /* Open Flags */
91 #define	PO_RDONLY		0x0
92 #define	PO_RDWR			0x1
93 #define	PO_CREAT		0x2
94 #define	PO_DISCO		0x4
95 #define	PO_UPDATE		0x8
96 #define	PO_TEMP			0x10
97 
98 /* Allocation policy */
99 #define	POA_IMPORTANCE		"importance based"
100 #define	POA_SURPLUS_TO_DEFAULT	"surplus to default"
101 
102 /* Pools updates */
103 #define	POU_SYSTEM		0x1
104 #define	POU_POOL		0x2
105 #define	POU_PSET		0x4
106 #define	POU_CPU			0x8
107 
108 /* Data Export Formats */
109 typedef enum pool_export_format {
110 	POX_NATIVE,		/* Native data representation format */
111 	POX_TEXT		/* Text */
112 } pool_export_format_t;
113 
114 /* Property data types */
115 typedef enum pool_value_class {
116 	POC_INVAL = -1,
117 	POC_UINT,
118 	POC_INT,
119 	POC_DOUBLE,
120 	POC_BOOL,
121 	POC_STRING
122 } pool_value_class_t;
123 
124 /* Validation levels */
125 typedef enum pool_valid_level {
126 	POV_NONE = 0,		/* No validation */
127 	POV_LOOSE,		/* Loose validation */
128 	POV_STRICT,		/* Strict validation */
129 	POV_RUNTIME		/* Validate instantiation on current machine */
130 } pool_valid_level_t;
131 
132 /* conf states */
133 typedef enum pool_conf_state {
134 	POF_INVALID = -1,
135 	POF_VALID,
136 	POF_DESTROY
137 } pool_conf_state_t;
138 
139 /* Element data values */
140 typedef struct pool_value pool_value_t;
141 
142 /* Elements */
143 typedef struct pool_elem pool_elem_t;
144 typedef struct pool pool_t;
145 typedef struct pool_resource pool_resource_t;
146 typedef struct pool_component pool_component_t;
147 
148 /*
149  * Resource management configuration
150  */
151 typedef struct pool_conf pool_conf_t;
152 
153 extern int		pool_error(void);
154 extern const char	*pool_strerror(int);
155 extern int		pool_resource_type_list(const char **, uint_t *);
156 extern int		pool_get_status(int *);
157 extern int		pool_set_status(int);
158 
159 /* Configuration manipulation */
160 extern pool_conf_t *pool_conf_alloc(void);
161 extern void pool_conf_free(pool_conf_t *);
162 extern pool_conf_state_t pool_conf_status(const pool_conf_t *);
163 
164 extern int pool_conf_close(pool_conf_t *);
165 extern int pool_conf_remove(pool_conf_t *);
166 extern int pool_conf_open(pool_conf_t *, const char *, int);
167 extern int pool_conf_rollback(pool_conf_t *);
168 extern int pool_conf_commit(pool_conf_t *, int);
169 extern int pool_conf_export(const pool_conf_t *, const char *,
170     pool_export_format_t);
171 extern int pool_conf_validate(const pool_conf_t *, pool_valid_level_t);
172 extern int pool_conf_update(const pool_conf_t *, int *);
173 extern pool_t *pool_get_pool(const pool_conf_t *, const char *);
174 extern pool_t **pool_query_pools(const pool_conf_t *, uint_t *,
175     pool_value_t **);
176 extern pool_resource_t *pool_get_resource(const pool_conf_t *, const char *,
177     const char *);
178 extern pool_resource_t **pool_query_resources(const pool_conf_t *, uint_t *,
179     pool_value_t **);
180 extern pool_component_t **pool_query_components(const pool_conf_t *, uint_t *,
181     pool_value_t **);
182 extern const char *pool_conf_location(const pool_conf_t *);
183 extern char *pool_conf_info(const pool_conf_t *, int);
184 
185 /* Resource manipulation */
186 extern pool_resource_t *pool_resource_create(pool_conf_t *, const char *,
187     const char *);
188 extern int pool_resource_destroy(pool_conf_t *, pool_resource_t *);
189 extern int pool_resource_transfer(pool_conf_t *, pool_resource_t *,
190     pool_resource_t *, uint64_t);
191 extern int pool_resource_xtransfer(pool_conf_t *, pool_resource_t *,
192     pool_resource_t *, pool_component_t **);
193 extern pool_component_t **pool_query_resource_components(const pool_conf_t *,
194     const pool_resource_t *, uint_t *, pool_value_t **);
195 extern char *pool_resource_info(const pool_conf_t *, const pool_resource_t *,
196     int);
197 
198 /* Pool manipulation */
199 extern pool_t *pool_create(pool_conf_t *, const char *);
200 extern int pool_destroy(pool_conf_t *, pool_t *);
201 extern int pool_associate(pool_conf_t *, pool_t *, const pool_resource_t *);
202 extern int pool_dissociate(pool_conf_t *, pool_t *, const pool_resource_t *);
203 extern char *pool_info(const pool_conf_t *, const pool_t *, int);
204 extern pool_resource_t **pool_query_pool_resources(const pool_conf_t *,
205     const pool_t *, uint_t *, pool_value_t **);
206 
207 /* Resource Component Manipulation */
208 extern pool_resource_t *pool_get_owning_resource(const pool_conf_t *,
209     const pool_component_t *);
210 extern char *pool_component_info(const pool_conf_t *, const pool_component_t *,
211     int);
212 
213 /* Property manipulation */
214 extern pool_value_class_t pool_get_property(const pool_conf_t *,
215     const pool_elem_t *, const char *, pool_value_t *);
216 extern int pool_put_property(pool_conf_t *, pool_elem_t *, const char *,
217     const pool_value_t *);
218 extern int pool_rm_property(pool_conf_t *, pool_elem_t *, const char *);
219 
220 /*
221  * Walk the associated properties of the supplied element calling the supplied
222  * function for each property in turn. There is no implied order in the walk.
223  * The arg parameter allows caller-specific data to be passed to the call.
224  */
225 extern int pool_walk_properties(pool_conf_t *, pool_elem_t *, void *,
226     int (*)(pool_conf_t *, pool_elem_t *, const char *, pool_value_t *,
227 	    void *));
228 
229 /* Get the underlying element */
230 extern pool_elem_t *pool_conf_to_elem(const pool_conf_t *);
231 extern pool_elem_t *pool_to_elem(const pool_conf_t *, const pool_t *);
232 extern pool_elem_t *pool_resource_to_elem(const pool_conf_t *,
233     const pool_resource_t *);
234 extern pool_elem_t *pool_component_to_elem(const pool_conf_t *,
235     const pool_component_t *);
236 
237 /* Pool Property Value Manipulation */
238 /* Get/Set Pool Property Values and Type */
239 extern int pool_value_get_uint64(const pool_value_t *, uint64_t *);
240 extern int pool_value_get_int64(const pool_value_t *, int64_t *);
241 extern int pool_value_get_double(const pool_value_t *, double *);
242 extern int pool_value_get_bool(const pool_value_t *, uchar_t *);
243 extern int pool_value_get_string(const pool_value_t *, const char **);
244 extern pool_value_class_t pool_value_get_type(const pool_value_t *);
245 extern void pool_value_set_uint64(pool_value_t *, uint64_t);
246 extern void pool_value_set_int64(pool_value_t *, int64_t);
247 extern void pool_value_set_double(pool_value_t *, double);
248 extern void pool_value_set_bool(pool_value_t *, uchar_t);
249 extern int pool_value_set_string(pool_value_t *, const char *);
250 extern const char *pool_value_get_name(const pool_value_t *);
251 extern int pool_value_set_name(pool_value_t *, const char *);
252 
253 /* Pool Property Value Creation/Destruction */
254 extern pool_value_t *pool_value_alloc(void);
255 extern void pool_value_free(pool_value_t *);
256 
257 /* Default pool data store locations */
258 extern const char *pool_static_location(void);
259 extern const char *pool_dynamic_location(void);
260 
261 /* Binding */
262 extern int pool_set_binding(const char *, idtype_t, id_t);
263 extern char *pool_get_binding(pid_t);
264 extern char *pool_get_resource_binding(const char *, pid_t);
265 
266 /* Walking */
267 extern int pool_walk_pools(pool_conf_t *, void *,
268     int (*)(pool_conf_t *, pool_t *, void *));
269 extern int pool_walk_resources(pool_conf_t *, pool_t *, void *,
270     int (*)(pool_conf_t *, pool_resource_t *, void *));
271 extern int pool_walk_components(pool_conf_t *, pool_resource_t *, void *,
272     int (*)(pool_conf_t *, pool_component_t *, void *));
273 
274 #ifdef	__cplusplus
275 }
276 #endif
277 
278 #endif	/* _POOL_H */
279