xref: /titanic_51/usr/src/lib/libpool/common/pool_internal.h (revision 0209230bf1261579beab4f55226bb509e6b850cb)
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 #ifndef	_POOL_INTERNAL_H
277c478bd9Sstevel@tonic-gate #define	_POOL_INTERNAL_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #include <libnvpair.h>
327c478bd9Sstevel@tonic-gate #include <stdarg.h>
337c478bd9Sstevel@tonic-gate #include <sys/pool.h>
347c478bd9Sstevel@tonic-gate #include <sys/pool_impl.h>
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
377c478bd9Sstevel@tonic-gate extern "C" {
387c478bd9Sstevel@tonic-gate #endif
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate /*
417c478bd9Sstevel@tonic-gate  * This file contains the libpool internal definitions which are not
427c478bd9Sstevel@tonic-gate  * directly related to the data access abstraction logic.
437c478bd9Sstevel@tonic-gate  */
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate /*
467c478bd9Sstevel@tonic-gate  * Define the various query specifiers for use in the
477c478bd9Sstevel@tonic-gate  * pool_connection_t query function, pc_exec_query.
487c478bd9Sstevel@tonic-gate  */
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate #define	PEC_QRY_ANY		(PEC_QRY_SYSTEM | PEC_QRY_POOL | PEC_QRY_RES | \
517c478bd9Sstevel@tonic-gate 				    PEC_QRY_COMP)
527c478bd9Sstevel@tonic-gate #define	PEC_QRY_SYSTEM		(1 << PEC_SYSTEM)
537c478bd9Sstevel@tonic-gate #define	PEC_QRY_POOL		(1 << PEC_POOL)
547c478bd9Sstevel@tonic-gate #define	PEC_QRY_RES		(PEC_QRY_RES_COMP | PEC_QRY_RES_AGG)
557c478bd9Sstevel@tonic-gate #define	PEC_QRY_RES_COMP	(1 << PEC_RES_COMP)
567c478bd9Sstevel@tonic-gate #define	PEC_QRY_RES_AGG		(1 << PEC_RES_AGG)
577c478bd9Sstevel@tonic-gate #define	PEC_QRY_COMP		(1 << PEC_COMP)
587c478bd9Sstevel@tonic-gate #define	PEC_QRY_ELEM(e)		(1 << pool_elem_class(e))
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate /*
617c478bd9Sstevel@tonic-gate  * Internal type conversion macros
627c478bd9Sstevel@tonic-gate  */
637c478bd9Sstevel@tonic-gate #define	TO_ELEM(s)		((pool_elem_t *)s)
647c478bd9Sstevel@tonic-gate /*
657c478bd9Sstevel@tonic-gate  * Get the configuration to which the supplied element belongs.
667c478bd9Sstevel@tonic-gate  */
677c478bd9Sstevel@tonic-gate #define	TO_CONF(s)		(s->pe_conf)
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate /*
707c478bd9Sstevel@tonic-gate  * Known Data Store Types
717c478bd9Sstevel@tonic-gate  */
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate #define	XML_DATA_STORE	0
747c478bd9Sstevel@tonic-gate #define	KERNEL_DATA_STORE	1
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate /*
777c478bd9Sstevel@tonic-gate  * Limits on pool values names and strings
787c478bd9Sstevel@tonic-gate  */
797c478bd9Sstevel@tonic-gate #define	PV_NAME_MAX_LEN		1024
807c478bd9Sstevel@tonic-gate #define	PV_VALUE_MAX_LEN	1024
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate /*
837c478bd9Sstevel@tonic-gate  * CB_TAB_BUF_SIZE represents the maximum number of indents to which a
847c478bd9Sstevel@tonic-gate  * char_buf_t is expected to grow. This value would need to be raised
857c478bd9Sstevel@tonic-gate  * if it was ever exceeded. It is an arbitrary limit, but currently
867c478bd9Sstevel@tonic-gate  * the implementation does not exceed a depth of 4.
877c478bd9Sstevel@tonic-gate  */
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate #define	CB_TAB_BUF_SIZE	8
907c478bd9Sstevel@tonic-gate #define	CB_DEFAULT_LEN	256
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate /*
937c478bd9Sstevel@tonic-gate  * Helpful pset macros
947c478bd9Sstevel@tonic-gate  */
957c478bd9Sstevel@tonic-gate #define	PSID_IS_SYSSET(psid)	(psid == PS_NONE)
967c478bd9Sstevel@tonic-gate #define	POOL_SYSID_BAD		(-2)
977c478bd9Sstevel@tonic-gate #define	POOL_SYSID_BAD_STRING	"-2"
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate /*
1007c478bd9Sstevel@tonic-gate  * Size of generated ref_id buffer
1017c478bd9Sstevel@tonic-gate  */
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate #define	KEY_BUFFER_SIZE	48
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate /*
1067c478bd9Sstevel@tonic-gate  * Various useful constant strings which are often encountered
1077c478bd9Sstevel@tonic-gate  */
1087c478bd9Sstevel@tonic-gate extern const char *c_a_dtype;
1097c478bd9Sstevel@tonic-gate extern const char *c_name;
1107c478bd9Sstevel@tonic-gate extern const char *c_type;
1117c478bd9Sstevel@tonic-gate extern const char *c_ref_id;
1127c478bd9Sstevel@tonic-gate extern const char *c_max_prop;
1137c478bd9Sstevel@tonic-gate extern const char *c_min_prop;
1147c478bd9Sstevel@tonic-gate extern const char *c_size_prop;
1157c478bd9Sstevel@tonic-gate extern const char *c_sys_prop;
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate /*
1187c478bd9Sstevel@tonic-gate  * The char_buf_t type is a very simple string implementation which
1197c478bd9Sstevel@tonic-gate  * makes it easier to manipulate complex character data.
1207c478bd9Sstevel@tonic-gate  */
1217c478bd9Sstevel@tonic-gate typedef struct char_buf
1227c478bd9Sstevel@tonic-gate {
1237c478bd9Sstevel@tonic-gate 	size_t cb_size;
1247c478bd9Sstevel@tonic-gate 	char *cb_buf;
1257c478bd9Sstevel@tonic-gate 	char cb_tab_buf[CB_TAB_BUF_SIZE];
1267c478bd9Sstevel@tonic-gate } char_buf_t;
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate /*
1297c478bd9Sstevel@tonic-gate  * libpool uses an opaque discriminated union type, pool_value_t, to
1307c478bd9Sstevel@tonic-gate  * contain values which are used to get/set properties on
1317c478bd9Sstevel@tonic-gate  * configuration components. Each value is strictly typed and the
1327c478bd9Sstevel@tonic-gate  * functions to manipulate these types are exported through the
1337c478bd9Sstevel@tonic-gate  * external interface.
1347c478bd9Sstevel@tonic-gate  */
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate /*
1377c478bd9Sstevel@tonic-gate  * Initialize a pool_value_t
1387c478bd9Sstevel@tonic-gate  */
1397c478bd9Sstevel@tonic-gate #define	POOL_VALUE_INITIALIZER	/* = DEFAULT POOL VALUE */	\
1407c478bd9Sstevel@tonic-gate 	{POC_INVAL, NULL, NULL }
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate struct pool_value {
1437c478bd9Sstevel@tonic-gate 	pool_value_class_t	pv_class;		/* Value type */
1447c478bd9Sstevel@tonic-gate 	const char		*pv_name;		/* Value name */
1457c478bd9Sstevel@tonic-gate 	union
1467c478bd9Sstevel@tonic-gate 	{
1477c478bd9Sstevel@tonic-gate 		uint64_t	u;
1487c478bd9Sstevel@tonic-gate 		int64_t		i;
1497c478bd9Sstevel@tonic-gate 		double		d;
1507c478bd9Sstevel@tonic-gate 		uchar_t		b;
1517c478bd9Sstevel@tonic-gate 		const char	*s;
1527c478bd9Sstevel@tonic-gate 	} pv_u;
1537c478bd9Sstevel@tonic-gate };
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate /*
1567c478bd9Sstevel@tonic-gate  * The pool_prop_op_t structure is used to perform property specific validation
1577c478bd9Sstevel@tonic-gate  * when setting the values of properties in a plugin and when getting a property
1587c478bd9Sstevel@tonic-gate  * value which is not stored (i.e. it is generated dynamically by the plugin at
1597c478bd9Sstevel@tonic-gate  * access.
1607c478bd9Sstevel@tonic-gate  *
1617c478bd9Sstevel@tonic-gate  * - ppo_get_value will provide a value for the specified property
1627c478bd9Sstevel@tonic-gate  * - ppo_set_value will allow a provider to validate a value before setting it
1637c478bd9Sstevel@tonic-gate  */
1647c478bd9Sstevel@tonic-gate typedef struct pool_prop_op {
1657c478bd9Sstevel@tonic-gate 	int	(*ppo_get_value)(const pool_elem_t *, pool_value_t *);
1667c478bd9Sstevel@tonic-gate 	int	(*ppo_set_value)(pool_elem_t *, const pool_value_t *);
1677c478bd9Sstevel@tonic-gate } pool_prop_op_t;
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate /*
1707c478bd9Sstevel@tonic-gate  * The pool_prop_t structure is used to hold all property related information
1717c478bd9Sstevel@tonic-gate  * for each property that a provider is interested in.
1727c478bd9Sstevel@tonic-gate  *
1737c478bd9Sstevel@tonic-gate  * - pp_pname is the name of the property
1747c478bd9Sstevel@tonic-gate  * - pp_value is the initial value of the property
1757c478bd9Sstevel@tonic-gate  * - pp_perms is an OR'd bitmap of the access characteristics for the property
1767c478bd9Sstevel@tonic-gate  * - pp_init is a function which initialises the value member of the property
1777c478bd9Sstevel@tonic-gate  * - pp_op is optional and supports access and validation of property values
1787c478bd9Sstevel@tonic-gate  */
1797c478bd9Sstevel@tonic-gate typedef struct pool_prop {
1807c478bd9Sstevel@tonic-gate 	const char	*pp_pname;
1817c478bd9Sstevel@tonic-gate 	pool_value_t	pp_value;
1827c478bd9Sstevel@tonic-gate 	uint_t		pp_perms;
1837c478bd9Sstevel@tonic-gate 	int		(*pp_init)(struct pool_prop *);
1847c478bd9Sstevel@tonic-gate 	pool_prop_op_t	pp_op;
1857c478bd9Sstevel@tonic-gate } pool_prop_t;
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate /*
1887c478bd9Sstevel@tonic-gate  * log state
1897c478bd9Sstevel@tonic-gate  */
1907c478bd9Sstevel@tonic-gate enum log_state {
1917c478bd9Sstevel@tonic-gate 	LS_DO,
1927c478bd9Sstevel@tonic-gate 	LS_UNDO,
1937c478bd9Sstevel@tonic-gate 	LS_RECOVER,
1947c478bd9Sstevel@tonic-gate 	LS_FAIL
1957c478bd9Sstevel@tonic-gate };
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate /*
1987c478bd9Sstevel@tonic-gate  * Forward declaration
1997c478bd9Sstevel@tonic-gate  */
2007c478bd9Sstevel@tonic-gate typedef struct log log_t;
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate /*
2037c478bd9Sstevel@tonic-gate  * log item.
2047c478bd9Sstevel@tonic-gate  *
2057c478bd9Sstevel@tonic-gate  * Used to describe each operation which needs to be logged. When
2067c478bd9Sstevel@tonic-gate  * modifications are desired to the kernel, they are logged in the
2077c478bd9Sstevel@tonic-gate  * configuration log file. If the user commits the changes, then the
2087c478bd9Sstevel@tonic-gate  * log entries are processed in sequence. If rollback is called, the
2097c478bd9Sstevel@tonic-gate  * log is dismissed without being processed. If the commit operation
2107c478bd9Sstevel@tonic-gate  * fails, then the log is "rolled back" to undo the previously
2117c478bd9Sstevel@tonic-gate  * successful operations.
2127c478bd9Sstevel@tonic-gate  */
2137c478bd9Sstevel@tonic-gate typedef struct log_item {
2147c478bd9Sstevel@tonic-gate 	log_t *li_log;				/* Log containing this item */
2157c478bd9Sstevel@tonic-gate 	int li_op;				/* Type of operation */
2167c478bd9Sstevel@tonic-gate 	void *li_details;			/* Operation details */
2177c478bd9Sstevel@tonic-gate 	struct log_item *li_next;		/* List of log items */
2187c478bd9Sstevel@tonic-gate 	struct log_item *li_prev;		/* List of log items */
2197c478bd9Sstevel@tonic-gate 	enum log_state li_state;		/* Item state */
2207c478bd9Sstevel@tonic-gate } log_item_t;
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate /*
2237c478bd9Sstevel@tonic-gate  * log.
2247c478bd9Sstevel@tonic-gate  *
2257c478bd9Sstevel@tonic-gate  * This maintains a list of log items. The sentinel is used to
2267c478bd9Sstevel@tonic-gate  * simplify processing around the "empty list". The state of the log
2277c478bd9Sstevel@tonic-gate  * indicates whether transactions are being processed normally, or
2287c478bd9Sstevel@tonic-gate  * whether recovery is in progress.
2297c478bd9Sstevel@tonic-gate  */
2307c478bd9Sstevel@tonic-gate struct log
2317c478bd9Sstevel@tonic-gate {
2327c478bd9Sstevel@tonic-gate 	pool_conf_t *l_conf;			/* Configuration for this log */
2337c478bd9Sstevel@tonic-gate 	log_item_t *l_sentinel;			/* Log sentinel */
2347c478bd9Sstevel@tonic-gate 	enum log_state l_state;			/* Log state */
2357c478bd9Sstevel@tonic-gate };
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate 
2387c478bd9Sstevel@tonic-gate /*
2397c478bd9Sstevel@tonic-gate  * log item action function type
2407c478bd9Sstevel@tonic-gate  */
2417c478bd9Sstevel@tonic-gate typedef int (*log_item_action_t)(log_item_t *);
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate /*
2447c478bd9Sstevel@tonic-gate  * Get the max/min/size property value of a resource.
2457c478bd9Sstevel@tonic-gate  */
2467c478bd9Sstevel@tonic-gate extern int		resource_get_max(const pool_resource_t *, uint64_t *);
2477c478bd9Sstevel@tonic-gate extern int		resource_get_min(const pool_resource_t *, uint64_t *);
2487c478bd9Sstevel@tonic-gate extern int		resource_get_size(const pool_resource_t *, uint64_t *);
2497c478bd9Sstevel@tonic-gate extern int		resource_get_pinned(const pool_resource_t *,
2507c478bd9Sstevel@tonic-gate 			    uint64_t *);
2517c478bd9Sstevel@tonic-gate 
2527c478bd9Sstevel@tonic-gate /*
2537c478bd9Sstevel@tonic-gate  * Element utility operations.
2547c478bd9Sstevel@tonic-gate  */
2557c478bd9Sstevel@tonic-gate extern char		*elem_get_name(const pool_elem_t *);
2567c478bd9Sstevel@tonic-gate extern id_t		elem_get_sysid(const pool_elem_t *);
2577c478bd9Sstevel@tonic-gate extern int    		elem_is_default(const pool_elem_t *);
258*0209230bSgjelinek extern boolean_t	elem_is_tmp(const pool_elem_t *);
2597c478bd9Sstevel@tonic-gate extern const pool_elem_t *get_default_elem(const pool_elem_t *);
2607c478bd9Sstevel@tonic-gate extern int		qsort_elem_compare(const void *, const void *);
2617c478bd9Sstevel@tonic-gate 
2627c478bd9Sstevel@tonic-gate /*
2637c478bd9Sstevel@tonic-gate  * Get the class of the supplied element.
2647c478bd9Sstevel@tonic-gate  */
2657c478bd9Sstevel@tonic-gate extern const char	*pool_elem_class_string(const pool_elem_t *);
2667c478bd9Sstevel@tonic-gate extern const char	*pool_resource_type_string(pool_resource_elem_class_t);
2677c478bd9Sstevel@tonic-gate extern const char *pool_component_type_string(pool_component_elem_class_t);
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate /*
2707c478bd9Sstevel@tonic-gate  * Commit the supplied configuration to the system. This function
2717c478bd9Sstevel@tonic-gate  * attempts to make the system look like the supplied configuration.
2727c478bd9Sstevel@tonic-gate  */
2737c478bd9Sstevel@tonic-gate extern int		pool_conf_commit_sys(pool_conf_t *, int);
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate /*
2767c478bd9Sstevel@tonic-gate  * Allocate an XML/kernel connection to a data representation.
2777c478bd9Sstevel@tonic-gate  */
2787c478bd9Sstevel@tonic-gate extern int		pool_xml_connection_alloc(pool_conf_t *, int);
2797c478bd9Sstevel@tonic-gate extern int		pool_knl_connection_alloc(pool_conf_t *, int);
2807c478bd9Sstevel@tonic-gate 
2817c478bd9Sstevel@tonic-gate /*
2827c478bd9Sstevel@tonic-gate  * Create/Destroy a pool component belonging to the supplied resource
2837c478bd9Sstevel@tonic-gate  */
2847c478bd9Sstevel@tonic-gate extern pool_component_t *pool_component_create(pool_conf_t *,
2857c478bd9Sstevel@tonic-gate     const pool_resource_t *, int64_t);
2867c478bd9Sstevel@tonic-gate extern int		pool_component_destroy(pool_component_t *);
2877c478bd9Sstevel@tonic-gate 
2887c478bd9Sstevel@tonic-gate /*
2897c478bd9Sstevel@tonic-gate  * Get/Set the owner (container) of a particular configuration
2907c478bd9Sstevel@tonic-gate  * element.
2917c478bd9Sstevel@tonic-gate  */
2927c478bd9Sstevel@tonic-gate extern pool_elem_t	*pool_get_container(const pool_elem_t *);
2937c478bd9Sstevel@tonic-gate extern int		pool_set_container(pool_elem_t *, pool_elem_t *);
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@tonic-gate /*
2967c478bd9Sstevel@tonic-gate  * These functions are used for debugging. Setting the environment
2977c478bd9Sstevel@tonic-gate  * variable LIBPOOL_DEBUG to 1, enables these functions.
2987c478bd9Sstevel@tonic-gate  */
2997c478bd9Sstevel@tonic-gate extern void		do_dprintf(const char *, va_list);
3007c478bd9Sstevel@tonic-gate extern void		dprintf(const char *, ...);
3017c478bd9Sstevel@tonic-gate 
3027c478bd9Sstevel@tonic-gate /*
3037c478bd9Sstevel@tonic-gate  * libpool maintains it's own error value, rather than further pollute
3047c478bd9Sstevel@tonic-gate  * errno, this function is used to set the current error value for
3057c478bd9Sstevel@tonic-gate  * retrieval.
3067c478bd9Sstevel@tonic-gate  */
3077c478bd9Sstevel@tonic-gate extern void		pool_seterror(int);
3087c478bd9Sstevel@tonic-gate 
3097c478bd9Sstevel@tonic-gate /*
3107c478bd9Sstevel@tonic-gate  * Element Class
3117c478bd9Sstevel@tonic-gate  */
3127c478bd9Sstevel@tonic-gate extern pool_elem_class_t pool_elem_class(const pool_elem_t *);
3137c478bd9Sstevel@tonic-gate extern pool_resource_elem_class_t pool_resource_elem_class(const pool_elem_t *);
3147c478bd9Sstevel@tonic-gate extern pool_component_elem_class_t pool_component_elem_class(const
3157c478bd9Sstevel@tonic-gate     pool_elem_t *);
3167c478bd9Sstevel@tonic-gate extern int pool_elem_same_class(const pool_elem_t *, const pool_elem_t *);
3177c478bd9Sstevel@tonic-gate extern pool_elem_class_t pool_elem_class_from_string(const char *);
3187c478bd9Sstevel@tonic-gate extern pool_resource_elem_class_t pool_resource_elem_class_from_string(const
3197c478bd9Sstevel@tonic-gate     char *);
3207c478bd9Sstevel@tonic-gate extern pool_component_elem_class_t pool_component_elem_class_from_string(const
3217c478bd9Sstevel@tonic-gate     char *);
3227c478bd9Sstevel@tonic-gate 
3237c478bd9Sstevel@tonic-gate /*
3247c478bd9Sstevel@tonic-gate  * Element Equivalency
3257c478bd9Sstevel@tonic-gate  */
3267c478bd9Sstevel@tonic-gate extern int		pool_elem_compare(const pool_elem_t *,
3277c478bd9Sstevel@tonic-gate     const pool_elem_t *);
3287c478bd9Sstevel@tonic-gate extern int		pool_elem_compare_name(const pool_elem_t *,
3297c478bd9Sstevel@tonic-gate     const pool_elem_t *);
3307c478bd9Sstevel@tonic-gate 
3317c478bd9Sstevel@tonic-gate /*
3327c478bd9Sstevel@tonic-gate  * Dynamic character buffers. Limited functionality but enough for our
3337c478bd9Sstevel@tonic-gate  * purposes.
3347c478bd9Sstevel@tonic-gate  */
3357c478bd9Sstevel@tonic-gate extern char_buf_t	*alloc_char_buf(size_t);
3367c478bd9Sstevel@tonic-gate extern void		free_char_buf(char_buf_t *);
3377c478bd9Sstevel@tonic-gate extern int		set_char_buf(char_buf_t *, const char *, ...);
3387c478bd9Sstevel@tonic-gate extern int		append_char_buf(char_buf_t *, const char *, ...);
3397c478bd9Sstevel@tonic-gate 
3407c478bd9Sstevel@tonic-gate /*
3417c478bd9Sstevel@tonic-gate  * Internal functions for use with pool values.
3427c478bd9Sstevel@tonic-gate  */
3437c478bd9Sstevel@tonic-gate extern int		pool_value_equal(pool_value_t *, pool_value_t *);
3447c478bd9Sstevel@tonic-gate extern int 		pool_value_from_nvpair(pool_value_t *, nvpair_t *);
3457c478bd9Sstevel@tonic-gate 
3467c478bd9Sstevel@tonic-gate /*
3477c478bd9Sstevel@tonic-gate  * Check to ensure that the supplied string is a valid name for a pool
3487c478bd9Sstevel@tonic-gate  * element.
3497c478bd9Sstevel@tonic-gate  */
3507c478bd9Sstevel@tonic-gate extern int		is_valid_name(const char *);
3517c478bd9Sstevel@tonic-gate 
3527c478bd9Sstevel@tonic-gate /*
3537c478bd9Sstevel@tonic-gate  * Functions related to element prefix manipulation. You can get the
3547c478bd9Sstevel@tonic-gate  * prefix for a supplied element or find out if a supplied string is a
3557c478bd9Sstevel@tonic-gate  * valid prefix for a certain class of element.
3567c478bd9Sstevel@tonic-gate  */
3577c478bd9Sstevel@tonic-gate extern const char	*elem_get_prefix(const pool_elem_t *);
3587c478bd9Sstevel@tonic-gate extern const char	*is_a_known_prefix(pool_elem_class_t, const char *);
3597c478bd9Sstevel@tonic-gate 
3607c478bd9Sstevel@tonic-gate /*
3617c478bd9Sstevel@tonic-gate  * Internal property manipulators
3627c478bd9Sstevel@tonic-gate  */
3637c478bd9Sstevel@tonic-gate extern int		pool_put_ns_property(pool_elem_t *, const char *,
3647c478bd9Sstevel@tonic-gate     const pool_value_t *);
3657c478bd9Sstevel@tonic-gate extern int		pool_put_any_property(pool_elem_t *, const char *,
3667c478bd9Sstevel@tonic-gate     const pool_value_t *);
3677c478bd9Sstevel@tonic-gate extern int		pool_put_any_ns_property(pool_elem_t *, const char *,
3687c478bd9Sstevel@tonic-gate     const pool_value_t *);
3697c478bd9Sstevel@tonic-gate extern pool_value_class_t pool_get_ns_property(const pool_elem_t *,
3707c478bd9Sstevel@tonic-gate     const char *, pool_value_t *);
3717c478bd9Sstevel@tonic-gate extern int		pool_walk_any_properties(pool_conf_t *, pool_elem_t *,
3727c478bd9Sstevel@tonic-gate     void *, int (*)(pool_conf_t *, pool_elem_t *, const char *,
3737c478bd9Sstevel@tonic-gate     pool_value_t *, void *), int);
374*0209230bSgjelinek extern int		pool_set_temporary(pool_conf_t *, pool_elem_t *);
3757c478bd9Sstevel@tonic-gate 
3767c478bd9Sstevel@tonic-gate /*
3777c478bd9Sstevel@tonic-gate  * Namespace aware utility functions.
3787c478bd9Sstevel@tonic-gate  */
3797c478bd9Sstevel@tonic-gate extern const char	*is_ns_property(const pool_elem_t *, const char *);
3807c478bd9Sstevel@tonic-gate extern const char	*property_name_minus_ns(const pool_elem_t *,
3817c478bd9Sstevel@tonic-gate     const char *);
3827c478bd9Sstevel@tonic-gate 
3837c478bd9Sstevel@tonic-gate /*
3847c478bd9Sstevel@tonic-gate  * Initialisation routines.
3857c478bd9Sstevel@tonic-gate  */
3867c478bd9Sstevel@tonic-gate extern void		internal_init(void);
3877c478bd9Sstevel@tonic-gate 
3887c478bd9Sstevel@tonic-gate /*
3897c478bd9Sstevel@tonic-gate  * Is the supplied configuration the dynamic configuration?
3907c478bd9Sstevel@tonic-gate  */
3917c478bd9Sstevel@tonic-gate extern int		conf_is_dynamic(const pool_conf_t *);
3927c478bd9Sstevel@tonic-gate 
3937c478bd9Sstevel@tonic-gate /*
3947c478bd9Sstevel@tonic-gate  * Update the library snapshot from the kernel
3957c478bd9Sstevel@tonic-gate  */
3967c478bd9Sstevel@tonic-gate extern int		pool_knl_update(pool_conf_t *, int *);
3977c478bd9Sstevel@tonic-gate 
3987c478bd9Sstevel@tonic-gate /*
3997c478bd9Sstevel@tonic-gate  * Resource property functions
4007c478bd9Sstevel@tonic-gate  */
4017c478bd9Sstevel@tonic-gate extern int    		resource_is_default(const pool_resource_t *);
4027c478bd9Sstevel@tonic-gate extern int    		resource_is_system(const pool_resource_t *);
4037c478bd9Sstevel@tonic-gate extern int    		resource_can_associate(const pool_resource_t *);
4047c478bd9Sstevel@tonic-gate extern const pool_resource_t	*get_default_resource(const pool_resource_t *);
4057c478bd9Sstevel@tonic-gate extern pool_resource_t 	*resource_by_sysid(const pool_conf_t *, id_t,
4067c478bd9Sstevel@tonic-gate     const char *);
4077c478bd9Sstevel@tonic-gate 
4087c478bd9Sstevel@tonic-gate /*
4097c478bd9Sstevel@tonic-gate  * Resource property provider functions
4107c478bd9Sstevel@tonic-gate  */
4117c478bd9Sstevel@tonic-gate extern uint_t		pool_get_provider_count(void);
4127c478bd9Sstevel@tonic-gate extern const pool_prop_t *provider_get_props(const pool_elem_t *);
4137c478bd9Sstevel@tonic-gate extern const pool_prop_t *provider_get_prop(const pool_elem_t *,
4147c478bd9Sstevel@tonic-gate     const char *);
4157c478bd9Sstevel@tonic-gate extern int		prop_is_stored(const pool_prop_t *);
4167c478bd9Sstevel@tonic-gate extern int		prop_is_readonly(const pool_prop_t *);
4177c478bd9Sstevel@tonic-gate extern int		prop_is_init(const pool_prop_t *);
4187c478bd9Sstevel@tonic-gate extern int		prop_is_hidden(const pool_prop_t *);
4197c478bd9Sstevel@tonic-gate extern int		prop_is_optional(const pool_prop_t *);
4207c478bd9Sstevel@tonic-gate 
4217c478bd9Sstevel@tonic-gate /*
4227c478bd9Sstevel@tonic-gate  * Component property functions
4237c478bd9Sstevel@tonic-gate  */
4247c478bd9Sstevel@tonic-gate extern int		cpu_is_requested(pool_component_t *);
4257c478bd9Sstevel@tonic-gate 
4267c478bd9Sstevel@tonic-gate /*
4277c478bd9Sstevel@tonic-gate  * Simple initialisation routines for values used when initialising the
4287c478bd9Sstevel@tonic-gate  * property arrays for each plugin
4297c478bd9Sstevel@tonic-gate  * Return PO_SUCCESS/PO_FAIL to indicate success/failure
4307c478bd9Sstevel@tonic-gate  */
4317c478bd9Sstevel@tonic-gate extern int		uint_init(pool_prop_t *, uint64_t);
4327c478bd9Sstevel@tonic-gate extern int		int_init(pool_prop_t *, int64_t);
4337c478bd9Sstevel@tonic-gate extern int		double_init(pool_prop_t *, double);
4347c478bd9Sstevel@tonic-gate extern int		bool_init(pool_prop_t *, uchar_t);
4357c478bd9Sstevel@tonic-gate extern int		string_init(pool_prop_t *, const char *);
4367c478bd9Sstevel@tonic-gate 
4377c478bd9Sstevel@tonic-gate 
4387c478bd9Sstevel@tonic-gate /*
4397c478bd9Sstevel@tonic-gate  * log functions
4407c478bd9Sstevel@tonic-gate  */
4417c478bd9Sstevel@tonic-gate extern log_t		*log_alloc(pool_conf_t *);
4427c478bd9Sstevel@tonic-gate extern void		log_free(log_t *);
4437c478bd9Sstevel@tonic-gate extern void		log_empty(log_t *);
4447c478bd9Sstevel@tonic-gate extern int		log_walk(log_t *, log_item_action_t);
4457c478bd9Sstevel@tonic-gate extern int		log_reverse_walk(log_t *, log_item_action_t);
4467c478bd9Sstevel@tonic-gate extern uint_t		log_size(log_t *);
4477c478bd9Sstevel@tonic-gate extern int		log_append(log_t *, int, void *);
4487c478bd9Sstevel@tonic-gate 
4497c478bd9Sstevel@tonic-gate /*
4507c478bd9Sstevel@tonic-gate  * log item functions
4517c478bd9Sstevel@tonic-gate  */
4527c478bd9Sstevel@tonic-gate extern log_item_t	*log_item_alloc(log_t *, int, void *);
4537c478bd9Sstevel@tonic-gate extern int		log_item_free(log_item_t *);
4547c478bd9Sstevel@tonic-gate 
4557c478bd9Sstevel@tonic-gate extern int		pool_validate_resource(const pool_conf_t *,
4567c478bd9Sstevel@tonic-gate     const char *, const char *, int64_t);
4577c478bd9Sstevel@tonic-gate 
4587c478bd9Sstevel@tonic-gate /*
4597c478bd9Sstevel@tonic-gate  * String atom functions
4607c478bd9Sstevel@tonic-gate  */
4617c478bd9Sstevel@tonic-gate extern const char	*atom_string(const char *);
4627c478bd9Sstevel@tonic-gate extern void		atom_free(const char *);
4637c478bd9Sstevel@tonic-gate /*
4647c478bd9Sstevel@tonic-gate  * debugging functions
4657c478bd9Sstevel@tonic-gate  */
4667c478bd9Sstevel@tonic-gate #ifdef DEBUG
4677c478bd9Sstevel@tonic-gate extern void		log_item_dprintf(log_item_t *);
4687c478bd9Sstevel@tonic-gate extern void		pool_value_dprintf(const pool_value_t *);
4697c478bd9Sstevel@tonic-gate extern void		pool_elem_dprintf(const pool_elem_t *);
4707c478bd9Sstevel@tonic-gate #endif
4717c478bd9Sstevel@tonic-gate 
4727c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
4737c478bd9Sstevel@tonic-gate }
4747c478bd9Sstevel@tonic-gate #endif
4757c478bd9Sstevel@tonic-gate 
4767c478bd9Sstevel@tonic-gate #endif	/* _POOL_INTERNAL_H */
477