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