xref: /onnv-gate/usr/src/lib/libpool/common/pool_impl.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #ifndef	_POOL_IMPL_H
28*0Sstevel@tonic-gate #define	_POOL_IMPL_H
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate #ifdef	__cplusplus
33*0Sstevel@tonic-gate extern "C" {
34*0Sstevel@tonic-gate #endif
35*0Sstevel@tonic-gate 
36*0Sstevel@tonic-gate /*
37*0Sstevel@tonic-gate  * This file contains the definitions of types and supporting
38*0Sstevel@tonic-gate  * functions to implement the libpool generic data manipulation
39*0Sstevel@tonic-gate  * facility.
40*0Sstevel@tonic-gate  *
41*0Sstevel@tonic-gate  * libpool is designed so that the data representation/storage method
42*0Sstevel@tonic-gate  * used may be easily replaced without affecting core functionality.
43*0Sstevel@tonic-gate  * A libpool configuration is connected to a particular data
44*0Sstevel@tonic-gate  * representation/storage "driver" via the pool_connection_t
45*0Sstevel@tonic-gate  * type. When a configuration is opened (see pool_conf_open) the
46*0Sstevel@tonic-gate  * libpool implementation allocates a specific data manipulation type
47*0Sstevel@tonic-gate  * and initialises it. For instance, see pool_xml_connection_alloc.
48*0Sstevel@tonic-gate  *
49*0Sstevel@tonic-gate  * This function represents a cross-over point and all routines used
50*0Sstevel@tonic-gate  * for data representation/storage are controlled by the type of
51*0Sstevel@tonic-gate  * allocated connection.
52*0Sstevel@tonic-gate  *
53*0Sstevel@tonic-gate  * Currently, there are two implemented methods of access. Data may be
54*0Sstevel@tonic-gate  * retrieved from the kernel, using the pool_knl_connection_t
55*0Sstevel@tonic-gate  * function. This implementation relies on a private interface
56*0Sstevel@tonic-gate  * provided by a driver, /dev/pool, and presents data retrieved from
57*0Sstevel@tonic-gate  * the kernel via the standard libpool interface. Alternatively, data
58*0Sstevel@tonic-gate  * may be retrieved from an XML file, via pool_xml_connection_t, and
59*0Sstevel@tonic-gate  * presented through the standard libpool interface. For details of
60*0Sstevel@tonic-gate  * these two implementations, see pool_kernel_impl.h and
61*0Sstevel@tonic-gate  * pool_xml_impl.h.
62*0Sstevel@tonic-gate  *
63*0Sstevel@tonic-gate  * In addition to defining a specific connection type for a desired
64*0Sstevel@tonic-gate  * data representation/storage medium, several other structures must
65*0Sstevel@tonic-gate  * be defined to allow manipulation of configuration elements.
66*0Sstevel@tonic-gate  *
67*0Sstevel@tonic-gate  * Configuration elements are represented as pool_elem_t instances, or
68*0Sstevel@tonic-gate  * as sub-types of this generic type (such as pool_t, which represents
69*0Sstevel@tonic-gate  * a pool element) with groups (or sets) of these instances available
70*0Sstevel@tonic-gate  * for manipulation via the pool_result_set_t type.
71*0Sstevel@tonic-gate  *
72*0Sstevel@tonic-gate  * For more information on the implementation of these types, read the
73*0Sstevel@tonic-gate  * detailed comments above each structure definition.
74*0Sstevel@tonic-gate  */
75*0Sstevel@tonic-gate 
76*0Sstevel@tonic-gate /*
77*0Sstevel@tonic-gate  * The pool_elem_t is used to represent a configuration element.The
78*0Sstevel@tonic-gate  * class of the element is stored within the structure along with a
79*0Sstevel@tonic-gate  * pointer to the containing configuration and a pointer to the
80*0Sstevel@tonic-gate  * element's specific subtype.
81*0Sstevel@tonic-gate  *
82*0Sstevel@tonic-gate  * The function pointers are initialised when the element is allocated
83*0Sstevel@tonic-gate  * to use the specific functions provided by the concrete data
84*0Sstevel@tonic-gate  * representation.
85*0Sstevel@tonic-gate  *
86*0Sstevel@tonic-gate  * The full set of operations that can be performed on an element
87*0Sstevel@tonic-gate  * which require special treatment from the data
88*0Sstevel@tonic-gate  * representation/storage medium are defined.
89*0Sstevel@tonic-gate  */
90*0Sstevel@tonic-gate struct pool_elem {
91*0Sstevel@tonic-gate 	pool_conf_t *pe_conf;				/* Configuration */
92*0Sstevel@tonic-gate 	pool_elem_class_t pe_class;			/* Element class */
93*0Sstevel@tonic-gate 	pool_resource_elem_class_t pe_resource_class;	/* Resource class */
94*0Sstevel@tonic-gate 	pool_component_elem_class_t pe_component_class;	/* Component class */
95*0Sstevel@tonic-gate 	struct pool_elem *pe_pair;			/* Static pair */
96*0Sstevel@tonic-gate 	pool_value_class_t (*pe_get_prop)(const pool_elem_t *, const char *,
97*0Sstevel@tonic-gate 	    pool_value_t *);
98*0Sstevel@tonic-gate 	int (*pe_put_prop)(pool_elem_t *, const char *, const pool_value_t *);
99*0Sstevel@tonic-gate 	int (*pe_rm_prop)(pool_elem_t *, const char *);
100*0Sstevel@tonic-gate 	pool_value_t **(*pe_get_props)(const pool_elem_t *, uint_t *);
101*0Sstevel@tonic-gate 	int (*pe_remove)(pool_elem_t *);
102*0Sstevel@tonic-gate 	pool_elem_t *(*pe_get_container)(const pool_elem_t *);
103*0Sstevel@tonic-gate 	int (*pe_set_container)(pool_elem_t *, pool_elem_t *);
104*0Sstevel@tonic-gate };
105*0Sstevel@tonic-gate 
106*0Sstevel@tonic-gate /*
107*0Sstevel@tonic-gate  * libpool performs many operations against a pool_elem_t. This basic
108*0Sstevel@tonic-gate  * type is extended to provide specific functionality and type safety
109*0Sstevel@tonic-gate  * for each of the different types of element supported by
110*0Sstevel@tonic-gate  * libpool. There are four types of element:
111*0Sstevel@tonic-gate  * - pool_system_t, represents an entire configuration
112*0Sstevel@tonic-gate  * - pool_t, represents a single pool
113*0Sstevel@tonic-gate  * - pool_resource_t, represents a single resource
114*0Sstevel@tonic-gate  * - pool_component_t, represents a single resource component
115*0Sstevel@tonic-gate  *
116*0Sstevel@tonic-gate  * pool_system_t is an internal structure, the other structures are
117*0Sstevel@tonic-gate  * externally visible and form a major part of the libpool interface.
118*0Sstevel@tonic-gate  */
119*0Sstevel@tonic-gate typedef struct pool_system
120*0Sstevel@tonic-gate {
121*0Sstevel@tonic-gate 	pool_elem_t ps_elem;
122*0Sstevel@tonic-gate 	void *pe_pad1;
123*0Sstevel@tonic-gate 	void *pe_pad2;
124*0Sstevel@tonic-gate } pool_system_t;
125*0Sstevel@tonic-gate 
126*0Sstevel@tonic-gate struct pool
127*0Sstevel@tonic-gate {
128*0Sstevel@tonic-gate 	pool_elem_t pp_elem;
129*0Sstevel@tonic-gate 	/*
130*0Sstevel@tonic-gate 	 * Specific to pool_t
131*0Sstevel@tonic-gate 	 */
132*0Sstevel@tonic-gate 	int (*pp_associate)(pool_t *, const pool_resource_t *);
133*0Sstevel@tonic-gate 	int (*pp_dissociate)(pool_t *, const pool_resource_t *);
134*0Sstevel@tonic-gate };
135*0Sstevel@tonic-gate 
136*0Sstevel@tonic-gate struct pool_resource
137*0Sstevel@tonic-gate {
138*0Sstevel@tonic-gate 	pool_elem_t pr_elem;
139*0Sstevel@tonic-gate 	/*
140*0Sstevel@tonic-gate 	 * Specific to pool_resource_t
141*0Sstevel@tonic-gate 	 */
142*0Sstevel@tonic-gate 	int (*pr_is_system)(const pool_resource_t *);
143*0Sstevel@tonic-gate 	int (*pr_can_associate)(const pool_resource_t *);
144*0Sstevel@tonic-gate };
145*0Sstevel@tonic-gate 
146*0Sstevel@tonic-gate struct pool_component
147*0Sstevel@tonic-gate {
148*0Sstevel@tonic-gate 	pool_elem_t pc_elem;
149*0Sstevel@tonic-gate 	void *pe_pad1;
150*0Sstevel@tonic-gate 	void *pe_pad2;
151*0Sstevel@tonic-gate };
152*0Sstevel@tonic-gate 
153*0Sstevel@tonic-gate /*
154*0Sstevel@tonic-gate  * The pool_result_set_t is used to represent a collection (set) of
155*0Sstevel@tonic-gate  * configuration elements. The configuration to which this result set
156*0Sstevel@tonic-gate  * applies is stored along with an indicator as to whether the result
157*0Sstevel@tonic-gate  * set is still in use.
158*0Sstevel@tonic-gate  *
159*0Sstevel@tonic-gate  * The function pointers are initialised when the element is allocated
160*0Sstevel@tonic-gate  * to use the specific functions provided by the concrete data
161*0Sstevel@tonic-gate  * representation.
162*0Sstevel@tonic-gate  *
163*0Sstevel@tonic-gate  * The full set of operations that can be performed on an element
164*0Sstevel@tonic-gate  * which require special treatment from the data
165*0Sstevel@tonic-gate  * representation/storage medium are defined.
166*0Sstevel@tonic-gate  */
167*0Sstevel@tonic-gate typedef struct pool_result_set {
168*0Sstevel@tonic-gate 	pool_conf_t *prs_conf;				/* Configuration */
169*0Sstevel@tonic-gate 	int prs_active;					/* Query active? */
170*0Sstevel@tonic-gate 	int prs_index;					/* Result Index */
171*0Sstevel@tonic-gate 	pool_elem_t *(*prs_next)(struct pool_result_set *);
172*0Sstevel@tonic-gate 	pool_elem_t *(*prs_prev)(struct pool_result_set *);
173*0Sstevel@tonic-gate 	pool_elem_t *(*prs_first)(struct pool_result_set *);
174*0Sstevel@tonic-gate 	pool_elem_t *(*prs_last)(struct pool_result_set *);
175*0Sstevel@tonic-gate 	int (*prs_set_index)(struct pool_result_set *, int);
176*0Sstevel@tonic-gate 	int (*prs_get_index)(struct pool_result_set *);
177*0Sstevel@tonic-gate 	int (*prs_close)(struct pool_result_set *);
178*0Sstevel@tonic-gate 	int (*prs_count)(struct pool_result_set *);
179*0Sstevel@tonic-gate } pool_result_set_t;
180*0Sstevel@tonic-gate 
181*0Sstevel@tonic-gate /*
182*0Sstevel@tonic-gate  * The pool_connection_t is used to represent a connection between a
183*0Sstevel@tonic-gate  * libpool configuration and a particular implementation of the
184*0Sstevel@tonic-gate  * libpool interface in a specific data representation/storage medium,
185*0Sstevel@tonic-gate  * e.g. XML.
186*0Sstevel@tonic-gate  *
187*0Sstevel@tonic-gate  * The name of the storage medium is stored along with the type of the
188*0Sstevel@tonic-gate  * data store.
189*0Sstevel@tonic-gate  *
190*0Sstevel@tonic-gate  * The function pointers are initialised when the element is allocated
191*0Sstevel@tonic-gate  * to use the specific functions provided by the concrete data
192*0Sstevel@tonic-gate  * representation.
193*0Sstevel@tonic-gate  *
194*0Sstevel@tonic-gate  * The full set of operations that can be performed on an element
195*0Sstevel@tonic-gate  * which require special treatment from the data
196*0Sstevel@tonic-gate  * representation/storage medium are defined.
197*0Sstevel@tonic-gate  */
198*0Sstevel@tonic-gate typedef struct pool_connection {
199*0Sstevel@tonic-gate 	const char *pc_name;				/* Provider name */
200*0Sstevel@tonic-gate 	int pc_store_type;				/* Datastore type */
201*0Sstevel@tonic-gate 	int pc_oflags;					/* Open flags */
202*0Sstevel@tonic-gate 	int (*pc_close)(pool_conf_t *);
203*0Sstevel@tonic-gate 	int (*pc_validate)(const pool_conf_t *, pool_valid_level_t);
204*0Sstevel@tonic-gate 	int (*pc_commit)(pool_conf_t *);
205*0Sstevel@tonic-gate 	int (*pc_export)(const pool_conf_t *, const char *,
206*0Sstevel@tonic-gate 	    pool_export_format_t);
207*0Sstevel@tonic-gate 	int (*pc_rollback)(pool_conf_t *);
208*0Sstevel@tonic-gate 	pool_result_set_t *(*pc_exec_query)(const pool_conf_t *,
209*0Sstevel@tonic-gate 	    const pool_elem_t *, const char *, pool_elem_class_t,
210*0Sstevel@tonic-gate 	    pool_value_t **);
211*0Sstevel@tonic-gate 	pool_elem_t *(*pc_elem_create)(pool_conf_t *, pool_elem_class_t,
212*0Sstevel@tonic-gate 	    pool_resource_elem_class_t, pool_component_elem_class_t);
213*0Sstevel@tonic-gate 	int (*pc_remove)(pool_conf_t *);
214*0Sstevel@tonic-gate 	int (*pc_res_xfer)(pool_resource_t *, pool_resource_t *, uint64_t);
215*0Sstevel@tonic-gate 	int (*pc_res_xxfer)(pool_resource_t *, pool_resource_t *,
216*0Sstevel@tonic-gate 	    pool_component_t **);
217*0Sstevel@tonic-gate 	char *(*pc_get_binding)(pool_conf_t *, pid_t);
218*0Sstevel@tonic-gate 	int (*pc_set_binding)(pool_conf_t *, const char *, idtype_t, id_t);
219*0Sstevel@tonic-gate 	char *(*pc_get_resource_binding)(pool_conf_t *,
220*0Sstevel@tonic-gate 	    pool_resource_elem_class_t, pid_t);
221*0Sstevel@tonic-gate } pool_connection_t;
222*0Sstevel@tonic-gate 
223*0Sstevel@tonic-gate /*
224*0Sstevel@tonic-gate  * pool_conf represents a resource management configuration. The
225*0Sstevel@tonic-gate  * configuration location is stored in the pc_location member with the
226*0Sstevel@tonic-gate  * state of the configuration stored in pc_state.
227*0Sstevel@tonic-gate  *
228*0Sstevel@tonic-gate  * The pc_prov member provides data representation/storage abstraction
229*0Sstevel@tonic-gate  * for the configuration since all access to data is performed through
230*0Sstevel@tonic-gate  * this member.
231*0Sstevel@tonic-gate  */
232*0Sstevel@tonic-gate struct pool_conf {
233*0Sstevel@tonic-gate 	const char *pc_location;			/* Location */
234*0Sstevel@tonic-gate 	pool_connection_t *pc_prov;			/* Data Provider */
235*0Sstevel@tonic-gate 	pool_conf_state_t pc_state;			/* State */
236*0Sstevel@tonic-gate };
237*0Sstevel@tonic-gate 
238*0Sstevel@tonic-gate /*
239*0Sstevel@tonic-gate  * Convert a pool_elem_t to it's appropriate sub-type.
240*0Sstevel@tonic-gate  */
241*0Sstevel@tonic-gate extern pool_system_t	*pool_conf_system(const pool_conf_t *);
242*0Sstevel@tonic-gate extern pool_system_t	*pool_elem_system(const pool_elem_t *);
243*0Sstevel@tonic-gate extern pool_t		*pool_elem_pool(const pool_elem_t *);
244*0Sstevel@tonic-gate extern pool_resource_t	*pool_elem_res(const pool_elem_t *);
245*0Sstevel@tonic-gate extern pool_component_t	*pool_elem_comp(const pool_elem_t *);
246*0Sstevel@tonic-gate 
247*0Sstevel@tonic-gate /*
248*0Sstevel@tonic-gate  * Convert a pool_system_t to a pool_elem_t.
249*0Sstevel@tonic-gate  */
250*0Sstevel@tonic-gate extern pool_elem_t	*pool_system_elem(const pool_system_t *);
251*0Sstevel@tonic-gate 
252*0Sstevel@tonic-gate /*
253*0Sstevel@tonic-gate  * Get/Set an element's "pair" element. A pair element is a temporary
254*0Sstevel@tonic-gate  * association at commit between an element in the dynamic
255*0Sstevel@tonic-gate  * configuration and an element in the static configuration. This
256*0Sstevel@tonic-gate  * relationship is stored in the pe_pair member of the element.
257*0Sstevel@tonic-gate  */
258*0Sstevel@tonic-gate extern pool_elem_t	*pool_get_pair(const pool_elem_t *);
259*0Sstevel@tonic-gate extern void		pool_set_pair(pool_elem_t *, pool_elem_t *);
260*0Sstevel@tonic-gate 
261*0Sstevel@tonic-gate /*
262*0Sstevel@tonic-gate  * Result Set Manipulation
263*0Sstevel@tonic-gate  */
264*0Sstevel@tonic-gate extern pool_elem_t	*pool_rs_next(pool_result_set_t *);
265*0Sstevel@tonic-gate extern pool_elem_t	*pool_rs_prev(pool_result_set_t *);
266*0Sstevel@tonic-gate extern pool_elem_t	*pool_rs_first(pool_result_set_t *);
267*0Sstevel@tonic-gate extern pool_elem_t	*pool_rs_last(pool_result_set_t *);
268*0Sstevel@tonic-gate extern int		pool_rs_count(pool_result_set_t *);
269*0Sstevel@tonic-gate extern int		pool_rs_get_index(pool_result_set_t *);
270*0Sstevel@tonic-gate extern int		pool_rs_set_index(pool_result_set_t *, int);
271*0Sstevel@tonic-gate extern int		pool_rs_close(pool_result_set_t *);
272*0Sstevel@tonic-gate 
273*0Sstevel@tonic-gate /*
274*0Sstevel@tonic-gate  * General Purpose Query
275*0Sstevel@tonic-gate  */
276*0Sstevel@tonic-gate extern pool_result_set_t *pool_exec_query(const pool_conf_t *,
277*0Sstevel@tonic-gate     const pool_elem_t *, const char *, pool_elem_class_t, pool_value_t **);
278*0Sstevel@tonic-gate 
279*0Sstevel@tonic-gate #ifdef	__cplusplus
280*0Sstevel@tonic-gate }
281*0Sstevel@tonic-gate #endif
282*0Sstevel@tonic-gate 
283*0Sstevel@tonic-gate #endif	/* _POOL_IMPL_H */
284