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