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