xref: /illumos-gate/usr/src/lib/libpool/common/pool.h (revision 1da57d55)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0209230bSgjelinek  * Common Development and Distribution License (the "License").
6*0209230bSgjelinek  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*0209230bSgjelinek  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate  *  NOTE
287c478bd9Sstevel@tonic-gate  *
297c478bd9Sstevel@tonic-gate  *  The following contents of this file are private to the
307c478bd9Sstevel@tonic-gate  *  implementation of the Solaris system and are subject to change at
317c478bd9Sstevel@tonic-gate  *  any time without notice.  Applications using these interfaces may
327c478bd9Sstevel@tonic-gate  *  fail to run on future releases.
337c478bd9Sstevel@tonic-gate  */
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #ifndef	_POOL_H
367c478bd9Sstevel@tonic-gate #define	_POOL_H
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #include <sys/procset.h>
397c478bd9Sstevel@tonic-gate #include <sys/types.h>
407c478bd9Sstevel@tonic-gate #include <sys/pool.h>
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
437c478bd9Sstevel@tonic-gate extern "C" {
447c478bd9Sstevel@tonic-gate #endif
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate /*
477c478bd9Sstevel@tonic-gate  * Library versioning support (c.f. elf_version(3e)).
487c478bd9Sstevel@tonic-gate  *
497c478bd9Sstevel@tonic-gate  * You can enquire about the version number of the library
507c478bd9Sstevel@tonic-gate  * by passing POOL_VER_NONE.  POOL_VER_CURRENT is the current
517c478bd9Sstevel@tonic-gate  * (most capable) version.
527c478bd9Sstevel@tonic-gate  *
537c478bd9Sstevel@tonic-gate  * You can set the version used by the library by passing the
547c478bd9Sstevel@tonic-gate  * required version number.  If this is not possible, the version
557c478bd9Sstevel@tonic-gate  * returned will be POOL_VER_NONE.
567c478bd9Sstevel@tonic-gate  */
577c478bd9Sstevel@tonic-gate #define	POOL_VER_CURRENT	1
587c478bd9Sstevel@tonic-gate #define	POOL_VER_NONE		0
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate extern uint_t pool_version(uint_t ver);
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate #ifndef PO_TRUE
637c478bd9Sstevel@tonic-gate #define	PO_TRUE	1
647c478bd9Sstevel@tonic-gate #endif
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate #ifndef PO_FALSE
677c478bd9Sstevel@tonic-gate #define	PO_FALSE	0
687c478bd9Sstevel@tonic-gate #endif
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate #ifndef PO_SUCCESS
717c478bd9Sstevel@tonic-gate #define	PO_SUCCESS	0
727c478bd9Sstevel@tonic-gate #endif
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate #ifndef PO_FAIL
757c478bd9Sstevel@tonic-gate #define	PO_FAIL	-1
767c478bd9Sstevel@tonic-gate #endif
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate /* Error codes */
797c478bd9Sstevel@tonic-gate #define	POE_OK			0
807c478bd9Sstevel@tonic-gate #define	POE_BAD_PROP_TYPE	1
817c478bd9Sstevel@tonic-gate #define	POE_INVALID_CONF	2
827c478bd9Sstevel@tonic-gate #define	POE_NOTSUP		3
837c478bd9Sstevel@tonic-gate #define	POE_INVALID_SEARCH    	4
847c478bd9Sstevel@tonic-gate #define	POE_BADPARAM    	5
857c478bd9Sstevel@tonic-gate #define	POE_PUTPROP    		6
867c478bd9Sstevel@tonic-gate #define	POE_DATASTORE		7
877c478bd9Sstevel@tonic-gate #define	POE_SYSTEM		8
887c478bd9Sstevel@tonic-gate #define	POE_ACCESS		9
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate /* Open Flags */
917c478bd9Sstevel@tonic-gate #define	PO_RDONLY		0x0
927c478bd9Sstevel@tonic-gate #define	PO_RDWR			0x1
937c478bd9Sstevel@tonic-gate #define	PO_CREAT		0x2
947c478bd9Sstevel@tonic-gate #define	PO_DISCO		0x4
957c478bd9Sstevel@tonic-gate #define	PO_UPDATE		0x8
96*0209230bSgjelinek #define	PO_TEMP			0x10
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate /* Allocation policy */
997c478bd9Sstevel@tonic-gate #define	POA_IMPORTANCE		"importance based"
1007c478bd9Sstevel@tonic-gate #define	POA_SURPLUS_TO_DEFAULT	"surplus to default"
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate /* Pools updates */
1037c478bd9Sstevel@tonic-gate #define	POU_SYSTEM		0x1
1047c478bd9Sstevel@tonic-gate #define	POU_POOL		0x2
1057c478bd9Sstevel@tonic-gate #define	POU_PSET		0x4
1067c478bd9Sstevel@tonic-gate #define	POU_CPU			0x8
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate /* Data Export Formats */
1097c478bd9Sstevel@tonic-gate typedef enum pool_export_format {
1107c478bd9Sstevel@tonic-gate 	POX_NATIVE,		/* Native data representation format */
1117c478bd9Sstevel@tonic-gate 	POX_TEXT		/* Text */
1127c478bd9Sstevel@tonic-gate } pool_export_format_t;
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate /* Property data types */
1157c478bd9Sstevel@tonic-gate typedef enum pool_value_class {
1167c478bd9Sstevel@tonic-gate 	POC_INVAL = -1,
1177c478bd9Sstevel@tonic-gate 	POC_UINT,
1187c478bd9Sstevel@tonic-gate 	POC_INT,
1197c478bd9Sstevel@tonic-gate 	POC_DOUBLE,
1207c478bd9Sstevel@tonic-gate 	POC_BOOL,
1217c478bd9Sstevel@tonic-gate 	POC_STRING
1227c478bd9Sstevel@tonic-gate } pool_value_class_t;
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate /* Validation levels */
1257c478bd9Sstevel@tonic-gate typedef enum pool_valid_level {
1267c478bd9Sstevel@tonic-gate 	POV_NONE = 0,		/* No validation */
1277c478bd9Sstevel@tonic-gate 	POV_LOOSE,		/* Loose validation */
1287c478bd9Sstevel@tonic-gate 	POV_STRICT,		/* Strict validation */
1297c478bd9Sstevel@tonic-gate 	POV_RUNTIME		/* Validate instantiation on current machine */
1307c478bd9Sstevel@tonic-gate } pool_valid_level_t;
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate /* conf states */
1337c478bd9Sstevel@tonic-gate typedef enum pool_conf_state {
1347c478bd9Sstevel@tonic-gate 	POF_INVALID = -1,
1357c478bd9Sstevel@tonic-gate 	POF_VALID,
1367c478bd9Sstevel@tonic-gate 	POF_DESTROY
1377c478bd9Sstevel@tonic-gate } pool_conf_state_t;
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate /* Element data values */
1407c478bd9Sstevel@tonic-gate typedef struct pool_value pool_value_t;
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate /* Elements */
1437c478bd9Sstevel@tonic-gate typedef struct pool_elem pool_elem_t;
1447c478bd9Sstevel@tonic-gate typedef struct pool pool_t;
1457c478bd9Sstevel@tonic-gate typedef struct pool_resource pool_resource_t;
1467c478bd9Sstevel@tonic-gate typedef struct pool_component pool_component_t;
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate /*
1497c478bd9Sstevel@tonic-gate  * Resource management configuration
1507c478bd9Sstevel@tonic-gate  */
1517c478bd9Sstevel@tonic-gate typedef struct pool_conf pool_conf_t;
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate extern int		pool_error(void);
1547c478bd9Sstevel@tonic-gate extern const char	*pool_strerror(int);
1557c478bd9Sstevel@tonic-gate extern int		pool_resource_type_list(const char **, uint_t *);
1567c478bd9Sstevel@tonic-gate extern int		pool_get_status(int *);
1577c478bd9Sstevel@tonic-gate extern int		pool_set_status(int);
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate /* Configuration manipulation */
1607c478bd9Sstevel@tonic-gate extern pool_conf_t *pool_conf_alloc(void);
1617c478bd9Sstevel@tonic-gate extern void pool_conf_free(pool_conf_t *);
1627c478bd9Sstevel@tonic-gate extern pool_conf_state_t pool_conf_status(const pool_conf_t *);
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate extern int pool_conf_close(pool_conf_t *);
1657c478bd9Sstevel@tonic-gate extern int pool_conf_remove(pool_conf_t *);
1667c478bd9Sstevel@tonic-gate extern int pool_conf_open(pool_conf_t *, const char *, int);
1677c478bd9Sstevel@tonic-gate extern int pool_conf_rollback(pool_conf_t *);
1687c478bd9Sstevel@tonic-gate extern int pool_conf_commit(pool_conf_t *, int);
1697c478bd9Sstevel@tonic-gate extern int pool_conf_export(const pool_conf_t *, const char *,
1707c478bd9Sstevel@tonic-gate     pool_export_format_t);
1717c478bd9Sstevel@tonic-gate extern int pool_conf_validate(const pool_conf_t *, pool_valid_level_t);
1727c478bd9Sstevel@tonic-gate extern int pool_conf_update(const pool_conf_t *, int *);
1737c478bd9Sstevel@tonic-gate extern pool_t *pool_get_pool(const pool_conf_t *, const char *);
1747c478bd9Sstevel@tonic-gate extern pool_t **pool_query_pools(const pool_conf_t *, uint_t *,
1757c478bd9Sstevel@tonic-gate     pool_value_t **);
1767c478bd9Sstevel@tonic-gate extern pool_resource_t *pool_get_resource(const pool_conf_t *, const char *,
1777c478bd9Sstevel@tonic-gate     const char *);
1787c478bd9Sstevel@tonic-gate extern pool_resource_t **pool_query_resources(const pool_conf_t *, uint_t *,
1797c478bd9Sstevel@tonic-gate     pool_value_t **);
1807c478bd9Sstevel@tonic-gate extern pool_component_t **pool_query_components(const pool_conf_t *, uint_t *,
1817c478bd9Sstevel@tonic-gate     pool_value_t **);
1827c478bd9Sstevel@tonic-gate extern const char *pool_conf_location(const pool_conf_t *);
1837c478bd9Sstevel@tonic-gate extern char *pool_conf_info(const pool_conf_t *, int);
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate /* Resource manipulation */
1867c478bd9Sstevel@tonic-gate extern pool_resource_t *pool_resource_create(pool_conf_t *, const char *,
1877c478bd9Sstevel@tonic-gate     const char *);
1887c478bd9Sstevel@tonic-gate extern int pool_resource_destroy(pool_conf_t *, pool_resource_t *);
1897c478bd9Sstevel@tonic-gate extern int pool_resource_transfer(pool_conf_t *, pool_resource_t *,
1907c478bd9Sstevel@tonic-gate     pool_resource_t *, uint64_t);
1917c478bd9Sstevel@tonic-gate extern int pool_resource_xtransfer(pool_conf_t *, pool_resource_t *,
1927c478bd9Sstevel@tonic-gate     pool_resource_t *, pool_component_t **);
1937c478bd9Sstevel@tonic-gate extern pool_component_t **pool_query_resource_components(const pool_conf_t *,
1947c478bd9Sstevel@tonic-gate     const pool_resource_t *, uint_t *, pool_value_t **);
1957c478bd9Sstevel@tonic-gate extern char *pool_resource_info(const pool_conf_t *, const pool_resource_t *,
1967c478bd9Sstevel@tonic-gate     int);
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate /* Pool manipulation */
1997c478bd9Sstevel@tonic-gate extern pool_t *pool_create(pool_conf_t *, const char *);
2007c478bd9Sstevel@tonic-gate extern int pool_destroy(pool_conf_t *, pool_t *);
2017c478bd9Sstevel@tonic-gate extern int pool_associate(pool_conf_t *, pool_t *, const pool_resource_t *);
2027c478bd9Sstevel@tonic-gate extern int pool_dissociate(pool_conf_t *, pool_t *, const pool_resource_t *);
2037c478bd9Sstevel@tonic-gate extern char *pool_info(const pool_conf_t *, const pool_t *, int);
2047c478bd9Sstevel@tonic-gate extern pool_resource_t **pool_query_pool_resources(const pool_conf_t *,
2057c478bd9Sstevel@tonic-gate     const pool_t *, uint_t *, pool_value_t **);
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate /* Resource Component Manipulation */
2087c478bd9Sstevel@tonic-gate extern pool_resource_t *pool_get_owning_resource(const pool_conf_t *,
2097c478bd9Sstevel@tonic-gate     const pool_component_t *);
2107c478bd9Sstevel@tonic-gate extern char *pool_component_info(const pool_conf_t *, const pool_component_t *,
2117c478bd9Sstevel@tonic-gate     int);
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate /* Property manipulation */
2147c478bd9Sstevel@tonic-gate extern pool_value_class_t pool_get_property(const pool_conf_t *,
2157c478bd9Sstevel@tonic-gate     const pool_elem_t *, const char *, pool_value_t *);
2167c478bd9Sstevel@tonic-gate extern int pool_put_property(pool_conf_t *, pool_elem_t *, const char *,
2177c478bd9Sstevel@tonic-gate     const pool_value_t *);
2187c478bd9Sstevel@tonic-gate extern int pool_rm_property(pool_conf_t *, pool_elem_t *, const char *);
219*0209230bSgjelinek 
2207c478bd9Sstevel@tonic-gate /*
2217c478bd9Sstevel@tonic-gate  * Walk the associated properties of the supplied element calling the supplied
2227c478bd9Sstevel@tonic-gate  * function for each property in turn. There is no implied order in the walk.
2237c478bd9Sstevel@tonic-gate  * The arg parameter allows caller-specific data to be passed to the call.
2247c478bd9Sstevel@tonic-gate  */
2257c478bd9Sstevel@tonic-gate extern int pool_walk_properties(pool_conf_t *, pool_elem_t *, void *,
2267c478bd9Sstevel@tonic-gate     int (*)(pool_conf_t *, pool_elem_t *, const char *, pool_value_t *,
2277c478bd9Sstevel@tonic-gate 	    void *));
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate /* Get the underlying element */
2307c478bd9Sstevel@tonic-gate extern pool_elem_t *pool_conf_to_elem(const pool_conf_t *);
2317c478bd9Sstevel@tonic-gate extern pool_elem_t *pool_to_elem(const pool_conf_t *, const pool_t *);
2327c478bd9Sstevel@tonic-gate extern pool_elem_t *pool_resource_to_elem(const pool_conf_t *,
2337c478bd9Sstevel@tonic-gate     const pool_resource_t *);
2347c478bd9Sstevel@tonic-gate extern pool_elem_t *pool_component_to_elem(const pool_conf_t *,
2357c478bd9Sstevel@tonic-gate     const pool_component_t *);
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate /* Pool Property Value Manipulation */
2387c478bd9Sstevel@tonic-gate /* Get/Set Pool Property Values and Type */
2397c478bd9Sstevel@tonic-gate extern int pool_value_get_uint64(const pool_value_t *, uint64_t *);
2407c478bd9Sstevel@tonic-gate extern int pool_value_get_int64(const pool_value_t *, int64_t *);
2417c478bd9Sstevel@tonic-gate extern int pool_value_get_double(const pool_value_t *, double *);
2427c478bd9Sstevel@tonic-gate extern int pool_value_get_bool(const pool_value_t *, uchar_t *);
2437c478bd9Sstevel@tonic-gate extern int pool_value_get_string(const pool_value_t *, const char **);
2447c478bd9Sstevel@tonic-gate extern pool_value_class_t pool_value_get_type(const pool_value_t *);
2457c478bd9Sstevel@tonic-gate extern void pool_value_set_uint64(pool_value_t *, uint64_t);
2467c478bd9Sstevel@tonic-gate extern void pool_value_set_int64(pool_value_t *, int64_t);
2477c478bd9Sstevel@tonic-gate extern void pool_value_set_double(pool_value_t *, double);
2487c478bd9Sstevel@tonic-gate extern void pool_value_set_bool(pool_value_t *, uchar_t);
2497c478bd9Sstevel@tonic-gate extern int pool_value_set_string(pool_value_t *, const char *);
2507c478bd9Sstevel@tonic-gate extern const char *pool_value_get_name(const pool_value_t *);
2517c478bd9Sstevel@tonic-gate extern int pool_value_set_name(pool_value_t *, const char *);
2527c478bd9Sstevel@tonic-gate 
2537c478bd9Sstevel@tonic-gate /* Pool Property Value Creation/Destruction */
2547c478bd9Sstevel@tonic-gate extern pool_value_t *pool_value_alloc(void);
2557c478bd9Sstevel@tonic-gate extern void pool_value_free(pool_value_t *);
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate /* Default pool data store locations */
2587c478bd9Sstevel@tonic-gate extern const char *pool_static_location(void);
2597c478bd9Sstevel@tonic-gate extern const char *pool_dynamic_location(void);
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate /* Binding */
2627c478bd9Sstevel@tonic-gate extern int pool_set_binding(const char *, idtype_t, id_t);
2637c478bd9Sstevel@tonic-gate extern char *pool_get_binding(pid_t);
2647c478bd9Sstevel@tonic-gate extern char *pool_get_resource_binding(const char *, pid_t);
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate /* Walking */
2677c478bd9Sstevel@tonic-gate extern int pool_walk_pools(pool_conf_t *, void *,
2687c478bd9Sstevel@tonic-gate     int (*)(pool_conf_t *, pool_t *, void *));
2697c478bd9Sstevel@tonic-gate extern int pool_walk_resources(pool_conf_t *, pool_t *, void *,
2707c478bd9Sstevel@tonic-gate     int (*)(pool_conf_t *, pool_resource_t *, void *));
2717c478bd9Sstevel@tonic-gate extern int pool_walk_components(pool_conf_t *, pool_resource_t *, void *,
2727c478bd9Sstevel@tonic-gate     int (*)(pool_conf_t *, pool_component_t *, void *));
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2757c478bd9Sstevel@tonic-gate }
2767c478bd9Sstevel@tonic-gate #endif
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate #endif	/* _POOL_H */
279