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 #pragma ident "%Z%%M% %I% %E% SMI" 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate #include <limits.h> 297c478bd9Sstevel@tonic-gate #include <pool.h> 307c478bd9Sstevel@tonic-gate #include <stdlib.h> 317c478bd9Sstevel@tonic-gate #include <stdio.h> 327c478bd9Sstevel@tonic-gate #include <string.h> 337c478bd9Sstevel@tonic-gate #include <synch.h> 347c478bd9Sstevel@tonic-gate #include <thread.h> 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate #include <sys/loadavg.h> 377c478bd9Sstevel@tonic-gate #include <sys/types.h> 387c478bd9Sstevel@tonic-gate #include <sys/utsname.h> 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate #include "dict.h" 417c478bd9Sstevel@tonic-gate #include "pool_internal.h" 427c478bd9Sstevel@tonic-gate #include "pool_impl.h" 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate /* 457c478bd9Sstevel@tonic-gate * Atom structure, used to reference count string atoms. 467c478bd9Sstevel@tonic-gate */ 477c478bd9Sstevel@tonic-gate typedef struct { 487c478bd9Sstevel@tonic-gate char *a_string; /* String atom */ 497c478bd9Sstevel@tonic-gate uint_t a_count; /* String reference count */ 507c478bd9Sstevel@tonic-gate } atom_t; 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate /* 537c478bd9Sstevel@tonic-gate * The _internal_lock is used to lock the state of libpool during 547c478bd9Sstevel@tonic-gate * internal initialisation operations. 557c478bd9Sstevel@tonic-gate */ 567c478bd9Sstevel@tonic-gate mutex_t _internal_lock; 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate static int _libpool_debug = 0; /* debugging messages */ 597c478bd9Sstevel@tonic-gate static dict_hdl_t *_pv_atoms; /* pool_value_t atoms */ 607c478bd9Sstevel@tonic-gate static mutex_t _atom_lock; /* atom table lock */ 617c478bd9Sstevel@tonic-gate static int _libpool_internal_initialised = PO_FALSE; 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate /* 647c478bd9Sstevel@tonic-gate * Various useful constant strings which are often encountered 657c478bd9Sstevel@tonic-gate */ 667c478bd9Sstevel@tonic-gate const char *c_a_dtype = "a-dtype"; 677c478bd9Sstevel@tonic-gate const char *c_name = "name"; 687c478bd9Sstevel@tonic-gate const char *c_type = "type"; 697c478bd9Sstevel@tonic-gate const char *c_ref_id = "ref_id"; 707c478bd9Sstevel@tonic-gate const char *c_max_prop = "max"; 717c478bd9Sstevel@tonic-gate const char *c_min_prop = "min"; 727c478bd9Sstevel@tonic-gate const char *c_size_prop = "size"; 737c478bd9Sstevel@tonic-gate const char *c_sys_prop = "sys_id"; 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate /* 767c478bd9Sstevel@tonic-gate * prop_is_type() checks the supplied property and returns PO_TRUE if the 777c478bd9Sstevel@tonic-gate * property value is set for the property else PO_FALSE 787c478bd9Sstevel@tonic-gate */ 797c478bd9Sstevel@tonic-gate static int prop_is_type(int, const pool_prop_t *); 807c478bd9Sstevel@tonic-gate static int resource_get_common(const pool_resource_t *, const char *, 817c478bd9Sstevel@tonic-gate uint64_t *); 827c478bd9Sstevel@tonic-gate static int64_t elem_get_expected_int64(const pool_elem_t *, const char *); 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate /* 857c478bd9Sstevel@tonic-gate * The following returns a malloc'ed string which must be free'd by the 867c478bd9Sstevel@tonic-gate * caller. 877c478bd9Sstevel@tonic-gate */ 887c478bd9Sstevel@tonic-gate static char *elem_get_expected_string(const pool_elem_t *, const char *); 897c478bd9Sstevel@tonic-gate static int element_props_init(pool_prop_t *); 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate /* 927c478bd9Sstevel@tonic-gate * Each element class/sub-class has a set of properties and behaviours 937c478bd9Sstevel@tonic-gate * which are used to create the element with appropriate property 947c478bd9Sstevel@tonic-gate * values and to ensure correct property manipulations. The details 957c478bd9Sstevel@tonic-gate * are all stored in the following arrays. 967c478bd9Sstevel@tonic-gate */ 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate static int elem_name_init(pool_prop_t *); 997c478bd9Sstevel@tonic-gate static int elem_comment_init(pool_prop_t *); 1007c478bd9Sstevel@tonic-gate 1017c478bd9Sstevel@tonic-gate static int pool_importance_init(pool_prop_t *); 1027c478bd9Sstevel@tonic-gate static int pool_active_init(pool_prop_t *); 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate static int res_max_init(pool_prop_t *); 1057c478bd9Sstevel@tonic-gate static int res_min_init(pool_prop_t *); 1067c478bd9Sstevel@tonic-gate static int res_size_init(pool_prop_t *); 1077c478bd9Sstevel@tonic-gate static int res_load_init(pool_prop_t *); 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate static int pset_units_init(pool_prop_t *); 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate static int cpu_status_init(pool_prop_t *); 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate static int elem_no_set(pool_elem_t *, const pool_value_t *); 1147c478bd9Sstevel@tonic-gate static int elem_set_name(pool_elem_t *, const pool_value_t *); 1157c478bd9Sstevel@tonic-gate static int elem_get_type(const pool_elem_t *, pool_value_t *); 1167c478bd9Sstevel@tonic-gate static int elem_set_string(pool_elem_t *, const pool_value_t *); 1177c478bd9Sstevel@tonic-gate static int elem_set_bool(pool_elem_t *, const pool_value_t *); 1187c478bd9Sstevel@tonic-gate static int elem_set_uint(pool_elem_t *, const pool_value_t *); 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate static int system_set_allocate(pool_elem_t *, const pool_value_t *); 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate static int pool_set_scheduler(pool_elem_t *, const pool_value_t *); 1237c478bd9Sstevel@tonic-gate static int pool_set_active(pool_elem_t *, const pool_value_t *); 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate static int res_set_max(pool_elem_t *, const pool_value_t *); 1267c478bd9Sstevel@tonic-gate static int res_set_min(pool_elem_t *, const pool_value_t *); 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate static int cpu_set_status(pool_elem_t *, const pool_value_t *); 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate static const char *pool_elem_class_name[] = { 1317c478bd9Sstevel@tonic-gate "invalid", 1327c478bd9Sstevel@tonic-gate "system", 1337c478bd9Sstevel@tonic-gate "pool", 1347c478bd9Sstevel@tonic-gate "component resource", 1357c478bd9Sstevel@tonic-gate "aggregate resource", 1367c478bd9Sstevel@tonic-gate "component" 1377c478bd9Sstevel@tonic-gate }; 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate /* 1407c478bd9Sstevel@tonic-gate * This must be kept in sync with the pool_resource_elem_ctl array and 1417c478bd9Sstevel@tonic-gate * the "enum pool_resource_elem_class" type. 1427c478bd9Sstevel@tonic-gate */ 1437c478bd9Sstevel@tonic-gate static const char *pool_resource_elem_class_name[] = { 1447c478bd9Sstevel@tonic-gate "invalid", 1457c478bd9Sstevel@tonic-gate "pset" 1467c478bd9Sstevel@tonic-gate }; 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate static const char *pool_component_elem_class_name[] = { 1497c478bd9Sstevel@tonic-gate "invalid", 1507c478bd9Sstevel@tonic-gate "cpu" 1517c478bd9Sstevel@tonic-gate }; 1527c478bd9Sstevel@tonic-gate 1537c478bd9Sstevel@tonic-gate static pool_prop_t system_props[] = { 1547c478bd9Sstevel@tonic-gate { "system.name", POOL_VALUE_INITIALIZER, PP_STORED, NULL, 1557c478bd9Sstevel@tonic-gate { NULL, elem_set_name } }, 1567c478bd9Sstevel@tonic-gate { "system.ref_id", POOL_VALUE_INITIALIZER, 1577c478bd9Sstevel@tonic-gate PP_HIDDEN | PP_STORED | PP_READ, NULL, { NULL, elem_no_set } }, 1587c478bd9Sstevel@tonic-gate { "system.comment", POOL_VALUE_INITIALIZER, PP_STORED, NULL, NULL }, 1597c478bd9Sstevel@tonic-gate { "system.version", POOL_VALUE_INITIALIZER, 1607c478bd9Sstevel@tonic-gate PP_STORED | PP_READ, NULL, NULL }, 1617c478bd9Sstevel@tonic-gate { "system.bind-default", POOL_VALUE_INITIALIZER, 1627c478bd9Sstevel@tonic-gate PP_STORED, NULL, NULL }, 1637c478bd9Sstevel@tonic-gate { "system.allocate-method", POOL_VALUE_INITIALIZER, 1647c478bd9Sstevel@tonic-gate PP_STORED | PP_OPTIONAL, NULL, { NULL, system_set_allocate } }, 1657c478bd9Sstevel@tonic-gate { "system.poold.log-level", POOL_VALUE_INITIALIZER, 1667c478bd9Sstevel@tonic-gate PP_STORED | PP_OPTIONAL, NULL, { NULL, elem_set_string } }, 1677c478bd9Sstevel@tonic-gate { "system.poold.log-location", POOL_VALUE_INITIALIZER, 1687c478bd9Sstevel@tonic-gate PP_STORED | PP_OPTIONAL, NULL, { NULL, elem_set_string } }, 1697c478bd9Sstevel@tonic-gate { "system.poold.monitor-interval", POOL_VALUE_INITIALIZER, 1707c478bd9Sstevel@tonic-gate PP_STORED | PP_OPTIONAL, NULL, { NULL, elem_set_uint } }, 1717c478bd9Sstevel@tonic-gate { "system.poold.history-file", POOL_VALUE_INITIALIZER, 1727c478bd9Sstevel@tonic-gate PP_STORED | PP_OPTIONAL, NULL, { NULL, elem_set_string } }, 1737c478bd9Sstevel@tonic-gate { "system.poold.objectives", POOL_VALUE_INITIALIZER, 1747c478bd9Sstevel@tonic-gate PP_STORED | PP_OPTIONAL, NULL, { NULL, elem_set_string } }, 1757c478bd9Sstevel@tonic-gate NULL 1767c478bd9Sstevel@tonic-gate }; 1777c478bd9Sstevel@tonic-gate 1787c478bd9Sstevel@tonic-gate static pool_prop_t pool_props[] = { 1797c478bd9Sstevel@tonic-gate { "pool.sys_id", POOL_VALUE_INITIALIZER, 1807c478bd9Sstevel@tonic-gate PP_STORED | PP_READ, NULL, NULL }, 1817c478bd9Sstevel@tonic-gate { "pool.name", POOL_VALUE_INITIALIZER, 1827c478bd9Sstevel@tonic-gate PP_STORED | PP_INIT, elem_name_init, { NULL, elem_set_name } }, 1837c478bd9Sstevel@tonic-gate { "pool.res", POOL_VALUE_INITIALIZER, 1847c478bd9Sstevel@tonic-gate PP_HIDDEN | PP_STORED | PP_READ, NULL, { NULL, elem_no_set } }, 1857c478bd9Sstevel@tonic-gate { "pool.ref_id", POOL_VALUE_INITIALIZER, 1867c478bd9Sstevel@tonic-gate PP_HIDDEN | PP_STORED | PP_READ, NULL, { NULL, elem_no_set } }, 1877c478bd9Sstevel@tonic-gate { "pool.active", POOL_VALUE_INITIALIZER, PP_STORED | PP_INIT, 1887c478bd9Sstevel@tonic-gate pool_active_init, { NULL, pool_set_active } }, 1897c478bd9Sstevel@tonic-gate { "pool.default", POOL_VALUE_INITIALIZER, 1907c478bd9Sstevel@tonic-gate PP_STORED | PP_READ, NULL, NULL }, 1917c478bd9Sstevel@tonic-gate { "pool.scheduler", POOL_VALUE_INITIALIZER, 1927c478bd9Sstevel@tonic-gate PP_STORED | PP_OPTIONAL, NULL, 1937c478bd9Sstevel@tonic-gate { NULL, pool_set_scheduler } }, 1947c478bd9Sstevel@tonic-gate { "pool.importance", POOL_VALUE_INITIALIZER, PP_STORED | PP_INIT, 1957c478bd9Sstevel@tonic-gate pool_importance_init, NULL }, 1967c478bd9Sstevel@tonic-gate { "pool.comment", POOL_VALUE_INITIALIZER, PP_STORED | PP_INIT, 1977c478bd9Sstevel@tonic-gate elem_comment_init, NULL }, 1987c478bd9Sstevel@tonic-gate NULL 1997c478bd9Sstevel@tonic-gate }; 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate static pool_prop_t pset_props[] = { 2027c478bd9Sstevel@tonic-gate { "type", POOL_VALUE_INITIALIZER, PP_HIDDEN | PP_STORED | PP_READ, NULL, 2037c478bd9Sstevel@tonic-gate { elem_get_type, NULL } }, 2047c478bd9Sstevel@tonic-gate { "pset.sys_id", POOL_VALUE_INITIALIZER, 2057c478bd9Sstevel@tonic-gate PP_STORED | PP_READ, NULL, NULL }, 2067c478bd9Sstevel@tonic-gate { "pset.name", POOL_VALUE_INITIALIZER, 2077c478bd9Sstevel@tonic-gate PP_STORED | PP_INIT, elem_name_init, { NULL, elem_set_name } }, 2087c478bd9Sstevel@tonic-gate { "pset.ref_id", POOL_VALUE_INITIALIZER, 2097c478bd9Sstevel@tonic-gate PP_HIDDEN | PP_STORED | PP_READ, NULL, { NULL, elem_no_set } }, 2107c478bd9Sstevel@tonic-gate { "pset.default", POOL_VALUE_INITIALIZER, 2117c478bd9Sstevel@tonic-gate PP_STORED | PP_READ, NULL, NULL }, 2127c478bd9Sstevel@tonic-gate { "pset.min", POOL_VALUE_INITIALIZER, PP_STORED | PP_INIT, res_min_init, 2137c478bd9Sstevel@tonic-gate { NULL, res_set_min } }, 2147c478bd9Sstevel@tonic-gate { "pset.max", POOL_VALUE_INITIALIZER, PP_STORED | PP_INIT, res_max_init, 2157c478bd9Sstevel@tonic-gate { NULL, res_set_max } }, 2167c478bd9Sstevel@tonic-gate { "pset.units", POOL_VALUE_INITIALIZER, 2177c478bd9Sstevel@tonic-gate PP_STORED | PP_INIT, pset_units_init, NULL }, 2187c478bd9Sstevel@tonic-gate { "pset.load", POOL_VALUE_INITIALIZER, PP_READ | PP_INIT, 2197c478bd9Sstevel@tonic-gate res_load_init, NULL }, 2207c478bd9Sstevel@tonic-gate { "pset.size", POOL_VALUE_INITIALIZER, PP_STORED | PP_INIT | PP_READ, 2217c478bd9Sstevel@tonic-gate res_size_init, NULL }, 2227c478bd9Sstevel@tonic-gate { "pset.comment", POOL_VALUE_INITIALIZER, PP_STORED | PP_INIT, 2237c478bd9Sstevel@tonic-gate elem_comment_init, NULL }, 2247c478bd9Sstevel@tonic-gate { "pset.poold.objectives", POOL_VALUE_INITIALIZER, 2257c478bd9Sstevel@tonic-gate PP_STORED | PP_OPTIONAL, NULL, { NULL, elem_set_string } }, 2267c478bd9Sstevel@tonic-gate NULL 2277c478bd9Sstevel@tonic-gate }; 2287c478bd9Sstevel@tonic-gate 2297c478bd9Sstevel@tonic-gate static pool_prop_t cpu_props[] = { 2307c478bd9Sstevel@tonic-gate { "type", POOL_VALUE_INITIALIZER, PP_HIDDEN | PP_STORED | PP_READ, NULL, 2317c478bd9Sstevel@tonic-gate { elem_get_type, NULL } }, 2327c478bd9Sstevel@tonic-gate { "cpu.sys_id", POOL_VALUE_INITIALIZER, PP_STORED | PP_READ, NULL, 2337c478bd9Sstevel@tonic-gate NULL }, 2347c478bd9Sstevel@tonic-gate { "cpu.ref_id", POOL_VALUE_INITIALIZER, 2357c478bd9Sstevel@tonic-gate PP_HIDDEN | PP_STORED | PP_READ, NULL, { NULL, elem_no_set } }, 2367c478bd9Sstevel@tonic-gate { "cpu.comment", POOL_VALUE_INITIALIZER, PP_STORED | PP_INIT, 2377c478bd9Sstevel@tonic-gate elem_comment_init, NULL }, 2387c478bd9Sstevel@tonic-gate { "cpu.status", POOL_VALUE_INITIALIZER, PP_INIT, cpu_status_init, 2397c478bd9Sstevel@tonic-gate { NULL, cpu_set_status } }, 2407c478bd9Sstevel@tonic-gate { "cpu.pinned", POOL_VALUE_INITIALIZER, PP_STORED | PP_OPTIONAL, NULL, 2417c478bd9Sstevel@tonic-gate { NULL, elem_set_bool } }, 2427c478bd9Sstevel@tonic-gate NULL 2437c478bd9Sstevel@tonic-gate }; 2447c478bd9Sstevel@tonic-gate 2457c478bd9Sstevel@tonic-gate static pool_prop_t *pool_elem_ctl[] = { 2467c478bd9Sstevel@tonic-gate NULL, 2477c478bd9Sstevel@tonic-gate system_props, 2487c478bd9Sstevel@tonic-gate pool_props, 2497c478bd9Sstevel@tonic-gate NULL, 2507c478bd9Sstevel@tonic-gate NULL, 2517c478bd9Sstevel@tonic-gate NULL 2527c478bd9Sstevel@tonic-gate }; 2537c478bd9Sstevel@tonic-gate 2547c478bd9Sstevel@tonic-gate /* 2557c478bd9Sstevel@tonic-gate * This must be kept in sync with the pool_resource_elem_class_name array and 2567c478bd9Sstevel@tonic-gate * the "enum pool_resource_elem_class" type. 2577c478bd9Sstevel@tonic-gate */ 2587c478bd9Sstevel@tonic-gate static pool_prop_t *pool_resource_elem_ctl[] = { 2597c478bd9Sstevel@tonic-gate NULL, 2607c478bd9Sstevel@tonic-gate pset_props 2617c478bd9Sstevel@tonic-gate }; 2627c478bd9Sstevel@tonic-gate 2637c478bd9Sstevel@tonic-gate static pool_prop_t *pool_component_elem_ctl[] = { 2647c478bd9Sstevel@tonic-gate NULL, 2657c478bd9Sstevel@tonic-gate cpu_props 2667c478bd9Sstevel@tonic-gate }; 2677c478bd9Sstevel@tonic-gate 2687c478bd9Sstevel@tonic-gate static void 2697c478bd9Sstevel@tonic-gate atom_init(void) 2707c478bd9Sstevel@tonic-gate { 2717c478bd9Sstevel@tonic-gate (void) mutex_lock(&_atom_lock); 2727c478bd9Sstevel@tonic-gate /* 2737c478bd9Sstevel@tonic-gate * Initialize pool_value_t atom dictionary 2747c478bd9Sstevel@tonic-gate */ 2757c478bd9Sstevel@tonic-gate if (_pv_atoms == NULL) 2767c478bd9Sstevel@tonic-gate if ((_pv_atoms = dict_new((int (*)(const void *, const void *)) 2777c478bd9Sstevel@tonic-gate strcmp, (uint64_t (*)(const void *))hash_str)) == NULL) 2787c478bd9Sstevel@tonic-gate abort(); 2797c478bd9Sstevel@tonic-gate (void) mutex_unlock(&_atom_lock); 2807c478bd9Sstevel@tonic-gate } 2817c478bd9Sstevel@tonic-gate 2827c478bd9Sstevel@tonic-gate /* 2837c478bd9Sstevel@tonic-gate * Initializer, called when the library is initialized. 2847c478bd9Sstevel@tonic-gate */ 2857c478bd9Sstevel@tonic-gate void 2867c478bd9Sstevel@tonic-gate internal_init(void) 2877c478bd9Sstevel@tonic-gate { 2887c478bd9Sstevel@tonic-gate (void) mutex_lock(&_internal_lock); 2897c478bd9Sstevel@tonic-gate if (_libpool_internal_initialised == PO_TRUE) { 2907c478bd9Sstevel@tonic-gate (void) mutex_unlock(&_internal_lock); 2917c478bd9Sstevel@tonic-gate return; 2927c478bd9Sstevel@tonic-gate } 2937c478bd9Sstevel@tonic-gate atom_init(); 2947c478bd9Sstevel@tonic-gate /* 2957c478bd9Sstevel@tonic-gate * Initialize all available property arrays. 2967c478bd9Sstevel@tonic-gate */ 2977c478bd9Sstevel@tonic-gate if (element_props_init(system_props) == PO_FAIL) 2987c478bd9Sstevel@tonic-gate abort(); 2997c478bd9Sstevel@tonic-gate if (element_props_init(pool_props) == PO_FAIL) 3007c478bd9Sstevel@tonic-gate abort(); 3017c478bd9Sstevel@tonic-gate if (element_props_init(pset_props) == PO_FAIL) 3027c478bd9Sstevel@tonic-gate abort(); 3037c478bd9Sstevel@tonic-gate if (element_props_init(cpu_props) == PO_FAIL) 3047c478bd9Sstevel@tonic-gate abort(); 3057c478bd9Sstevel@tonic-gate _libpool_internal_initialised = PO_TRUE; 3067c478bd9Sstevel@tonic-gate (void) mutex_unlock(&_internal_lock); 3077c478bd9Sstevel@tonic-gate 3087c478bd9Sstevel@tonic-gate } 3097c478bd9Sstevel@tonic-gate 3107c478bd9Sstevel@tonic-gate static int 3117c478bd9Sstevel@tonic-gate element_props_init(pool_prop_t *props) 3127c478bd9Sstevel@tonic-gate { 3137c478bd9Sstevel@tonic-gate int i; 3147c478bd9Sstevel@tonic-gate 3157c478bd9Sstevel@tonic-gate for (i = 0; props[i].pp_pname != NULL; i++) { 3167c478bd9Sstevel@tonic-gate /* 3177c478bd9Sstevel@tonic-gate * Initialise each of the properties 3187c478bd9Sstevel@tonic-gate */ 3197c478bd9Sstevel@tonic-gate if (pool_value_set_name(&props[i].pp_value, 3207c478bd9Sstevel@tonic-gate props[i].pp_pname) != PO_SUCCESS) { 3217c478bd9Sstevel@tonic-gate return (PO_FAIL); 3227c478bd9Sstevel@tonic-gate } 3237c478bd9Sstevel@tonic-gate if (props[i].pp_init && 3247c478bd9Sstevel@tonic-gate props[i].pp_init(&props[i]) != PO_SUCCESS) { 3257c478bd9Sstevel@tonic-gate return (PO_FAIL); 3267c478bd9Sstevel@tonic-gate } 3277c478bd9Sstevel@tonic-gate } 3287c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 3297c478bd9Sstevel@tonic-gate } 3307c478bd9Sstevel@tonic-gate 3317c478bd9Sstevel@tonic-gate 3327c478bd9Sstevel@tonic-gate /* 3337c478bd9Sstevel@tonic-gate * These functions intialise the properties of this plugin. The only reason 3347c478bd9Sstevel@tonic-gate * they exist is because the ability to perform the static initialisation of 3357c478bd9Sstevel@tonic-gate * union members properly was only introduced in the C99 standard. i.e. if you 3367c478bd9Sstevel@tonic-gate * could do {.f = 1.0} like in the proposed C99 standard then that would 3377c478bd9Sstevel@tonic-gate * be the preferred way to do this as it keeps the data in the array and 3387c478bd9Sstevel@tonic-gate * minimises the scope for errors. However, until that time these functions 3397c478bd9Sstevel@tonic-gate * are the best way to minimise the scope for errors and to maximise 3407c478bd9Sstevel@tonic-gate * maintainability. 3417c478bd9Sstevel@tonic-gate * 3427c478bd9Sstevel@tonic-gate * There is one function for each property, and the initial value for each 3437c478bd9Sstevel@tonic-gate * property is hard-coded into each function. 3447c478bd9Sstevel@tonic-gate */ 3457c478bd9Sstevel@tonic-gate 3467c478bd9Sstevel@tonic-gate static int 3477c478bd9Sstevel@tonic-gate elem_name_init(pool_prop_t *prop) 3487c478bd9Sstevel@tonic-gate { 3497c478bd9Sstevel@tonic-gate return (string_init(prop, "default")); 3507c478bd9Sstevel@tonic-gate } 3517c478bd9Sstevel@tonic-gate 3527c478bd9Sstevel@tonic-gate static int 3537c478bd9Sstevel@tonic-gate elem_comment_init(pool_prop_t *prop) 3547c478bd9Sstevel@tonic-gate { 3557c478bd9Sstevel@tonic-gate return (string_init(prop, "")); 3567c478bd9Sstevel@tonic-gate } 3577c478bd9Sstevel@tonic-gate 3587c478bd9Sstevel@tonic-gate static int 3597c478bd9Sstevel@tonic-gate pool_importance_init(pool_prop_t *prop) 3607c478bd9Sstevel@tonic-gate { 3617c478bd9Sstevel@tonic-gate return (int_init(prop, 1)); 3627c478bd9Sstevel@tonic-gate } 3637c478bd9Sstevel@tonic-gate 3647c478bd9Sstevel@tonic-gate static int 3657c478bd9Sstevel@tonic-gate pool_active_init(pool_prop_t *prop) 3667c478bd9Sstevel@tonic-gate { 3677c478bd9Sstevel@tonic-gate return (bool_init(prop, PO_TRUE)); 3687c478bd9Sstevel@tonic-gate } 3697c478bd9Sstevel@tonic-gate 3707c478bd9Sstevel@tonic-gate static int 3717c478bd9Sstevel@tonic-gate res_max_init(pool_prop_t *prop) 3727c478bd9Sstevel@tonic-gate { 3737c478bd9Sstevel@tonic-gate return (uint_init(prop, 0)); 3747c478bd9Sstevel@tonic-gate } 3757c478bd9Sstevel@tonic-gate 3767c478bd9Sstevel@tonic-gate static int 3777c478bd9Sstevel@tonic-gate res_min_init(pool_prop_t *prop) 3787c478bd9Sstevel@tonic-gate { 3797c478bd9Sstevel@tonic-gate return (uint_init(prop, 0)); 3807c478bd9Sstevel@tonic-gate } 3817c478bd9Sstevel@tonic-gate 3827c478bd9Sstevel@tonic-gate static int 3837c478bd9Sstevel@tonic-gate res_size_init(pool_prop_t *prop) 3847c478bd9Sstevel@tonic-gate { 3857c478bd9Sstevel@tonic-gate return (uint_init(prop, 0)); 3867c478bd9Sstevel@tonic-gate } 3877c478bd9Sstevel@tonic-gate 3887c478bd9Sstevel@tonic-gate static int 3897c478bd9Sstevel@tonic-gate res_load_init(pool_prop_t *prop) 3907c478bd9Sstevel@tonic-gate { 3917c478bd9Sstevel@tonic-gate return (uint_init(prop, 0)); 3927c478bd9Sstevel@tonic-gate } 3937c478bd9Sstevel@tonic-gate 3947c478bd9Sstevel@tonic-gate static int 3957c478bd9Sstevel@tonic-gate pset_units_init(pool_prop_t *prop) 3967c478bd9Sstevel@tonic-gate { 3977c478bd9Sstevel@tonic-gate return (string_init(prop, "population")); 3987c478bd9Sstevel@tonic-gate } 3997c478bd9Sstevel@tonic-gate 4007c478bd9Sstevel@tonic-gate static int 4017c478bd9Sstevel@tonic-gate cpu_status_init(pool_prop_t *prop) 4027c478bd9Sstevel@tonic-gate { 4037c478bd9Sstevel@tonic-gate return (string_init(prop, PS_ONLINE)); 4047c478bd9Sstevel@tonic-gate } 4057c478bd9Sstevel@tonic-gate 4067c478bd9Sstevel@tonic-gate /* 4077c478bd9Sstevel@tonic-gate * Individual property manipulation routines for use by the generic 4087c478bd9Sstevel@tonic-gate * get/put property routines 4097c478bd9Sstevel@tonic-gate */ 4107c478bd9Sstevel@tonic-gate 4117c478bd9Sstevel@tonic-gate /* 4127c478bd9Sstevel@tonic-gate * Many properties cannot be modified. This function prevents property 4137c478bd9Sstevel@tonic-gate * modification. 4147c478bd9Sstevel@tonic-gate */ 4157c478bd9Sstevel@tonic-gate /* ARGSUSED */ 4167c478bd9Sstevel@tonic-gate static int 4177c478bd9Sstevel@tonic-gate elem_no_set(pool_elem_t *elem, const pool_value_t *pval) 4187c478bd9Sstevel@tonic-gate { 4197c478bd9Sstevel@tonic-gate return (PO_FAIL); 4207c478bd9Sstevel@tonic-gate } 4217c478bd9Sstevel@tonic-gate 4227c478bd9Sstevel@tonic-gate /* 4237c478bd9Sstevel@tonic-gate * Duplicate names for a pool or resource type are illegal. 4247c478bd9Sstevel@tonic-gate */ 4257c478bd9Sstevel@tonic-gate static int 4267c478bd9Sstevel@tonic-gate elem_set_name(pool_elem_t *elem, const pool_value_t *pval) 4277c478bd9Sstevel@tonic-gate { 4287c478bd9Sstevel@tonic-gate const char *nm; 4297c478bd9Sstevel@tonic-gate pool_t *pool; 4307c478bd9Sstevel@tonic-gate pool_resource_t *res; 4317c478bd9Sstevel@tonic-gate 4327c478bd9Sstevel@tonic-gate if (pool_value_get_string(pval, &nm) != PO_SUCCESS) { 4337c478bd9Sstevel@tonic-gate return (PO_FAIL); 4347c478bd9Sstevel@tonic-gate } 4357c478bd9Sstevel@tonic-gate if (!is_valid_name(nm)) { 4367c478bd9Sstevel@tonic-gate pool_seterror(POE_PUTPROP); 4377c478bd9Sstevel@tonic-gate return (PO_FAIL); 4387c478bd9Sstevel@tonic-gate } 4397c478bd9Sstevel@tonic-gate switch (pool_elem_class(elem)) { 4407c478bd9Sstevel@tonic-gate case PEC_SYSTEM: 4417c478bd9Sstevel@tonic-gate break; 4427c478bd9Sstevel@tonic-gate case PEC_POOL: 4437c478bd9Sstevel@tonic-gate pool = pool_get_pool(TO_CONF(elem), nm); 4447c478bd9Sstevel@tonic-gate if (pool != NULL && pool != pool_elem_pool(elem)) { 4457c478bd9Sstevel@tonic-gate pool_seterror(POE_PUTPROP); 4467c478bd9Sstevel@tonic-gate return (PO_FAIL); 4477c478bd9Sstevel@tonic-gate } 4487c478bd9Sstevel@tonic-gate break; 4497c478bd9Sstevel@tonic-gate case PEC_RES_COMP: 4507c478bd9Sstevel@tonic-gate case PEC_RES_AGG: 4517c478bd9Sstevel@tonic-gate res = pool_get_resource(TO_CONF(elem), 4527c478bd9Sstevel@tonic-gate pool_elem_class_string(elem), nm); 4537c478bd9Sstevel@tonic-gate if (res != NULL && res != pool_elem_res(elem)) { 4547c478bd9Sstevel@tonic-gate pool_seterror(POE_PUTPROP); 4557c478bd9Sstevel@tonic-gate return (PO_FAIL); 4567c478bd9Sstevel@tonic-gate } 4577c478bd9Sstevel@tonic-gate break; 4587c478bd9Sstevel@tonic-gate default: 4597c478bd9Sstevel@tonic-gate return (PO_FAIL); 4607c478bd9Sstevel@tonic-gate } 4617c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 4627c478bd9Sstevel@tonic-gate } 4637c478bd9Sstevel@tonic-gate 4647c478bd9Sstevel@tonic-gate /* 4657c478bd9Sstevel@tonic-gate * Ensure the type is a string. 4667c478bd9Sstevel@tonic-gate */ 4677c478bd9Sstevel@tonic-gate /* ARGSUSED */ 4687c478bd9Sstevel@tonic-gate static int 4697c478bd9Sstevel@tonic-gate elem_set_string(pool_elem_t *elem, const pool_value_t *pval) 4707c478bd9Sstevel@tonic-gate { 4717c478bd9Sstevel@tonic-gate if (pool_value_get_type(pval) == POC_STRING) 4727c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 4737c478bd9Sstevel@tonic-gate else { 4747c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 4757c478bd9Sstevel@tonic-gate return (PO_FAIL); 4767c478bd9Sstevel@tonic-gate } 4777c478bd9Sstevel@tonic-gate } 4787c478bd9Sstevel@tonic-gate 4797c478bd9Sstevel@tonic-gate /* 4807c478bd9Sstevel@tonic-gate * Ensure the type is a boolean. 4817c478bd9Sstevel@tonic-gate */ 4827c478bd9Sstevel@tonic-gate /* ARGSUSED */ 4837c478bd9Sstevel@tonic-gate static int 4847c478bd9Sstevel@tonic-gate elem_set_bool(pool_elem_t *elem, const pool_value_t *pval) 4857c478bd9Sstevel@tonic-gate { 4867c478bd9Sstevel@tonic-gate if (pool_value_get_type(pval) == POC_BOOL) 4877c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 4887c478bd9Sstevel@tonic-gate else { 4897c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 4907c478bd9Sstevel@tonic-gate return (PO_FAIL); 4917c478bd9Sstevel@tonic-gate } 4927c478bd9Sstevel@tonic-gate } 4937c478bd9Sstevel@tonic-gate 4947c478bd9Sstevel@tonic-gate /* 4957c478bd9Sstevel@tonic-gate * Ensure the type is an unsigned int. 4967c478bd9Sstevel@tonic-gate */ 4977c478bd9Sstevel@tonic-gate /* ARGSUSED */ 4987c478bd9Sstevel@tonic-gate static int 4997c478bd9Sstevel@tonic-gate elem_set_uint(pool_elem_t *elem, const pool_value_t *pval) 5007c478bd9Sstevel@tonic-gate { 5017c478bd9Sstevel@tonic-gate if (pool_value_get_type(pval) == POC_UINT) 5027c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 5037c478bd9Sstevel@tonic-gate else { 5047c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 5057c478bd9Sstevel@tonic-gate return (PO_FAIL); 5067c478bd9Sstevel@tonic-gate } 5077c478bd9Sstevel@tonic-gate } 5087c478bd9Sstevel@tonic-gate 5097c478bd9Sstevel@tonic-gate /* ARGSUSED */ 5107c478bd9Sstevel@tonic-gate int 5117c478bd9Sstevel@tonic-gate system_set_allocate(pool_elem_t *elem, const pool_value_t *pval) 5127c478bd9Sstevel@tonic-gate { 5137c478bd9Sstevel@tonic-gate const char *sval; 5147c478bd9Sstevel@tonic-gate 5157c478bd9Sstevel@tonic-gate if (pool_value_get_string(pval, &sval) != PO_SUCCESS) { 5167c478bd9Sstevel@tonic-gate pool_seterror(POE_PUTPROP); 5177c478bd9Sstevel@tonic-gate return (PO_FAIL); 5187c478bd9Sstevel@tonic-gate } 5197c478bd9Sstevel@tonic-gate if (strcmp(POA_IMPORTANCE, sval) != 0 && 5207c478bd9Sstevel@tonic-gate strcmp(POA_SURPLUS_TO_DEFAULT, sval) != 0) { 5217c478bd9Sstevel@tonic-gate pool_seterror(POE_PUTPROP); 5227c478bd9Sstevel@tonic-gate return (PO_FAIL); 5237c478bd9Sstevel@tonic-gate } 5247c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 5257c478bd9Sstevel@tonic-gate } 5267c478bd9Sstevel@tonic-gate 5277c478bd9Sstevel@tonic-gate /* ARGSUSED */ 5287c478bd9Sstevel@tonic-gate int 5297c478bd9Sstevel@tonic-gate pool_set_active(pool_elem_t *elem, const pool_value_t *pval) 5307c478bd9Sstevel@tonic-gate { 5317c478bd9Sstevel@tonic-gate uchar_t bval; 5327c478bd9Sstevel@tonic-gate 5337c478bd9Sstevel@tonic-gate if (pool_value_get_type(pval) != POC_BOOL) { 5347c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 5357c478bd9Sstevel@tonic-gate return (PO_FAIL); 5367c478bd9Sstevel@tonic-gate } 5377c478bd9Sstevel@tonic-gate (void) pool_value_get_bool(pval, &bval); 5387c478bd9Sstevel@tonic-gate if (bval != 1) { 5397c478bd9Sstevel@tonic-gate /* 5407c478bd9Sstevel@tonic-gate * "active" must be true on pools for 5417c478bd9Sstevel@tonic-gate * now. 5427c478bd9Sstevel@tonic-gate */ 5437c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 5447c478bd9Sstevel@tonic-gate return (PO_FAIL); 5457c478bd9Sstevel@tonic-gate } 5467c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 5477c478bd9Sstevel@tonic-gate } 5487c478bd9Sstevel@tonic-gate 5497c478bd9Sstevel@tonic-gate /* ARGSUSED */ 5507c478bd9Sstevel@tonic-gate int 5517c478bd9Sstevel@tonic-gate pool_set_scheduler(pool_elem_t *elem, const pool_value_t *pval) 5527c478bd9Sstevel@tonic-gate { 5537c478bd9Sstevel@tonic-gate pcinfo_t pcinfo; 5547c478bd9Sstevel@tonic-gate const char *sched; 5557c478bd9Sstevel@tonic-gate 5567c478bd9Sstevel@tonic-gate if (pool_value_get_string(pval, &sched) != 0) { 5577c478bd9Sstevel@tonic-gate pool_seterror(POE_PUTPROP); 5587c478bd9Sstevel@tonic-gate return (PO_FAIL); 5597c478bd9Sstevel@tonic-gate } 5607c478bd9Sstevel@tonic-gate (void) strncpy(pcinfo.pc_clname, sched, PC_CLNMSZ); 5617c478bd9Sstevel@tonic-gate if (priocntl(0, 0, PC_GETCID, &pcinfo) == -1) { 5627c478bd9Sstevel@tonic-gate pool_seterror(POE_PUTPROP); 5637c478bd9Sstevel@tonic-gate return (PO_FAIL); 5647c478bd9Sstevel@tonic-gate } 5657c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 5667c478bd9Sstevel@tonic-gate } 5677c478bd9Sstevel@tonic-gate 5687c478bd9Sstevel@tonic-gate static int 5697c478bd9Sstevel@tonic-gate res_set_max(pool_elem_t *elem, const pool_value_t *pval) 5707c478bd9Sstevel@tonic-gate { 5717c478bd9Sstevel@tonic-gate uint64_t min, max; 5727c478bd9Sstevel@tonic-gate pool_value_t val = POOL_VALUE_INITIALIZER; 5737c478bd9Sstevel@tonic-gate 5747c478bd9Sstevel@tonic-gate /* 5757c478bd9Sstevel@tonic-gate * max must be a uint 5767c478bd9Sstevel@tonic-gate */ 5777c478bd9Sstevel@tonic-gate if (pool_value_get_uint64(pval, &max) != PO_SUCCESS) { 5787c478bd9Sstevel@tonic-gate pool_seterror(POE_PUTPROP); 5797c478bd9Sstevel@tonic-gate return (PO_FAIL); 5807c478bd9Sstevel@tonic-gate } 5817c478bd9Sstevel@tonic-gate /* 5827c478bd9Sstevel@tonic-gate * max can't be less than min (if it exists) 5837c478bd9Sstevel@tonic-gate */ 5847c478bd9Sstevel@tonic-gate if (pool_get_ns_property(elem, c_min_prop, &val) == POC_INVAL) 5857c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 5867c478bd9Sstevel@tonic-gate if (pool_value_get_uint64(&val, &min) != PO_SUCCESS) { 5877c478bd9Sstevel@tonic-gate pool_seterror(POE_PUTPROP); 5887c478bd9Sstevel@tonic-gate return (PO_FAIL); 5897c478bd9Sstevel@tonic-gate } 5907c478bd9Sstevel@tonic-gate if (max < min) { 5917c478bd9Sstevel@tonic-gate pool_seterror(POE_PUTPROP); 5927c478bd9Sstevel@tonic-gate return (PO_FAIL); 5937c478bd9Sstevel@tonic-gate } 5947c478bd9Sstevel@tonic-gate /* 5957c478bd9Sstevel@tonic-gate * Ensure that changes to the max in a dynamic configuration 5967c478bd9Sstevel@tonic-gate * are still valid. 5977c478bd9Sstevel@tonic-gate */ 5987c478bd9Sstevel@tonic-gate if (conf_is_dynamic(TO_CONF(elem)) == PO_TRUE) { 5997c478bd9Sstevel@tonic-gate uint64_t oldmax; 6007c478bd9Sstevel@tonic-gate 6017c478bd9Sstevel@tonic-gate if (pool_get_ns_property(elem, c_max_prop, &val) == POC_INVAL) { 6027c478bd9Sstevel@tonic-gate pool_seterror(POE_PUTPROP); 6037c478bd9Sstevel@tonic-gate return (PO_FAIL); 6047c478bd9Sstevel@tonic-gate } 6057c478bd9Sstevel@tonic-gate if (pool_value_get_uint64(&val, &oldmax) != PO_SUCCESS) { 6067c478bd9Sstevel@tonic-gate pool_seterror(POE_PUTPROP); 6077c478bd9Sstevel@tonic-gate return (PO_FAIL); 6087c478bd9Sstevel@tonic-gate } 6097c478bd9Sstevel@tonic-gate if (max < oldmax) { 6107c478bd9Sstevel@tonic-gate /* 6117c478bd9Sstevel@tonic-gate * Ensure that the modified total max is >= size 6127c478bd9Sstevel@tonic-gate * of all resources of this type 6137c478bd9Sstevel@tonic-gate */ 6147c478bd9Sstevel@tonic-gate return (pool_validate_resource(TO_CONF(elem), 6157c478bd9Sstevel@tonic-gate pool_elem_class_string(elem), c_max_prop, 6167c478bd9Sstevel@tonic-gate max - oldmax)); 6177c478bd9Sstevel@tonic-gate } 6187c478bd9Sstevel@tonic-gate } 6197c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 6207c478bd9Sstevel@tonic-gate } 6217c478bd9Sstevel@tonic-gate 6227c478bd9Sstevel@tonic-gate static int 6237c478bd9Sstevel@tonic-gate res_set_min(pool_elem_t *elem, const pool_value_t *pval) 6247c478bd9Sstevel@tonic-gate { 6257c478bd9Sstevel@tonic-gate uint64_t min, max; 6267c478bd9Sstevel@tonic-gate pool_value_t val = POOL_VALUE_INITIALIZER; 6277c478bd9Sstevel@tonic-gate 6287c478bd9Sstevel@tonic-gate /* 6297c478bd9Sstevel@tonic-gate * min must be a uint 6307c478bd9Sstevel@tonic-gate */ 6317c478bd9Sstevel@tonic-gate if (pool_value_get_uint64(pval, &min) != PO_SUCCESS) { 6327c478bd9Sstevel@tonic-gate pool_seterror(POE_PUTPROP); 6337c478bd9Sstevel@tonic-gate return (PO_FAIL); 6347c478bd9Sstevel@tonic-gate } 6357c478bd9Sstevel@tonic-gate /* 6367c478bd9Sstevel@tonic-gate * min can't be more than max (if it exists) 6377c478bd9Sstevel@tonic-gate */ 6387c478bd9Sstevel@tonic-gate if (pool_get_ns_property(elem, c_max_prop, &val) == POC_INVAL) 6397c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 6407c478bd9Sstevel@tonic-gate if (pool_value_get_uint64(&val, &max) != PO_SUCCESS) { 6417c478bd9Sstevel@tonic-gate pool_seterror(POE_PUTPROP); 6427c478bd9Sstevel@tonic-gate return (PO_FAIL); 6437c478bd9Sstevel@tonic-gate } 6447c478bd9Sstevel@tonic-gate if (min > max) { 6457c478bd9Sstevel@tonic-gate pool_seterror(POE_PUTPROP); 6467c478bd9Sstevel@tonic-gate return (PO_FAIL); 6477c478bd9Sstevel@tonic-gate } 6487c478bd9Sstevel@tonic-gate 6497c478bd9Sstevel@tonic-gate switch (pool_resource_elem_class(elem)) { 6507c478bd9Sstevel@tonic-gate case PREC_PSET: 6517c478bd9Sstevel@tonic-gate if (resource_is_default(pool_elem_res(elem))) { 6527c478bd9Sstevel@tonic-gate if (min < 1) { 6537c478bd9Sstevel@tonic-gate pool_seterror(POE_PUTPROP); 6547c478bd9Sstevel@tonic-gate return (PO_FAIL); 6557c478bd9Sstevel@tonic-gate } 6567c478bd9Sstevel@tonic-gate } 6577c478bd9Sstevel@tonic-gate break; 6587c478bd9Sstevel@tonic-gate default: 6597c478bd9Sstevel@tonic-gate break; 6607c478bd9Sstevel@tonic-gate } 6617c478bd9Sstevel@tonic-gate 6627c478bd9Sstevel@tonic-gate /* 6637c478bd9Sstevel@tonic-gate * Ensure that changes to the min in a dynamic configuration 6647c478bd9Sstevel@tonic-gate * are still valid. 6657c478bd9Sstevel@tonic-gate */ 6667c478bd9Sstevel@tonic-gate if (conf_is_dynamic(TO_CONF(elem)) == PO_TRUE) { 6677c478bd9Sstevel@tonic-gate uint64_t oldmin; 6687c478bd9Sstevel@tonic-gate 6697c478bd9Sstevel@tonic-gate if (pool_get_ns_property(elem, c_min_prop, &val) == POC_INVAL) { 6707c478bd9Sstevel@tonic-gate pool_seterror(POE_PUTPROP); 6717c478bd9Sstevel@tonic-gate return (PO_FAIL); 6727c478bd9Sstevel@tonic-gate } 6737c478bd9Sstevel@tonic-gate if (pool_value_get_uint64(&val, &oldmin) != PO_SUCCESS) { 6747c478bd9Sstevel@tonic-gate pool_seterror(POE_PUTPROP); 6757c478bd9Sstevel@tonic-gate return (PO_FAIL); 6767c478bd9Sstevel@tonic-gate } 6777c478bd9Sstevel@tonic-gate if (min > oldmin) { 6787c478bd9Sstevel@tonic-gate /* 6797c478bd9Sstevel@tonic-gate * Ensure that the modified total min is <= size 6807c478bd9Sstevel@tonic-gate * of all resources of this type 6817c478bd9Sstevel@tonic-gate */ 6827c478bd9Sstevel@tonic-gate return (pool_validate_resource(TO_CONF(elem), 6837c478bd9Sstevel@tonic-gate pool_elem_class_string(elem), c_min_prop, 6847c478bd9Sstevel@tonic-gate min - oldmin)); 6857c478bd9Sstevel@tonic-gate } 6867c478bd9Sstevel@tonic-gate } 6877c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 6887c478bd9Sstevel@tonic-gate } 6897c478bd9Sstevel@tonic-gate 6907c478bd9Sstevel@tonic-gate /* ARGSUSED */ 6917c478bd9Sstevel@tonic-gate int 6927c478bd9Sstevel@tonic-gate cpu_set_status(pool_elem_t *elem, const pool_value_t *pval) 6937c478bd9Sstevel@tonic-gate { 6947c478bd9Sstevel@tonic-gate const char *status; 6957c478bd9Sstevel@tonic-gate 6967c478bd9Sstevel@tonic-gate if (pool_value_get_string(pval, &status) != 0) { 6977c478bd9Sstevel@tonic-gate pool_seterror(POE_PUTPROP); 6987c478bd9Sstevel@tonic-gate return (PO_FAIL); 6997c478bd9Sstevel@tonic-gate } 7007c478bd9Sstevel@tonic-gate 7017c478bd9Sstevel@tonic-gate if (strcmp(PS_ONLINE, status) != 0 && 7027c478bd9Sstevel@tonic-gate strcmp(PS_OFFLINE, status) != 0 && 7037c478bd9Sstevel@tonic-gate strcmp(PS_NOINTR, status) != 0 && 7047c478bd9Sstevel@tonic-gate strcmp(PS_SPARE, status) != 0 && 7057c478bd9Sstevel@tonic-gate strcmp(PS_FAULTED, status) != 0) { 7067c478bd9Sstevel@tonic-gate pool_seterror(POE_PUTPROP); 7077c478bd9Sstevel@tonic-gate return (PO_FAIL); 7087c478bd9Sstevel@tonic-gate } 7097c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 7107c478bd9Sstevel@tonic-gate } 7117c478bd9Sstevel@tonic-gate 7127c478bd9Sstevel@tonic-gate static int 7137c478bd9Sstevel@tonic-gate elem_get_type(const pool_elem_t *elem, pool_value_t *pval) 7147c478bd9Sstevel@tonic-gate { 7157c478bd9Sstevel@tonic-gate if (pool_value_set_string(pval, pool_elem_class_string(elem)) == 7167c478bd9Sstevel@tonic-gate PO_FAIL) 7177c478bd9Sstevel@tonic-gate return (PO_FAIL); 7187c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 7197c478bd9Sstevel@tonic-gate } 7207c478bd9Sstevel@tonic-gate 7217c478bd9Sstevel@tonic-gate /* 7227c478bd9Sstevel@tonic-gate * More general utilities 7237c478bd9Sstevel@tonic-gate */ 7247c478bd9Sstevel@tonic-gate /* 7257c478bd9Sstevel@tonic-gate * Is the supplied configuration the dynamic configuration 7267c478bd9Sstevel@tonic-gate * Return: PO_TRUE/PO_FALSE 7277c478bd9Sstevel@tonic-gate */ 7287c478bd9Sstevel@tonic-gate int 7297c478bd9Sstevel@tonic-gate conf_is_dynamic(const pool_conf_t *conf) 7307c478bd9Sstevel@tonic-gate { 7317c478bd9Sstevel@tonic-gate if (strcmp(pool_conf_location(conf), pool_dynamic_location()) == 0) 7327c478bd9Sstevel@tonic-gate return (PO_TRUE); 7337c478bd9Sstevel@tonic-gate return (PO_FALSE); 7347c478bd9Sstevel@tonic-gate } 7357c478bd9Sstevel@tonic-gate 7367c478bd9Sstevel@tonic-gate /* 7377c478bd9Sstevel@tonic-gate * uint_init() initialises the value of the supplied property with the 7387c478bd9Sstevel@tonic-gate * supplied value. 7397c478bd9Sstevel@tonic-gate * Returns PO_SUCCESS 7407c478bd9Sstevel@tonic-gate */ 7417c478bd9Sstevel@tonic-gate int 7427c478bd9Sstevel@tonic-gate uint_init(pool_prop_t *prop, uint64_t val) 7437c478bd9Sstevel@tonic-gate { 7447c478bd9Sstevel@tonic-gate pool_value_set_uint64(&prop->pp_value, val); 7457c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 7467c478bd9Sstevel@tonic-gate } 7477c478bd9Sstevel@tonic-gate 7487c478bd9Sstevel@tonic-gate /* 7497c478bd9Sstevel@tonic-gate * int_init() initialises the value of the supplied property with the 7507c478bd9Sstevel@tonic-gate * supplied value. 7517c478bd9Sstevel@tonic-gate * Returns PO_SUCCESS 7527c478bd9Sstevel@tonic-gate */ 7537c478bd9Sstevel@tonic-gate int 7547c478bd9Sstevel@tonic-gate int_init(pool_prop_t *prop, int64_t val) 7557c478bd9Sstevel@tonic-gate { 7567c478bd9Sstevel@tonic-gate pool_value_set_int64(&prop->pp_value, val); 7577c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 7587c478bd9Sstevel@tonic-gate } 7597c478bd9Sstevel@tonic-gate 7607c478bd9Sstevel@tonic-gate /* 7617c478bd9Sstevel@tonic-gate * double_init() initialises the value of the supplied property with the 7627c478bd9Sstevel@tonic-gate * supplied value. 7637c478bd9Sstevel@tonic-gate * Returns PO_SUCCESS 7647c478bd9Sstevel@tonic-gate */ 7657c478bd9Sstevel@tonic-gate int 7667c478bd9Sstevel@tonic-gate double_init(pool_prop_t *prop, double val) 7677c478bd9Sstevel@tonic-gate { 7687c478bd9Sstevel@tonic-gate pool_value_set_double(&prop->pp_value, val); 7697c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 7707c478bd9Sstevel@tonic-gate } 7717c478bd9Sstevel@tonic-gate 7727c478bd9Sstevel@tonic-gate /* 7737c478bd9Sstevel@tonic-gate * bool_init() initialises the value of the supplied property with the 7747c478bd9Sstevel@tonic-gate * supplied value. 7757c478bd9Sstevel@tonic-gate * Returns PO_SUCCESS 7767c478bd9Sstevel@tonic-gate */ 7777c478bd9Sstevel@tonic-gate int 7787c478bd9Sstevel@tonic-gate bool_init(pool_prop_t *prop, uchar_t val) 7797c478bd9Sstevel@tonic-gate { 7807c478bd9Sstevel@tonic-gate pool_value_set_bool(&prop->pp_value, val); 7817c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 7827c478bd9Sstevel@tonic-gate } 7837c478bd9Sstevel@tonic-gate 7847c478bd9Sstevel@tonic-gate /* 7857c478bd9Sstevel@tonic-gate * string_init() initialises the value of the supplied property with the 7867c478bd9Sstevel@tonic-gate * supplied value. 7877c478bd9Sstevel@tonic-gate * Returns PO_SUCCESS/PO_FAIL 7887c478bd9Sstevel@tonic-gate */ 7897c478bd9Sstevel@tonic-gate int 7907c478bd9Sstevel@tonic-gate string_init(pool_prop_t *prop, const char *val) 7917c478bd9Sstevel@tonic-gate { 7927c478bd9Sstevel@tonic-gate return (pool_value_set_string(&prop->pp_value, val)); 7937c478bd9Sstevel@tonic-gate } 7947c478bd9Sstevel@tonic-gate 7957c478bd9Sstevel@tonic-gate /* 7967c478bd9Sstevel@tonic-gate * pool_get_provider_count() returns the count of registered providers. 7977c478bd9Sstevel@tonic-gate * 7987c478bd9Sstevel@tonic-gate * Returns count of registered providers 7997c478bd9Sstevel@tonic-gate */ 8007c478bd9Sstevel@tonic-gate uint_t 8017c478bd9Sstevel@tonic-gate pool_get_provider_count(void) 8027c478bd9Sstevel@tonic-gate { 8037c478bd9Sstevel@tonic-gate uint_t count = 0; 8047c478bd9Sstevel@tonic-gate int i; 8057c478bd9Sstevel@tonic-gate 8067c478bd9Sstevel@tonic-gate for (i = 0; i < sizeof (pool_resource_elem_ctl) / 8077c478bd9Sstevel@tonic-gate sizeof (pool_resource_elem_ctl[0]); i++) { 8087c478bd9Sstevel@tonic-gate if (pool_resource_elem_ctl[i] != NULL) 8097c478bd9Sstevel@tonic-gate count++; 8107c478bd9Sstevel@tonic-gate } 8117c478bd9Sstevel@tonic-gate return (count); 8127c478bd9Sstevel@tonic-gate } 8137c478bd9Sstevel@tonic-gate 8147c478bd9Sstevel@tonic-gate /* 8157c478bd9Sstevel@tonic-gate * Return all the props for a specified provider 8167c478bd9Sstevel@tonic-gate */ 8177c478bd9Sstevel@tonic-gate const pool_prop_t * 8187c478bd9Sstevel@tonic-gate provider_get_props(const pool_elem_t *elem) 8197c478bd9Sstevel@tonic-gate { 8207c478bd9Sstevel@tonic-gate const pool_prop_t *prop_list = NULL; 8217c478bd9Sstevel@tonic-gate pool_elem_class_t elem_class = pool_elem_class(elem); 8227c478bd9Sstevel@tonic-gate 8237c478bd9Sstevel@tonic-gate switch (elem_class) { 8247c478bd9Sstevel@tonic-gate case PEC_SYSTEM: 8257c478bd9Sstevel@tonic-gate case PEC_POOL: 8267c478bd9Sstevel@tonic-gate prop_list = pool_elem_ctl[elem_class]; 8277c478bd9Sstevel@tonic-gate break; 8287c478bd9Sstevel@tonic-gate case PEC_RES_AGG: 8297c478bd9Sstevel@tonic-gate case PEC_RES_COMP: 8307c478bd9Sstevel@tonic-gate prop_list = pool_resource_elem_ctl 8317c478bd9Sstevel@tonic-gate [pool_resource_elem_class(elem)]; 8327c478bd9Sstevel@tonic-gate break; 8337c478bd9Sstevel@tonic-gate case PEC_COMP: 8347c478bd9Sstevel@tonic-gate prop_list = pool_component_elem_ctl 8357c478bd9Sstevel@tonic-gate [pool_component_elem_class(elem)]; 8367c478bd9Sstevel@tonic-gate break; 8377c478bd9Sstevel@tonic-gate } 8387c478bd9Sstevel@tonic-gate return (prop_list); 8397c478bd9Sstevel@tonic-gate } 8407c478bd9Sstevel@tonic-gate 8417c478bd9Sstevel@tonic-gate /* 8427c478bd9Sstevel@tonic-gate * provider_get_prop() return the pool_prop_t structure which 8437c478bd9Sstevel@tonic-gate * describes the supplied property name for the supplied provider. 8447c478bd9Sstevel@tonic-gate * 8457c478bd9Sstevel@tonic-gate * Returns the property description or NULL if it doesn't exist. 8467c478bd9Sstevel@tonic-gate */ 8477c478bd9Sstevel@tonic-gate const pool_prop_t * 8487c478bd9Sstevel@tonic-gate provider_get_prop(const pool_elem_t *elem, const char *name) 8497c478bd9Sstevel@tonic-gate { 8507c478bd9Sstevel@tonic-gate int i; 8517c478bd9Sstevel@tonic-gate const pool_prop_t *prop_list; 8527c478bd9Sstevel@tonic-gate 8537c478bd9Sstevel@tonic-gate if ((prop_list = provider_get_props(elem)) == NULL) 8547c478bd9Sstevel@tonic-gate return (NULL); 8557c478bd9Sstevel@tonic-gate 8567c478bd9Sstevel@tonic-gate for (i = 0; prop_list[i].pp_pname != NULL; i++) { 8577c478bd9Sstevel@tonic-gate if (strcmp(name, prop_list[i].pp_pname) == 0) { 8587c478bd9Sstevel@tonic-gate return (&prop_list[i]); 8597c478bd9Sstevel@tonic-gate } 8607c478bd9Sstevel@tonic-gate } 8617c478bd9Sstevel@tonic-gate return (NULL); 8627c478bd9Sstevel@tonic-gate } 8637c478bd9Sstevel@tonic-gate 8647c478bd9Sstevel@tonic-gate /* 8657c478bd9Sstevel@tonic-gate * prop_is_type() checks the supplied property and returns PO_TRUE if the 8667c478bd9Sstevel@tonic-gate * property value is 1 else PO_FALSE 8677c478bd9Sstevel@tonic-gate */ 8687c478bd9Sstevel@tonic-gate static int 8697c478bd9Sstevel@tonic-gate prop_is_type(int prop_type, const pool_prop_t *prop) 8707c478bd9Sstevel@tonic-gate { 8717c478bd9Sstevel@tonic-gate return ((prop->pp_perms & prop_type) ? PO_TRUE : PO_FALSE); 8727c478bd9Sstevel@tonic-gate } 8737c478bd9Sstevel@tonic-gate 8747c478bd9Sstevel@tonic-gate /* 8757c478bd9Sstevel@tonic-gate * prop_is_stored() returns PO_TRUE if the property is stored in the backing 8767c478bd9Sstevel@tonic-gate * configuration and PO_FALSE else. 8777c478bd9Sstevel@tonic-gate */ 8787c478bd9Sstevel@tonic-gate int 8797c478bd9Sstevel@tonic-gate prop_is_stored(const pool_prop_t *prop) 8807c478bd9Sstevel@tonic-gate { 8817c478bd9Sstevel@tonic-gate return (prop_is_type(PP_STORED, prop)); 8827c478bd9Sstevel@tonic-gate } 8837c478bd9Sstevel@tonic-gate 8847c478bd9Sstevel@tonic-gate /* 8857c478bd9Sstevel@tonic-gate * prop_is_readonly() returns PO_TRUE if the property is a read-only property 8867c478bd9Sstevel@tonic-gate * and PO_FALSE else. 8877c478bd9Sstevel@tonic-gate */ 8887c478bd9Sstevel@tonic-gate int 8897c478bd9Sstevel@tonic-gate prop_is_readonly(const pool_prop_t *prop) 8907c478bd9Sstevel@tonic-gate { 8917c478bd9Sstevel@tonic-gate return (prop_is_type(PP_READ, prop)); 8927c478bd9Sstevel@tonic-gate } 8937c478bd9Sstevel@tonic-gate 8947c478bd9Sstevel@tonic-gate /* 8957c478bd9Sstevel@tonic-gate * prop_is_init() returns PO_TRUE if the property should be 8967c478bd9Sstevel@tonic-gate * initialised when an element of this type is created and PO_FALSE 8977c478bd9Sstevel@tonic-gate * else. 8987c478bd9Sstevel@tonic-gate */ 8997c478bd9Sstevel@tonic-gate int 9007c478bd9Sstevel@tonic-gate prop_is_init(const pool_prop_t *prop) 9017c478bd9Sstevel@tonic-gate { 9027c478bd9Sstevel@tonic-gate return (prop_is_type(PP_INIT, prop)); 9037c478bd9Sstevel@tonic-gate } 9047c478bd9Sstevel@tonic-gate 9057c478bd9Sstevel@tonic-gate /* 9067c478bd9Sstevel@tonic-gate * prop_is_hidden() returns PO_TRUE if the property should be hidden 9077c478bd9Sstevel@tonic-gate * from access by the external property access mechanisms. 9087c478bd9Sstevel@tonic-gate */ 9097c478bd9Sstevel@tonic-gate int 9107c478bd9Sstevel@tonic-gate prop_is_hidden(const pool_prop_t *prop) 9117c478bd9Sstevel@tonic-gate { 9127c478bd9Sstevel@tonic-gate return (prop_is_type(PP_HIDDEN, prop)); 9137c478bd9Sstevel@tonic-gate } 9147c478bd9Sstevel@tonic-gate 9157c478bd9Sstevel@tonic-gate /* 9167c478bd9Sstevel@tonic-gate * prop_is_optional() returns PO_TRUE if the property is optional and 9177c478bd9Sstevel@tonic-gate * can be removed by external property access mechanisms. 9187c478bd9Sstevel@tonic-gate */ 9197c478bd9Sstevel@tonic-gate int 9207c478bd9Sstevel@tonic-gate prop_is_optional(const pool_prop_t *prop) 9217c478bd9Sstevel@tonic-gate { 9227c478bd9Sstevel@tonic-gate return (prop_is_type(PP_OPTIONAL, prop)); 9237c478bd9Sstevel@tonic-gate } 9247c478bd9Sstevel@tonic-gate 9257c478bd9Sstevel@tonic-gate int 9267c478bd9Sstevel@tonic-gate cpu_is_requested(pool_component_t *component) 9277c478bd9Sstevel@tonic-gate { 9287c478bd9Sstevel@tonic-gate pool_value_t val = POOL_VALUE_INITIALIZER; 9297c478bd9Sstevel@tonic-gate uchar_t requested; 9307c478bd9Sstevel@tonic-gate 9317c478bd9Sstevel@tonic-gate if (pool_get_property(TO_CONF(TO_ELEM(component)), TO_ELEM(component), 9327c478bd9Sstevel@tonic-gate "cpu.requested", &val) != POC_BOOL) { 9337c478bd9Sstevel@tonic-gate return (PO_FALSE); 9347c478bd9Sstevel@tonic-gate } 9357c478bd9Sstevel@tonic-gate if (pool_value_get_bool(&val, &requested) != PO_SUCCESS) { 9367c478bd9Sstevel@tonic-gate return (PO_FALSE); 9377c478bd9Sstevel@tonic-gate } 9387c478bd9Sstevel@tonic-gate return ((int)requested); 9397c478bd9Sstevel@tonic-gate } 9407c478bd9Sstevel@tonic-gate 9417c478bd9Sstevel@tonic-gate /* 9427c478bd9Sstevel@tonic-gate * Common code for various resource get functions 9437c478bd9Sstevel@tonic-gate */ 9447c478bd9Sstevel@tonic-gate static int 9457c478bd9Sstevel@tonic-gate resource_get_common(const pool_resource_t *res, const char *name, 9467c478bd9Sstevel@tonic-gate uint64_t *uval) 9477c478bd9Sstevel@tonic-gate { 9487c478bd9Sstevel@tonic-gate pool_value_t val = POOL_VALUE_INITIALIZER; 9497c478bd9Sstevel@tonic-gate pool_value_class_t pvc; 9507c478bd9Sstevel@tonic-gate int retval = PO_SUCCESS; 9517c478bd9Sstevel@tonic-gate 9527c478bd9Sstevel@tonic-gate pvc = pool_get_ns_property(TO_ELEM(res), name, &val); 9537c478bd9Sstevel@tonic-gate if (pvc == POC_INVAL) { 9547c478bd9Sstevel@tonic-gate *uval = 0; 9557c478bd9Sstevel@tonic-gate #ifdef DEBUG 9567c478bd9Sstevel@tonic-gate dprintf("can't retrieve %s\n"); 9577c478bd9Sstevel@tonic-gate pool_elem_dprintf(TO_ELEM(res)); 9587c478bd9Sstevel@tonic-gate #endif /* DEBUG */ 9597c478bd9Sstevel@tonic-gate } else if (pvc == POC_UINT) { 9607c478bd9Sstevel@tonic-gate retval = pool_value_get_uint64(&val, uval); 9617c478bd9Sstevel@tonic-gate } 9627c478bd9Sstevel@tonic-gate return (retval); 9637c478bd9Sstevel@tonic-gate } 9647c478bd9Sstevel@tonic-gate 9657c478bd9Sstevel@tonic-gate /* 9667c478bd9Sstevel@tonic-gate * resource_get_size() updates size with the size of the supplied resource. 9677c478bd9Sstevel@tonic-gate * 9687c478bd9Sstevel@tonic-gate * Returns PO_SUCCESS/PO_FAIL 9697c478bd9Sstevel@tonic-gate */ 9707c478bd9Sstevel@tonic-gate int 9717c478bd9Sstevel@tonic-gate resource_get_size(const pool_resource_t *res, uint64_t *size) 9727c478bd9Sstevel@tonic-gate { 9737c478bd9Sstevel@tonic-gate return (resource_get_common(res, c_size_prop, size)); 9747c478bd9Sstevel@tonic-gate } 9757c478bd9Sstevel@tonic-gate 9767c478bd9Sstevel@tonic-gate /* 9777c478bd9Sstevel@tonic-gate * resource_get_pinned() updates pinned with the size of the 9787c478bd9Sstevel@tonic-gate * pinned part of a supplied resource. Resource is not available for 9797c478bd9Sstevel@tonic-gate * allocation if it is marked as "pinned". 9807c478bd9Sstevel@tonic-gate * 9817c478bd9Sstevel@tonic-gate * Returns PO_SUCCESS/PO_FAIL 9827c478bd9Sstevel@tonic-gate */ 9837c478bd9Sstevel@tonic-gate int 9847c478bd9Sstevel@tonic-gate resource_get_pinned(const pool_resource_t *res, uint64_t *pinned) 9857c478bd9Sstevel@tonic-gate { 9867c478bd9Sstevel@tonic-gate pool_value_t *props[] = { NULL, NULL }; 9877c478bd9Sstevel@tonic-gate pool_value_t val = POOL_VALUE_INITIALIZER; 9887c478bd9Sstevel@tonic-gate pool_component_t **cs = NULL; 9897c478bd9Sstevel@tonic-gate uint_t ncompelem; 9907c478bd9Sstevel@tonic-gate 9917c478bd9Sstevel@tonic-gate props[0] = &val; 9927c478bd9Sstevel@tonic-gate 9937c478bd9Sstevel@tonic-gate pool_value_set_bool(props[0], PO_TRUE); 9947c478bd9Sstevel@tonic-gate if (pool_value_set_name(props[0], "cpu.pinned") != PO_SUCCESS) 9957c478bd9Sstevel@tonic-gate return (PO_FAIL); 9967c478bd9Sstevel@tonic-gate 9977c478bd9Sstevel@tonic-gate if ((cs = pool_query_resource_components(TO_CONF(TO_ELEM(res)), res, 9987c478bd9Sstevel@tonic-gate &ncompelem, props)) != NULL) { 9997c478bd9Sstevel@tonic-gate *pinned = ncompelem; 10007c478bd9Sstevel@tonic-gate free(cs); 10017c478bd9Sstevel@tonic-gate } else 10027c478bd9Sstevel@tonic-gate *pinned = 0; 10037c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 10047c478bd9Sstevel@tonic-gate } 10057c478bd9Sstevel@tonic-gate 10067c478bd9Sstevel@tonic-gate /* 10077c478bd9Sstevel@tonic-gate * resource_get_min() updates min with the minimum size of the supplied 10087c478bd9Sstevel@tonic-gate * resource. 10097c478bd9Sstevel@tonic-gate * 10107c478bd9Sstevel@tonic-gate * Returns PO_SUCCESS/PO_FAIL 10117c478bd9Sstevel@tonic-gate */ 10127c478bd9Sstevel@tonic-gate int 10137c478bd9Sstevel@tonic-gate resource_get_min(const pool_resource_t *res, uint64_t *min) 10147c478bd9Sstevel@tonic-gate { 10157c478bd9Sstevel@tonic-gate return (resource_get_common(res, c_min_prop, min)); 10167c478bd9Sstevel@tonic-gate } 10177c478bd9Sstevel@tonic-gate 10187c478bd9Sstevel@tonic-gate /* 10197c478bd9Sstevel@tonic-gate * resource_get_max() updates max with the maximum size of the supplied 10207c478bd9Sstevel@tonic-gate * resource. 10217c478bd9Sstevel@tonic-gate * 10227c478bd9Sstevel@tonic-gate * Returns PO_SUCCESS/PO_FAIL 10237c478bd9Sstevel@tonic-gate */ 10247c478bd9Sstevel@tonic-gate int 10257c478bd9Sstevel@tonic-gate resource_get_max(const pool_resource_t *res, uint64_t *max) 10267c478bd9Sstevel@tonic-gate { 10277c478bd9Sstevel@tonic-gate return (resource_get_common(res, c_max_prop, max)); 10287c478bd9Sstevel@tonic-gate } 10297c478bd9Sstevel@tonic-gate 10307c478bd9Sstevel@tonic-gate /* 10317c478bd9Sstevel@tonic-gate * TODO: This is pset specific 10327c478bd9Sstevel@tonic-gate * 10337c478bd9Sstevel@tonic-gate * get_default_resource() returns the default resource for type of the supplied 10347c478bd9Sstevel@tonic-gate * resource. 10357c478bd9Sstevel@tonic-gate * 10367c478bd9Sstevel@tonic-gate * Returns A pointer to the default resource of the same type as the supplied 10377c478bd9Sstevel@tonic-gate * resource. 10387c478bd9Sstevel@tonic-gate */ 10397c478bd9Sstevel@tonic-gate const pool_resource_t * 10407c478bd9Sstevel@tonic-gate get_default_resource(const pool_resource_t *res) 10417c478bd9Sstevel@tonic-gate { 10427c478bd9Sstevel@tonic-gate return (resource_by_sysid(TO_CONF(TO_ELEM(res)), PS_NONE, 10437c478bd9Sstevel@tonic-gate pool_elem_class_string(TO_ELEM(res)))); 10447c478bd9Sstevel@tonic-gate } 10457c478bd9Sstevel@tonic-gate 10467c478bd9Sstevel@tonic-gate /* 10477c478bd9Sstevel@tonic-gate * resource_is_default() returns 1 if the supplied resource is the default 10487c478bd9Sstevel@tonic-gate * resource for it's type. 10497c478bd9Sstevel@tonic-gate */ 10507c478bd9Sstevel@tonic-gate int 10517c478bd9Sstevel@tonic-gate resource_is_default(const pool_resource_t *res) 10527c478bd9Sstevel@tonic-gate { 10537c478bd9Sstevel@tonic-gate 10547c478bd9Sstevel@tonic-gate return (get_default_resource(res) == res); 10557c478bd9Sstevel@tonic-gate } 10567c478bd9Sstevel@tonic-gate 10577c478bd9Sstevel@tonic-gate /* 10587c478bd9Sstevel@tonic-gate * resource_is_system() determines if the resource is a system resource. 10597c478bd9Sstevel@tonic-gate */ 10607c478bd9Sstevel@tonic-gate int 10617c478bd9Sstevel@tonic-gate resource_is_system(const pool_resource_t *res) 10627c478bd9Sstevel@tonic-gate { 10637c478bd9Sstevel@tonic-gate return (res->pr_is_system(res)); 10647c478bd9Sstevel@tonic-gate 10657c478bd9Sstevel@tonic-gate } 10667c478bd9Sstevel@tonic-gate 10677c478bd9Sstevel@tonic-gate /* 10687c478bd9Sstevel@tonic-gate * resource_can_associate() determines if it is possible to associate 10697c478bd9Sstevel@tonic-gate * with the supplied resource. 10707c478bd9Sstevel@tonic-gate */ 10717c478bd9Sstevel@tonic-gate int 10727c478bd9Sstevel@tonic-gate resource_can_associate(const pool_resource_t *res) 10737c478bd9Sstevel@tonic-gate { 10747c478bd9Sstevel@tonic-gate return (res->pr_can_associate(res)); 10757c478bd9Sstevel@tonic-gate } 10767c478bd9Sstevel@tonic-gate 10777c478bd9Sstevel@tonic-gate /* 10787c478bd9Sstevel@tonic-gate * Common code to get an int64 property. 10797c478bd9Sstevel@tonic-gate * Unfortunately (-1) is a valid psetid, so we'll return (-2) in case of 10807c478bd9Sstevel@tonic-gate * error. 10817c478bd9Sstevel@tonic-gate */ 10827c478bd9Sstevel@tonic-gate static int64_t 10837c478bd9Sstevel@tonic-gate elem_get_expected_int64(const pool_elem_t *elem, const char *name) 10847c478bd9Sstevel@tonic-gate { 10857c478bd9Sstevel@tonic-gate int64_t val64; 10867c478bd9Sstevel@tonic-gate pool_value_t val = POOL_VALUE_INITIALIZER; 10877c478bd9Sstevel@tonic-gate 10887c478bd9Sstevel@tonic-gate if (pool_get_ns_property(elem, name, &val) != POC_INT) { 10897c478bd9Sstevel@tonic-gate return (POOL_SYSID_BAD); 10907c478bd9Sstevel@tonic-gate } 10917c478bd9Sstevel@tonic-gate (void) pool_value_get_int64(&val, &val64); 10927c478bd9Sstevel@tonic-gate 10937c478bd9Sstevel@tonic-gate return (val64); 10947c478bd9Sstevel@tonic-gate } 10957c478bd9Sstevel@tonic-gate 10967c478bd9Sstevel@tonic-gate /* 10977c478bd9Sstevel@tonic-gate * The following returns a malloc'ed string which must be free'd by the 10987c478bd9Sstevel@tonic-gate * caller. 10997c478bd9Sstevel@tonic-gate */ 11007c478bd9Sstevel@tonic-gate static char * 11017c478bd9Sstevel@tonic-gate elem_get_expected_string(const pool_elem_t *elem, const char *name) 11027c478bd9Sstevel@tonic-gate { 11037c478bd9Sstevel@tonic-gate pool_value_t val = POOL_VALUE_INITIALIZER; 11047c478bd9Sstevel@tonic-gate char *retval; 11057c478bd9Sstevel@tonic-gate 11067c478bd9Sstevel@tonic-gate if (pool_get_ns_property(elem, name, &val) != POC_STRING) { 11077c478bd9Sstevel@tonic-gate return (NULL); 11087c478bd9Sstevel@tonic-gate } 11097c478bd9Sstevel@tonic-gate (void) pool_value_get_string(&val, (const char **)&retval); 11107c478bd9Sstevel@tonic-gate retval = strdup(retval); 11117c478bd9Sstevel@tonic-gate return (retval); 11127c478bd9Sstevel@tonic-gate } 11137c478bd9Sstevel@tonic-gate 11147c478bd9Sstevel@tonic-gate /* 11157c478bd9Sstevel@tonic-gate * elem_get_sysid() returns the sys_id for the supplied elem. 11167c478bd9Sstevel@tonic-gate */ 11177c478bd9Sstevel@tonic-gate id_t 11187c478bd9Sstevel@tonic-gate elem_get_sysid(const pool_elem_t *elem) 11197c478bd9Sstevel@tonic-gate { 11207c478bd9Sstevel@tonic-gate return ((id_t)elem_get_expected_int64(elem, c_sys_prop)); 11217c478bd9Sstevel@tonic-gate } 11227c478bd9Sstevel@tonic-gate 11237c478bd9Sstevel@tonic-gate /* 11247c478bd9Sstevel@tonic-gate * elem_get_name() returns the name for the supplied elem. Note that 11257c478bd9Sstevel@tonic-gate * it is the caller's responsibility to free this memory. 11267c478bd9Sstevel@tonic-gate */ 11277c478bd9Sstevel@tonic-gate char * 11287c478bd9Sstevel@tonic-gate elem_get_name(const pool_elem_t *elem) 11297c478bd9Sstevel@tonic-gate { 11307c478bd9Sstevel@tonic-gate return (elem_get_expected_string(elem, c_name)); 11317c478bd9Sstevel@tonic-gate } 11327c478bd9Sstevel@tonic-gate 11337c478bd9Sstevel@tonic-gate /* 11347c478bd9Sstevel@tonic-gate * elem_is_default() returns 1 if the supplied elem is the default 11357c478bd9Sstevel@tonic-gate * elem for it's type. 11367c478bd9Sstevel@tonic-gate */ 11377c478bd9Sstevel@tonic-gate int 11387c478bd9Sstevel@tonic-gate elem_is_default(const pool_elem_t *res) 11397c478bd9Sstevel@tonic-gate { 11407c478bd9Sstevel@tonic-gate 11417c478bd9Sstevel@tonic-gate return (get_default_elem(res) == res); 11427c478bd9Sstevel@tonic-gate } 11437c478bd9Sstevel@tonic-gate 11447c478bd9Sstevel@tonic-gate /* 1145*0209230bSgjelinek * Return B_TRUE if the element has the 'temporary' property set. 1146*0209230bSgjelinek */ 1147*0209230bSgjelinek boolean_t 1148*0209230bSgjelinek elem_is_tmp(const pool_elem_t *elem) 1149*0209230bSgjelinek { 1150*0209230bSgjelinek pool_value_t val = POOL_VALUE_INITIALIZER; 1151*0209230bSgjelinek uchar_t bval; 1152*0209230bSgjelinek 1153*0209230bSgjelinek if (pool_get_ns_property(elem, "temporary", &val) != POC_BOOL) 1154*0209230bSgjelinek return (B_FALSE); 1155*0209230bSgjelinek 1156*0209230bSgjelinek (void) pool_value_get_bool(&val, &bval); 1157*0209230bSgjelinek 1158*0209230bSgjelinek return (bval != 0); 1159*0209230bSgjelinek } 1160*0209230bSgjelinek 1161*0209230bSgjelinek /* 11627c478bd9Sstevel@tonic-gate * get_default_elem() returns the default elem for type of the supplied 11637c478bd9Sstevel@tonic-gate * elem. 11647c478bd9Sstevel@tonic-gate * 11657c478bd9Sstevel@tonic-gate * Returns A pointer to the default elem of the same type as the 11667c478bd9Sstevel@tonic-gate * supplied elem or NULL on error. Trying to access the default elem 11677c478bd9Sstevel@tonic-gate * for a type of element which doesn't support the notion of default 11687c478bd9Sstevel@tonic-gate * is an error. 11697c478bd9Sstevel@tonic-gate */ 11707c478bd9Sstevel@tonic-gate const pool_elem_t * 11717c478bd9Sstevel@tonic-gate get_default_elem(const pool_elem_t *pe) 11727c478bd9Sstevel@tonic-gate { 11737c478bd9Sstevel@tonic-gate pool_result_set_t *rs; 11747c478bd9Sstevel@tonic-gate pool_value_t *props[] = { NULL, NULL }; 11757c478bd9Sstevel@tonic-gate pool_value_t val = POOL_VALUE_INITIALIZER; 11767c478bd9Sstevel@tonic-gate char_buf_t *cb; 11777c478bd9Sstevel@tonic-gate const pool_elem_t *pe_default; 11787c478bd9Sstevel@tonic-gate 11797c478bd9Sstevel@tonic-gate props[0] = &val; 11807c478bd9Sstevel@tonic-gate if ((cb = alloc_char_buf(CB_DEFAULT_LEN)) == NULL) { 11817c478bd9Sstevel@tonic-gate return (NULL); 11827c478bd9Sstevel@tonic-gate } 11837c478bd9Sstevel@tonic-gate if (set_char_buf(cb, "%s.default", pool_elem_class_string(pe)) != 11847c478bd9Sstevel@tonic-gate PO_SUCCESS) { 11857c478bd9Sstevel@tonic-gate free_char_buf(cb); 11867c478bd9Sstevel@tonic-gate return (NULL); 11877c478bd9Sstevel@tonic-gate } 11887c478bd9Sstevel@tonic-gate if (pool_value_set_name(props[0], cb->cb_buf) != PO_SUCCESS) { 11897c478bd9Sstevel@tonic-gate free_char_buf(cb); 11907c478bd9Sstevel@tonic-gate return (NULL); 11917c478bd9Sstevel@tonic-gate } 11927c478bd9Sstevel@tonic-gate free_char_buf(cb); 11937c478bd9Sstevel@tonic-gate pool_value_set_bool(props[0], PO_TRUE); 11947c478bd9Sstevel@tonic-gate 11957c478bd9Sstevel@tonic-gate if ((rs = pool_exec_query(TO_CONF(pe), NULL, NULL, 11967c478bd9Sstevel@tonic-gate PEC_QRY_ELEM(pe), props)) == NULL) { 11977c478bd9Sstevel@tonic-gate pool_seterror(POE_INVALID_CONF); 11987c478bd9Sstevel@tonic-gate return (NULL); 11997c478bd9Sstevel@tonic-gate } 12007c478bd9Sstevel@tonic-gate if (pool_rs_count(rs) != 1) { 12017c478bd9Sstevel@tonic-gate (void) pool_rs_close(rs); 12027c478bd9Sstevel@tonic-gate pool_seterror(POE_INVALID_CONF); 12037c478bd9Sstevel@tonic-gate return (NULL); 12047c478bd9Sstevel@tonic-gate } 12057c478bd9Sstevel@tonic-gate 12067c478bd9Sstevel@tonic-gate pe_default = rs->prs_next(rs); 12077c478bd9Sstevel@tonic-gate (void) pool_rs_close(rs); 12087c478bd9Sstevel@tonic-gate return (pe_default); 12097c478bd9Sstevel@tonic-gate } 12107c478bd9Sstevel@tonic-gate 12117c478bd9Sstevel@tonic-gate /* 12127c478bd9Sstevel@tonic-gate * is_a_known_prefix() determines if the supplied prop_name is a known 12137c478bd9Sstevel@tonic-gate * name for the supplied class. 12147c478bd9Sstevel@tonic-gate * 12157c478bd9Sstevel@tonic-gate * Returns a pointer to the prefix if it is found or NULL 12167c478bd9Sstevel@tonic-gate */ 12177c478bd9Sstevel@tonic-gate const char * 12187c478bd9Sstevel@tonic-gate is_a_known_prefix(pool_elem_class_t class, const char *prop_name) 12197c478bd9Sstevel@tonic-gate { 12207c478bd9Sstevel@tonic-gate int i; 12217c478bd9Sstevel@tonic-gate int len; 12227c478bd9Sstevel@tonic-gate 12237c478bd9Sstevel@tonic-gate switch (class) { 12247c478bd9Sstevel@tonic-gate case PEC_SYSTEM: 12257c478bd9Sstevel@tonic-gate case PEC_POOL: 12267c478bd9Sstevel@tonic-gate len = strlen(pool_elem_class_name[class]); 12277c478bd9Sstevel@tonic-gate if (strncmp(prop_name, pool_elem_class_name[class], len) == 0 && 12287c478bd9Sstevel@tonic-gate prop_name[len] == '.' || strcmp(prop_name, c_type) == 0) 12297c478bd9Sstevel@tonic-gate return (pool_elem_class_name[class]); 12307c478bd9Sstevel@tonic-gate break; 12317c478bd9Sstevel@tonic-gate case PEC_RES_COMP: 12327c478bd9Sstevel@tonic-gate case PEC_RES_AGG: 12337c478bd9Sstevel@tonic-gate for (i = 0; i < sizeof (pool_resource_elem_class_name) / 12347c478bd9Sstevel@tonic-gate sizeof (pool_resource_elem_class_name[0]); i++) { 12357c478bd9Sstevel@tonic-gate len = strlen(pool_resource_elem_class_name[i]); 12367c478bd9Sstevel@tonic-gate if (strncmp(prop_name, 12377c478bd9Sstevel@tonic-gate pool_resource_elem_class_name[i], len) == 0 && 12387c478bd9Sstevel@tonic-gate prop_name[len] == '.' || 12397c478bd9Sstevel@tonic-gate strcmp(prop_name, c_type) == 0) 12407c478bd9Sstevel@tonic-gate return (pool_resource_elem_class_name[i]); 12417c478bd9Sstevel@tonic-gate } 12427c478bd9Sstevel@tonic-gate break; 12437c478bd9Sstevel@tonic-gate case PEC_COMP: 12447c478bd9Sstevel@tonic-gate for (i = 0; i < sizeof (pool_component_elem_class_name) / 12457c478bd9Sstevel@tonic-gate sizeof (pool_component_elem_class_name[0]); i++) { 12467c478bd9Sstevel@tonic-gate len = strlen(pool_component_elem_class_name[i]); 12477c478bd9Sstevel@tonic-gate if (strncmp(prop_name, 12487c478bd9Sstevel@tonic-gate pool_component_elem_class_name[i], len) == 0 && 12497c478bd9Sstevel@tonic-gate prop_name[len] == '.' || 12507c478bd9Sstevel@tonic-gate strcmp(prop_name, c_type) == 0) 12517c478bd9Sstevel@tonic-gate return (pool_component_elem_class_name[i]); 12527c478bd9Sstevel@tonic-gate } 12537c478bd9Sstevel@tonic-gate break; 12547c478bd9Sstevel@tonic-gate default: 12557c478bd9Sstevel@tonic-gate break; 12567c478bd9Sstevel@tonic-gate } 12577c478bd9Sstevel@tonic-gate return (NULL); 12587c478bd9Sstevel@tonic-gate } 12597c478bd9Sstevel@tonic-gate 12607c478bd9Sstevel@tonic-gate 12617c478bd9Sstevel@tonic-gate const char * 12627c478bd9Sstevel@tonic-gate pool_elem_class_string(const pool_elem_t *pe) 12637c478bd9Sstevel@tonic-gate { 12647c478bd9Sstevel@tonic-gate switch (pool_elem_class(pe)) { 12657c478bd9Sstevel@tonic-gate case PEC_SYSTEM: 12667c478bd9Sstevel@tonic-gate case PEC_POOL: 12677c478bd9Sstevel@tonic-gate return (pool_elem_class_name[pool_elem_class(pe)]); 12687c478bd9Sstevel@tonic-gate case PEC_RES_COMP: 12697c478bd9Sstevel@tonic-gate case PEC_RES_AGG: 12707c478bd9Sstevel@tonic-gate return (pool_resource_elem_class_name 12717c478bd9Sstevel@tonic-gate [pool_resource_elem_class(pe)]); 12727c478bd9Sstevel@tonic-gate case PEC_COMP: 12737c478bd9Sstevel@tonic-gate return (pool_component_elem_class_name 12747c478bd9Sstevel@tonic-gate [pool_component_elem_class(pe)]); 12757c478bd9Sstevel@tonic-gate default: 12767c478bd9Sstevel@tonic-gate return (pool_elem_class_name[PEC_INVALID]); 12777c478bd9Sstevel@tonic-gate } 12787c478bd9Sstevel@tonic-gate } 12797c478bd9Sstevel@tonic-gate 12807c478bd9Sstevel@tonic-gate const char * 12817c478bd9Sstevel@tonic-gate pool_resource_type_string(pool_resource_elem_class_t type) 12827c478bd9Sstevel@tonic-gate { 12837c478bd9Sstevel@tonic-gate return (pool_resource_elem_class_name[type]); 12847c478bd9Sstevel@tonic-gate } 12857c478bd9Sstevel@tonic-gate 12867c478bd9Sstevel@tonic-gate const char * 12877c478bd9Sstevel@tonic-gate pool_component_type_string(pool_component_elem_class_t type) 12887c478bd9Sstevel@tonic-gate { 12897c478bd9Sstevel@tonic-gate return (pool_component_elem_class_name[type]); 12907c478bd9Sstevel@tonic-gate } 12917c478bd9Sstevel@tonic-gate 12927c478bd9Sstevel@tonic-gate /* 12937c478bd9Sstevel@tonic-gate * resource_by_sysid() finds a resource from it's supplied sysid and type. 12947c478bd9Sstevel@tonic-gate * 12957c478bd9Sstevel@tonic-gate * Returns a pointer to the resource or NULL if it doesn't exist. 12967c478bd9Sstevel@tonic-gate */ 12977c478bd9Sstevel@tonic-gate pool_resource_t * 12987c478bd9Sstevel@tonic-gate resource_by_sysid(const pool_conf_t *conf, id_t sysid, const char *type) 12997c478bd9Sstevel@tonic-gate { 13007c478bd9Sstevel@tonic-gate pool_value_t *props[] = { NULL, NULL, NULL }; 13017c478bd9Sstevel@tonic-gate pool_resource_t **resources = NULL; 13027c478bd9Sstevel@tonic-gate pool_resource_t *retval = NULL; 13037c478bd9Sstevel@tonic-gate uint_t nelem; 13047c478bd9Sstevel@tonic-gate char_buf_t *cb; 13057c478bd9Sstevel@tonic-gate pool_value_t val0 = POOL_VALUE_INITIALIZER; 13067c478bd9Sstevel@tonic-gate pool_value_t val1 = POOL_VALUE_INITIALIZER; 13077c478bd9Sstevel@tonic-gate 13087c478bd9Sstevel@tonic-gate props[0] = &val0; 13097c478bd9Sstevel@tonic-gate props[1] = &val1; 13107c478bd9Sstevel@tonic-gate 13117c478bd9Sstevel@tonic-gate if (pool_value_set_string(props[0], type) != PO_SUCCESS || 13127c478bd9Sstevel@tonic-gate pool_value_set_name(props[0], c_type) != PO_SUCCESS) 13137c478bd9Sstevel@tonic-gate return (NULL); 13147c478bd9Sstevel@tonic-gate 13157c478bd9Sstevel@tonic-gate if ((cb = alloc_char_buf(CB_DEFAULT_LEN)) == NULL) { 13167c478bd9Sstevel@tonic-gate return (NULL); 13177c478bd9Sstevel@tonic-gate } 13187c478bd9Sstevel@tonic-gate if (set_char_buf(cb, "%s.sys_id", type) != PO_SUCCESS) { 13197c478bd9Sstevel@tonic-gate free_char_buf(cb); 13207c478bd9Sstevel@tonic-gate return (NULL); 13217c478bd9Sstevel@tonic-gate } 13227c478bd9Sstevel@tonic-gate if (pool_value_set_name(props[1], cb->cb_buf) != PO_SUCCESS) { 13237c478bd9Sstevel@tonic-gate free_char_buf(cb); 13247c478bd9Sstevel@tonic-gate return (NULL); 13257c478bd9Sstevel@tonic-gate } 13267c478bd9Sstevel@tonic-gate free_char_buf(cb); 13277c478bd9Sstevel@tonic-gate pool_value_set_int64(props[1], sysid); 13287c478bd9Sstevel@tonic-gate 13297c478bd9Sstevel@tonic-gate resources = pool_query_resources(conf, &nelem, props); 13307c478bd9Sstevel@tonic-gate 13317c478bd9Sstevel@tonic-gate if (resources != NULL) { 13327c478bd9Sstevel@tonic-gate retval = resources[0]; 13337c478bd9Sstevel@tonic-gate free(resources); 13347c478bd9Sstevel@tonic-gate } 13357c478bd9Sstevel@tonic-gate return (retval); 13367c478bd9Sstevel@tonic-gate } 13377c478bd9Sstevel@tonic-gate 13387c478bd9Sstevel@tonic-gate pool_elem_class_t 13397c478bd9Sstevel@tonic-gate pool_elem_class_from_string(const char *type) 13407c478bd9Sstevel@tonic-gate { 13417c478bd9Sstevel@tonic-gate int i; 13427c478bd9Sstevel@tonic-gate 13437c478bd9Sstevel@tonic-gate for (i = 0; i < sizeof (pool_elem_class_name) / 13447c478bd9Sstevel@tonic-gate sizeof (pool_elem_class_name[0]); i++) { 13457c478bd9Sstevel@tonic-gate if (strcmp(pool_elem_class_name[i], type) == 0) 13467c478bd9Sstevel@tonic-gate break; 13477c478bd9Sstevel@tonic-gate } 13487c478bd9Sstevel@tonic-gate if (i == sizeof (pool_elem_class_name) / 13497c478bd9Sstevel@tonic-gate sizeof (pool_elem_class_name[0])) 13507c478bd9Sstevel@tonic-gate return (PEC_INVALID); 13517c478bd9Sstevel@tonic-gate return ((pool_elem_class_t)i); 13527c478bd9Sstevel@tonic-gate } 13537c478bd9Sstevel@tonic-gate 13547c478bd9Sstevel@tonic-gate pool_resource_elem_class_t 13557c478bd9Sstevel@tonic-gate pool_resource_elem_class_from_string(const char *type) 13567c478bd9Sstevel@tonic-gate { 13577c478bd9Sstevel@tonic-gate int i; 13587c478bd9Sstevel@tonic-gate 13597c478bd9Sstevel@tonic-gate for (i = 0; i < sizeof (pool_resource_elem_class_name) / 13607c478bd9Sstevel@tonic-gate sizeof (pool_resource_elem_class_name[0]); i++) { 13617c478bd9Sstevel@tonic-gate if (strcmp(pool_resource_elem_class_name[i], type) == 0) 13627c478bd9Sstevel@tonic-gate break; 13637c478bd9Sstevel@tonic-gate } 13647c478bd9Sstevel@tonic-gate if (i == sizeof (pool_resource_elem_class_name) / 13657c478bd9Sstevel@tonic-gate sizeof (pool_resource_elem_class_name[0])) 13667c478bd9Sstevel@tonic-gate return (PREC_INVALID); 13677c478bd9Sstevel@tonic-gate return ((pool_resource_elem_class_t)i); 13687c478bd9Sstevel@tonic-gate } 13697c478bd9Sstevel@tonic-gate 13707c478bd9Sstevel@tonic-gate pool_component_elem_class_t 13717c478bd9Sstevel@tonic-gate pool_component_elem_class_from_string(const char *type) 13727c478bd9Sstevel@tonic-gate { 13737c478bd9Sstevel@tonic-gate int i; 13747c478bd9Sstevel@tonic-gate 13757c478bd9Sstevel@tonic-gate for (i = 0; i < sizeof (pool_component_elem_class_name) / 13767c478bd9Sstevel@tonic-gate sizeof (pool_component_elem_class_name[0]); i++) { 13777c478bd9Sstevel@tonic-gate if (strcmp(pool_component_elem_class_name[i], type) == 0) 13787c478bd9Sstevel@tonic-gate break; 13797c478bd9Sstevel@tonic-gate } 13807c478bd9Sstevel@tonic-gate if (i == sizeof (pool_component_elem_class_name) / 13817c478bd9Sstevel@tonic-gate sizeof (pool_component_elem_class_name[0])) 13827c478bd9Sstevel@tonic-gate return (PCEC_INVALID); 13837c478bd9Sstevel@tonic-gate return ((pool_component_elem_class_t)i); 13847c478bd9Sstevel@tonic-gate } 13857c478bd9Sstevel@tonic-gate 13867c478bd9Sstevel@tonic-gate /* 13877c478bd9Sstevel@tonic-gate * pool_resource_type_list() populates the supplied array of pointers 13887c478bd9Sstevel@tonic-gate * with the names of the available resource types on this system. 13897c478bd9Sstevel@tonic-gate */ 13907c478bd9Sstevel@tonic-gate int 13917c478bd9Sstevel@tonic-gate pool_resource_type_list(const char **types, uint_t *numtypes) 13927c478bd9Sstevel@tonic-gate { 13937c478bd9Sstevel@tonic-gate int i, j; 13947c478bd9Sstevel@tonic-gate uint_t maxnum = *numtypes; 13957c478bd9Sstevel@tonic-gate 13967c478bd9Sstevel@tonic-gate *numtypes = pool_get_provider_count(); 13977c478bd9Sstevel@tonic-gate 13987c478bd9Sstevel@tonic-gate if (types) { 13997c478bd9Sstevel@tonic-gate for (i = 0, j = 0; i < sizeof (pool_resource_elem_ctl) / 14007c478bd9Sstevel@tonic-gate sizeof (pool_resource_elem_ctl[0]) && j < maxnum; i++) { 14017c478bd9Sstevel@tonic-gate if (pool_resource_elem_ctl[i] != NULL) 14027c478bd9Sstevel@tonic-gate types[j++] = pool_resource_elem_class_name[i]; 14037c478bd9Sstevel@tonic-gate } 14047c478bd9Sstevel@tonic-gate } 14057c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 14067c478bd9Sstevel@tonic-gate } 14077c478bd9Sstevel@tonic-gate 14087c478bd9Sstevel@tonic-gate /* 14097c478bd9Sstevel@tonic-gate * Return the system element for the supplied conf. 14107c478bd9Sstevel@tonic-gate * NULL is returned if an error is detected and the error code is updated 14117c478bd9Sstevel@tonic-gate * to indicate the cause of the error. 14127c478bd9Sstevel@tonic-gate */ 14137c478bd9Sstevel@tonic-gate pool_system_t * 14147c478bd9Sstevel@tonic-gate pool_conf_system(const pool_conf_t *conf) 14157c478bd9Sstevel@tonic-gate { 14167c478bd9Sstevel@tonic-gate pool_elem_t *system; 14177c478bd9Sstevel@tonic-gate pool_result_set_t *rs; 14187c478bd9Sstevel@tonic-gate 14197c478bd9Sstevel@tonic-gate if ((rs = pool_exec_query(conf, NULL, NULL, PEC_QRY_SYSTEM, NULL)) == 14207c478bd9Sstevel@tonic-gate NULL) { 14217c478bd9Sstevel@tonic-gate pool_seterror(POE_INVALID_CONF); 14227c478bd9Sstevel@tonic-gate return (NULL); 14237c478bd9Sstevel@tonic-gate } 14247c478bd9Sstevel@tonic-gate /* There should only be one system record */ 14257c478bd9Sstevel@tonic-gate if (pool_rs_count(rs) != 1) { 14267c478bd9Sstevel@tonic-gate pool_seterror(POE_INVALID_CONF); 14277c478bd9Sstevel@tonic-gate (void) pool_rs_close(rs); 14287c478bd9Sstevel@tonic-gate return (NULL); 14297c478bd9Sstevel@tonic-gate } 14307c478bd9Sstevel@tonic-gate system = rs->prs_next(rs); 14317c478bd9Sstevel@tonic-gate (void) pool_rs_close(rs); 14327c478bd9Sstevel@tonic-gate return (pool_elem_system(system)); 14337c478bd9Sstevel@tonic-gate } 14347c478bd9Sstevel@tonic-gate 14357c478bd9Sstevel@tonic-gate pool_system_t * 14367c478bd9Sstevel@tonic-gate pool_elem_system(const pool_elem_t *pe) 14377c478bd9Sstevel@tonic-gate { 14387c478bd9Sstevel@tonic-gate if (pe->pe_class != PEC_SYSTEM) { 14397c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 14407c478bd9Sstevel@tonic-gate return (NULL); 14417c478bd9Sstevel@tonic-gate } 14427c478bd9Sstevel@tonic-gate return ((pool_system_t *)pe); 14437c478bd9Sstevel@tonic-gate } 14447c478bd9Sstevel@tonic-gate 14457c478bd9Sstevel@tonic-gate pool_t * 14467c478bd9Sstevel@tonic-gate pool_elem_pool(const pool_elem_t *pe) 14477c478bd9Sstevel@tonic-gate { 14487c478bd9Sstevel@tonic-gate if (pe->pe_class != PEC_POOL) { 14497c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 14507c478bd9Sstevel@tonic-gate return (NULL); 14517c478bd9Sstevel@tonic-gate } 14527c478bd9Sstevel@tonic-gate return ((pool_t *)pe); 14537c478bd9Sstevel@tonic-gate } 14547c478bd9Sstevel@tonic-gate 14557c478bd9Sstevel@tonic-gate pool_resource_t * 14567c478bd9Sstevel@tonic-gate pool_elem_res(const pool_elem_t *pe) 14577c478bd9Sstevel@tonic-gate { 14587c478bd9Sstevel@tonic-gate if (pe->pe_class != PEC_RES_COMP && 14597c478bd9Sstevel@tonic-gate pool_elem_class(pe) != PEC_RES_AGG) { 14607c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 14617c478bd9Sstevel@tonic-gate return (NULL); 14627c478bd9Sstevel@tonic-gate } 14637c478bd9Sstevel@tonic-gate return ((pool_resource_t *)pe); 14647c478bd9Sstevel@tonic-gate } 14657c478bd9Sstevel@tonic-gate 14667c478bd9Sstevel@tonic-gate pool_component_t * 14677c478bd9Sstevel@tonic-gate pool_elem_comp(const pool_elem_t *pe) 14687c478bd9Sstevel@tonic-gate { 14697c478bd9Sstevel@tonic-gate if (pe->pe_class != PEC_COMP) { 14707c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 14717c478bd9Sstevel@tonic-gate return (NULL); 14727c478bd9Sstevel@tonic-gate } 14737c478bd9Sstevel@tonic-gate return ((pool_component_t *)pe); 14747c478bd9Sstevel@tonic-gate } 14757c478bd9Sstevel@tonic-gate 14767c478bd9Sstevel@tonic-gate /* 14777c478bd9Sstevel@tonic-gate * qsort_elem_compare() is used for qsort elemement comparison. 14787c478bd9Sstevel@tonic-gate * 14797c478bd9Sstevel@tonic-gate * Returns see qsort(3c) 14807c478bd9Sstevel@tonic-gate */ 14817c478bd9Sstevel@tonic-gate int 14827c478bd9Sstevel@tonic-gate qsort_elem_compare(const void *a, const void *b) 14837c478bd9Sstevel@tonic-gate { 14847c478bd9Sstevel@tonic-gate const pool_elem_t *e1 = *(const pool_elem_t **)a; 14857c478bd9Sstevel@tonic-gate const pool_elem_t *e2 = *(const pool_elem_t **)b; 14867c478bd9Sstevel@tonic-gate 14877c478bd9Sstevel@tonic-gate /* 14887c478bd9Sstevel@tonic-gate * Special case for handling name changes on default elements 14897c478bd9Sstevel@tonic-gate * If both elements are default elements then always return 0 14907c478bd9Sstevel@tonic-gate */ 14917c478bd9Sstevel@tonic-gate if (pool_elem_same_class(e1, e2) == PO_TRUE && 14927c478bd9Sstevel@tonic-gate (elem_is_default(e1) && elem_is_default(e2))) 14937c478bd9Sstevel@tonic-gate return (0); 14947c478bd9Sstevel@tonic-gate else 14957c478bd9Sstevel@tonic-gate return (pool_elem_compare_name(e1, e2)); 14967c478bd9Sstevel@tonic-gate } 14977c478bd9Sstevel@tonic-gate 14987c478bd9Sstevel@tonic-gate /* 14997c478bd9Sstevel@tonic-gate * Dynamic character buffers. 15007c478bd9Sstevel@tonic-gate */ 15017c478bd9Sstevel@tonic-gate 15027c478bd9Sstevel@tonic-gate /* 15037c478bd9Sstevel@tonic-gate * Resize the supplied character buffer to the new size. 15047c478bd9Sstevel@tonic-gate */ 15057c478bd9Sstevel@tonic-gate static int 15067c478bd9Sstevel@tonic-gate resize_char_buf(char_buf_t *cb, size_t size) 15077c478bd9Sstevel@tonic-gate { 15087c478bd9Sstevel@tonic-gate char *re_cb = NULL; 15097c478bd9Sstevel@tonic-gate 15107c478bd9Sstevel@tonic-gate if ((re_cb = realloc(cb->cb_buf, size)) == NULL) { 15117c478bd9Sstevel@tonic-gate pool_seterror(POE_SYSTEM); 15127c478bd9Sstevel@tonic-gate return (PO_FAIL); 15137c478bd9Sstevel@tonic-gate } 15147c478bd9Sstevel@tonic-gate /* If inital allocation, make sure buffer is zeroed */ 15157c478bd9Sstevel@tonic-gate if (cb->cb_buf == NULL) 15167c478bd9Sstevel@tonic-gate (void) memset(re_cb, 0, sizeof (re_cb)); 15177c478bd9Sstevel@tonic-gate /* If resized smaller, make sure buffer NULL terminated */ 15187c478bd9Sstevel@tonic-gate if (size < cb->cb_size) 15197c478bd9Sstevel@tonic-gate re_cb[size] = 0; 15207c478bd9Sstevel@tonic-gate cb->cb_buf = re_cb; 15217c478bd9Sstevel@tonic-gate cb->cb_size = size; 15227c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 15237c478bd9Sstevel@tonic-gate } 15247c478bd9Sstevel@tonic-gate 15257c478bd9Sstevel@tonic-gate /* 15267c478bd9Sstevel@tonic-gate * Allocate a new char_buf_t structure. If there isn't enough memory, return 15277c478bd9Sstevel@tonic-gate * NULL. Initialise the new char_buf_t to 0 and then call resize_char_buf 15287c478bd9Sstevel@tonic-gate * to initialise the character buffer. Return a pointer to the new 15297c478bd9Sstevel@tonic-gate * char_buf_t if the operation succeeds. 15307c478bd9Sstevel@tonic-gate */ 15317c478bd9Sstevel@tonic-gate char_buf_t * 15327c478bd9Sstevel@tonic-gate alloc_char_buf(size_t size) 15337c478bd9Sstevel@tonic-gate { 15347c478bd9Sstevel@tonic-gate char_buf_t *cb; 15357c478bd9Sstevel@tonic-gate 15367c478bd9Sstevel@tonic-gate if ((cb = malloc(sizeof (char_buf_t))) == NULL) { 15377c478bd9Sstevel@tonic-gate pool_seterror(POE_SYSTEM); 15387c478bd9Sstevel@tonic-gate return (NULL); 15397c478bd9Sstevel@tonic-gate } 15407c478bd9Sstevel@tonic-gate (void) memset(cb, 0, sizeof (char_buf_t)); 15417c478bd9Sstevel@tonic-gate 15427c478bd9Sstevel@tonic-gate if (resize_char_buf(cb, size + 1) == PO_FAIL) { 15437c478bd9Sstevel@tonic-gate free(cb); 15447c478bd9Sstevel@tonic-gate return (NULL); 15457c478bd9Sstevel@tonic-gate } 15467c478bd9Sstevel@tonic-gate return (cb); 15477c478bd9Sstevel@tonic-gate } 15487c478bd9Sstevel@tonic-gate 15497c478bd9Sstevel@tonic-gate /* 15507c478bd9Sstevel@tonic-gate * Free the character buffer and then free the char_buf_t. 15517c478bd9Sstevel@tonic-gate */ 15527c478bd9Sstevel@tonic-gate void 15537c478bd9Sstevel@tonic-gate free_char_buf(char_buf_t *cb) 15547c478bd9Sstevel@tonic-gate { 15557c478bd9Sstevel@tonic-gate free((void *)cb->cb_buf); 15567c478bd9Sstevel@tonic-gate free(cb); 15577c478bd9Sstevel@tonic-gate } 15587c478bd9Sstevel@tonic-gate 15597c478bd9Sstevel@tonic-gate /* 15607c478bd9Sstevel@tonic-gate * Set the character buffer to the supplied data. The user supplies a printf 15617c478bd9Sstevel@tonic-gate * like format string and then an appropriate number of parameters for the 15627c478bd9Sstevel@tonic-gate * specified format. The character buffer is automatically resized to fit 15637c478bd9Sstevel@tonic-gate * the data as determined by resize_char_buf. 15647c478bd9Sstevel@tonic-gate */ 15657c478bd9Sstevel@tonic-gate /*PRINTFLIKE2*/ 15667c478bd9Sstevel@tonic-gate int 15677c478bd9Sstevel@tonic-gate set_char_buf(char_buf_t *cb, const char *fmt, ...) 15687c478bd9Sstevel@tonic-gate { 15697c478bd9Sstevel@tonic-gate va_list ap; 15707c478bd9Sstevel@tonic-gate int new_size; 15717c478bd9Sstevel@tonic-gate 15727c478bd9Sstevel@tonic-gate va_start(ap, fmt); 15737c478bd9Sstevel@tonic-gate if ((new_size = vsnprintf(cb->cb_buf, cb->cb_size, fmt, ap)) >= 15747c478bd9Sstevel@tonic-gate cb->cb_size) { 15757c478bd9Sstevel@tonic-gate if (resize_char_buf(cb, new_size + 1) != PO_SUCCESS) { 15767c478bd9Sstevel@tonic-gate pool_seterror(POE_SYSTEM); 15777c478bd9Sstevel@tonic-gate return (PO_FAIL); 15787c478bd9Sstevel@tonic-gate } 15797c478bd9Sstevel@tonic-gate (void) vsnprintf(cb->cb_buf, cb->cb_size, fmt, ap); 15807c478bd9Sstevel@tonic-gate } 15817c478bd9Sstevel@tonic-gate va_end(ap); 15827c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 15837c478bd9Sstevel@tonic-gate } 15847c478bd9Sstevel@tonic-gate 15857c478bd9Sstevel@tonic-gate /* 15867c478bd9Sstevel@tonic-gate * Append the supplied data to the character buffer. The user supplies a printf 15877c478bd9Sstevel@tonic-gate * like format string and then an appropriate number of parameters for the 15887c478bd9Sstevel@tonic-gate * specified format. The character buffer is automatically resized to fit 15897c478bd9Sstevel@tonic-gate * the data as determined by resize_char_buf. 15907c478bd9Sstevel@tonic-gate */ 15917c478bd9Sstevel@tonic-gate /*PRINTFLIKE2*/ 15927c478bd9Sstevel@tonic-gate int 15937c478bd9Sstevel@tonic-gate append_char_buf(char_buf_t *cb, const char *fmt, ...) 15947c478bd9Sstevel@tonic-gate { 15957c478bd9Sstevel@tonic-gate va_list ap; 15967c478bd9Sstevel@tonic-gate int new_len; 15977c478bd9Sstevel@tonic-gate char size_buf[1]; 15987c478bd9Sstevel@tonic-gate int old_len = 0; 15997c478bd9Sstevel@tonic-gate 16007c478bd9Sstevel@tonic-gate if (cb->cb_buf != NULL) 16017c478bd9Sstevel@tonic-gate old_len = strlen(cb->cb_buf); 16027c478bd9Sstevel@tonic-gate va_start(ap, fmt); 16037c478bd9Sstevel@tonic-gate new_len = vsnprintf(size_buf, sizeof (size_buf), fmt, ap); 16047c478bd9Sstevel@tonic-gate if (new_len + old_len >= cb->cb_size) { 16057c478bd9Sstevel@tonic-gate if (resize_char_buf(cb, old_len + new_len + 1) != 16067c478bd9Sstevel@tonic-gate PO_SUCCESS) { 16077c478bd9Sstevel@tonic-gate pool_seterror(POE_SYSTEM); 16087c478bd9Sstevel@tonic-gate return (PO_FAIL); 16097c478bd9Sstevel@tonic-gate } 16107c478bd9Sstevel@tonic-gate } 16117c478bd9Sstevel@tonic-gate /* 16127c478bd9Sstevel@tonic-gate * Resized the buffer to the right size, now append the new data 16137c478bd9Sstevel@tonic-gate */ 16147c478bd9Sstevel@tonic-gate (void) vsnprintf(&cb->cb_buf[old_len], cb->cb_size - old_len, fmt, ap); 16157c478bd9Sstevel@tonic-gate va_end(ap); 16167c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 16177c478bd9Sstevel@tonic-gate } 16187c478bd9Sstevel@tonic-gate 16197c478bd9Sstevel@tonic-gate /* 16207c478bd9Sstevel@tonic-gate * Return the class for the supplied elem. 16217c478bd9Sstevel@tonic-gate * If the return is PEC_INVALID, the error code will be set to reflect cause. 16227c478bd9Sstevel@tonic-gate */ 16237c478bd9Sstevel@tonic-gate pool_elem_class_t 16247c478bd9Sstevel@tonic-gate pool_elem_class(const pool_elem_t *elem) 16257c478bd9Sstevel@tonic-gate { 16267c478bd9Sstevel@tonic-gate return (elem->pe_class); 16277c478bd9Sstevel@tonic-gate } 16287c478bd9Sstevel@tonic-gate 16297c478bd9Sstevel@tonic-gate 16307c478bd9Sstevel@tonic-gate /* 16317c478bd9Sstevel@tonic-gate * Return the resource class for the supplied elem. 16327c478bd9Sstevel@tonic-gate */ 16337c478bd9Sstevel@tonic-gate pool_resource_elem_class_t 16347c478bd9Sstevel@tonic-gate pool_resource_elem_class(const pool_elem_t *elem) 16357c478bd9Sstevel@tonic-gate { 16367c478bd9Sstevel@tonic-gate return (elem->pe_resource_class); 16377c478bd9Sstevel@tonic-gate } 16387c478bd9Sstevel@tonic-gate 16397c478bd9Sstevel@tonic-gate /* 16407c478bd9Sstevel@tonic-gate * Return the component class for the supplied elem. 16417c478bd9Sstevel@tonic-gate */ 16427c478bd9Sstevel@tonic-gate pool_component_elem_class_t 16437c478bd9Sstevel@tonic-gate pool_component_elem_class(const pool_elem_t *elem) 16447c478bd9Sstevel@tonic-gate { 16457c478bd9Sstevel@tonic-gate return (elem->pe_component_class); 16467c478bd9Sstevel@tonic-gate } 16477c478bd9Sstevel@tonic-gate 16487c478bd9Sstevel@tonic-gate pool_elem_t * 16497c478bd9Sstevel@tonic-gate pool_get_pair(const pool_elem_t *pe) 16507c478bd9Sstevel@tonic-gate { 16517c478bd9Sstevel@tonic-gate return (pe->pe_pair); 16527c478bd9Sstevel@tonic-gate } 16537c478bd9Sstevel@tonic-gate 16547c478bd9Sstevel@tonic-gate void 16557c478bd9Sstevel@tonic-gate pool_set_pair(pool_elem_t *pe1, pool_elem_t *pe2) 16567c478bd9Sstevel@tonic-gate { 16577c478bd9Sstevel@tonic-gate pe1->pe_pair = pe2; 16587c478bd9Sstevel@tonic-gate } 16597c478bd9Sstevel@tonic-gate 16607c478bd9Sstevel@tonic-gate int 16617c478bd9Sstevel@tonic-gate pool_validate_resource(const pool_conf_t *conf, const char *type, 16627c478bd9Sstevel@tonic-gate const char *prop, int64_t delta) 16637c478bd9Sstevel@tonic-gate { 16647c478bd9Sstevel@tonic-gate pool_conf_t *dyn; 16657c478bd9Sstevel@tonic-gate uint_t nelem; 16667c478bd9Sstevel@tonic-gate uint64_t available, required, uval; 16677c478bd9Sstevel@tonic-gate int i; 16687c478bd9Sstevel@tonic-gate pool_resource_t **rl; 16697c478bd9Sstevel@tonic-gate pool_value_t val = POOL_VALUE_INITIALIZER; 16707c478bd9Sstevel@tonic-gate pool_value_t val1 = POOL_VALUE_INITIALIZER; 16717c478bd9Sstevel@tonic-gate pool_value_t *pvals[] = { NULL, NULL }; 16727c478bd9Sstevel@tonic-gate 16737c478bd9Sstevel@tonic-gate if (strcmp(prop, c_min_prop) && strcmp(prop, c_max_prop)) { 16747c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 16757c478bd9Sstevel@tonic-gate return (PO_FAIL); 16767c478bd9Sstevel@tonic-gate } 16777c478bd9Sstevel@tonic-gate 16787c478bd9Sstevel@tonic-gate pvals[0] = &val; 16797c478bd9Sstevel@tonic-gate (void) pool_value_set_string(&val, type); 16807c478bd9Sstevel@tonic-gate (void) pool_value_set_name(&val, c_type); 16817c478bd9Sstevel@tonic-gate 16827c478bd9Sstevel@tonic-gate /* 16837c478bd9Sstevel@tonic-gate * Check that there are available resources on this 16847c478bd9Sstevel@tonic-gate * system for this configuration to be applied. Find 16857c478bd9Sstevel@tonic-gate * each resource type and then find all resources of 16867c478bd9Sstevel@tonic-gate * each type and total ".min". Find all available 16877c478bd9Sstevel@tonic-gate * resources and ensure >= total min. 16887c478bd9Sstevel@tonic-gate */ 16897c478bd9Sstevel@tonic-gate 16907c478bd9Sstevel@tonic-gate available = 0; 16917c478bd9Sstevel@tonic-gate required = delta; 16927c478bd9Sstevel@tonic-gate 16937c478bd9Sstevel@tonic-gate if ((rl = (pool_query_resources(conf, &nelem, pvals))) == NULL) 16947c478bd9Sstevel@tonic-gate return (PO_FAIL); 16957c478bd9Sstevel@tonic-gate 16967c478bd9Sstevel@tonic-gate for (i = 0; i < nelem; i++) { 16977c478bd9Sstevel@tonic-gate if (pool_get_ns_property(TO_ELEM(rl[i]), prop, 16987c478bd9Sstevel@tonic-gate &val1) == POC_INVAL || 16997c478bd9Sstevel@tonic-gate pool_value_get_uint64(&val1, &uval) != PO_SUCCESS) { 17007c478bd9Sstevel@tonic-gate free(rl); 17017c478bd9Sstevel@tonic-gate return (PO_FAIL); 17027c478bd9Sstevel@tonic-gate } 17037c478bd9Sstevel@tonic-gate /* 17047c478bd9Sstevel@tonic-gate * Watch out for overflow 17057c478bd9Sstevel@tonic-gate */ 17067c478bd9Sstevel@tonic-gate if (required + uval < required) { 17077c478bd9Sstevel@tonic-gate required = UINT64_MAX; 17087c478bd9Sstevel@tonic-gate break; 17097c478bd9Sstevel@tonic-gate } else 17107c478bd9Sstevel@tonic-gate required += uval; 17117c478bd9Sstevel@tonic-gate } 17127c478bd9Sstevel@tonic-gate 17137c478bd9Sstevel@tonic-gate if (conf_is_dynamic(conf) == PO_TRUE) { 17147c478bd9Sstevel@tonic-gate dyn = (pool_conf_t *)conf; 17157c478bd9Sstevel@tonic-gate } else { 17167c478bd9Sstevel@tonic-gate free(rl); 17177c478bd9Sstevel@tonic-gate if ((dyn = pool_conf_alloc()) == NULL) 17187c478bd9Sstevel@tonic-gate return (PO_FAIL); 17197c478bd9Sstevel@tonic-gate if (pool_conf_open(dyn, pool_dynamic_location(), PO_RDONLY) != 17207c478bd9Sstevel@tonic-gate PO_SUCCESS) { 17217c478bd9Sstevel@tonic-gate pool_conf_free(dyn); 17227c478bd9Sstevel@tonic-gate return (PO_FAIL); 17237c478bd9Sstevel@tonic-gate } 17247c478bd9Sstevel@tonic-gate if ((rl = (pool_query_resources(dyn, &nelem, pvals))) == 17257c478bd9Sstevel@tonic-gate NULL) { 17267c478bd9Sstevel@tonic-gate (void) pool_conf_close(dyn); 17277c478bd9Sstevel@tonic-gate pool_conf_free(dyn); 17287c478bd9Sstevel@tonic-gate return (PO_FAIL); 17297c478bd9Sstevel@tonic-gate } 17307c478bd9Sstevel@tonic-gate } 17317c478bd9Sstevel@tonic-gate for (i = 0; i < nelem; i++) { 17327c478bd9Sstevel@tonic-gate if (pool_get_ns_property(TO_ELEM(rl[i]), c_size_prop, 17337c478bd9Sstevel@tonic-gate &val1) == POC_INVAL || 17347c478bd9Sstevel@tonic-gate pool_value_get_uint64(&val1, &uval) != PO_SUCCESS) { 17357c478bd9Sstevel@tonic-gate free(rl); 17367c478bd9Sstevel@tonic-gate if (conf != dyn) { 17377c478bd9Sstevel@tonic-gate (void) pool_conf_close(dyn); 17387c478bd9Sstevel@tonic-gate pool_conf_free(dyn); 17397c478bd9Sstevel@tonic-gate } 17407c478bd9Sstevel@tonic-gate return (PO_FAIL); 17417c478bd9Sstevel@tonic-gate } 17427c478bd9Sstevel@tonic-gate available += uval; 17437c478bd9Sstevel@tonic-gate } 17447c478bd9Sstevel@tonic-gate free(rl); 17457c478bd9Sstevel@tonic-gate if (conf != dyn) { 17467c478bd9Sstevel@tonic-gate (void) pool_conf_close(dyn); 17477c478bd9Sstevel@tonic-gate pool_conf_free(dyn); 17487c478bd9Sstevel@tonic-gate } 17497c478bd9Sstevel@tonic-gate if (strcmp(prop, c_min_prop) == 0) { 17507c478bd9Sstevel@tonic-gate if (available < required) { 17517c478bd9Sstevel@tonic-gate pool_seterror(POE_INVALID_CONF); 17527c478bd9Sstevel@tonic-gate return (PO_FAIL); 17537c478bd9Sstevel@tonic-gate } 17547c478bd9Sstevel@tonic-gate } else { 17557c478bd9Sstevel@tonic-gate if (available > required) { 17567c478bd9Sstevel@tonic-gate pool_seterror(POE_INVALID_CONF); 17577c478bd9Sstevel@tonic-gate return (PO_FAIL); 17587c478bd9Sstevel@tonic-gate } 17597c478bd9Sstevel@tonic-gate } 17607c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 17617c478bd9Sstevel@tonic-gate } 17627c478bd9Sstevel@tonic-gate 17637c478bd9Sstevel@tonic-gate /* 17647c478bd9Sstevel@tonic-gate * If _libpool_debug is set, printf the debug message to stderr with an 17657c478bd9Sstevel@tonic-gate * appropriate prefix in front of it. 17667c478bd9Sstevel@tonic-gate */ 17677c478bd9Sstevel@tonic-gate void 17687c478bd9Sstevel@tonic-gate do_dprintf(const char *format, va_list ap) 17697c478bd9Sstevel@tonic-gate { 17707c478bd9Sstevel@tonic-gate if (_libpool_debug) { 17717c478bd9Sstevel@tonic-gate (void) fputs("libpool DEBUG: ", stderr); 17727c478bd9Sstevel@tonic-gate (void) vfprintf(stderr, format, ap); 17737c478bd9Sstevel@tonic-gate } 17747c478bd9Sstevel@tonic-gate } 17757c478bd9Sstevel@tonic-gate 17767c478bd9Sstevel@tonic-gate /*PRINTFLIKE1*/ 17777c478bd9Sstevel@tonic-gate void 17787c478bd9Sstevel@tonic-gate dprintf(const char *format, ...) 17797c478bd9Sstevel@tonic-gate { 17807c478bd9Sstevel@tonic-gate if (_libpool_debug) { 17817c478bd9Sstevel@tonic-gate va_list alist; 17827c478bd9Sstevel@tonic-gate va_start(alist, format); 17837c478bd9Sstevel@tonic-gate do_dprintf(format, alist); 17847c478bd9Sstevel@tonic-gate va_end(alist); 17857c478bd9Sstevel@tonic-gate } 17867c478bd9Sstevel@tonic-gate } 17877c478bd9Sstevel@tonic-gate 17887c478bd9Sstevel@tonic-gate /* 17897c478bd9Sstevel@tonic-gate * log_alloc() allocates a new, empty transaction log. 17907c478bd9Sstevel@tonic-gate * 17917c478bd9Sstevel@tonic-gate * Returns a pointer to the new log or NULL on failure. 17927c478bd9Sstevel@tonic-gate */ 17937c478bd9Sstevel@tonic-gate log_t * 17947c478bd9Sstevel@tonic-gate log_alloc(pool_conf_t *conf) 17957c478bd9Sstevel@tonic-gate { 17967c478bd9Sstevel@tonic-gate log_t *l; 17977c478bd9Sstevel@tonic-gate 17987c478bd9Sstevel@tonic-gate if ((l = calloc(1, sizeof (log_t))) == NULL) { 17997c478bd9Sstevel@tonic-gate pool_seterror(POE_SYSTEM); 18007c478bd9Sstevel@tonic-gate return (NULL); 18017c478bd9Sstevel@tonic-gate } 18027c478bd9Sstevel@tonic-gate l->l_state = LS_DO; 18037c478bd9Sstevel@tonic-gate l->l_conf = conf; 18047c478bd9Sstevel@tonic-gate if ((l->l_sentinel = log_item_alloc(l, 0, NULL)) 18057c478bd9Sstevel@tonic-gate == NULL) { 18067c478bd9Sstevel@tonic-gate free(l); 18077c478bd9Sstevel@tonic-gate pool_seterror(POE_SYSTEM); 18087c478bd9Sstevel@tonic-gate return (NULL); 18097c478bd9Sstevel@tonic-gate } 18107c478bd9Sstevel@tonic-gate l->l_sentinel->li_next = l->l_sentinel; 18117c478bd9Sstevel@tonic-gate l->l_sentinel->li_prev = l->l_sentinel; 18127c478bd9Sstevel@tonic-gate 18137c478bd9Sstevel@tonic-gate return (l); 18147c478bd9Sstevel@tonic-gate } 18157c478bd9Sstevel@tonic-gate 18167c478bd9Sstevel@tonic-gate /* 18177c478bd9Sstevel@tonic-gate * log_free() reclaims the resources associated with a transaction log. 18187c478bd9Sstevel@tonic-gate */ 18197c478bd9Sstevel@tonic-gate void 18207c478bd9Sstevel@tonic-gate log_free(log_t *l) 18217c478bd9Sstevel@tonic-gate { 18227c478bd9Sstevel@tonic-gate (void) log_walk(l, log_item_free); 18237c478bd9Sstevel@tonic-gate (void) log_item_free(l->l_sentinel); 18247c478bd9Sstevel@tonic-gate free(l); 18257c478bd9Sstevel@tonic-gate } 18267c478bd9Sstevel@tonic-gate /* 18277c478bd9Sstevel@tonic-gate * log_empty() removes all items from a transaction log. It is the 18287c478bd9Sstevel@tonic-gate * users responsibility to ensure that any resources associated with 18297c478bd9Sstevel@tonic-gate * an item are reclaimed before this function is invoked. 18307c478bd9Sstevel@tonic-gate */ 18317c478bd9Sstevel@tonic-gate void 18327c478bd9Sstevel@tonic-gate log_empty(log_t *l) 18337c478bd9Sstevel@tonic-gate { 18347c478bd9Sstevel@tonic-gate (void) log_walk(l, log_item_free); 18357c478bd9Sstevel@tonic-gate } 18367c478bd9Sstevel@tonic-gate 18377c478bd9Sstevel@tonic-gate /* 18387c478bd9Sstevel@tonic-gate * log_walk() visits each log item in turn and executes the supplied action 18397c478bd9Sstevel@tonic-gate * using the item as a parameter. If no action is supplied, then the item 18407c478bd9Sstevel@tonic-gate * uses it's own stored action. 18417c478bd9Sstevel@tonic-gate * 18427c478bd9Sstevel@tonic-gate * Returns PO_SUCCESS/PO_FAIL 18437c478bd9Sstevel@tonic-gate */ 18447c478bd9Sstevel@tonic-gate int 18457c478bd9Sstevel@tonic-gate log_walk(log_t *l, log_item_action_t action) 18467c478bd9Sstevel@tonic-gate { 18477c478bd9Sstevel@tonic-gate log_item_t *li, *li_next; 18487c478bd9Sstevel@tonic-gate 18497c478bd9Sstevel@tonic-gate li = l->l_sentinel->li_next; 18507c478bd9Sstevel@tonic-gate while (li != l->l_sentinel) { 18517c478bd9Sstevel@tonic-gate li_next = li->li_next; 18527c478bd9Sstevel@tonic-gate if ((action(li)) != PO_SUCCESS) 18537c478bd9Sstevel@tonic-gate return (PO_FAIL); 18547c478bd9Sstevel@tonic-gate li = li_next; 18557c478bd9Sstevel@tonic-gate } 18567c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 18577c478bd9Sstevel@tonic-gate } 18587c478bd9Sstevel@tonic-gate 18597c478bd9Sstevel@tonic-gate /* 18607c478bd9Sstevel@tonic-gate * log_reverse_walk() visits each log item in turn (in reverse order) 18617c478bd9Sstevel@tonic-gate * and executes the supplied action using the item as a parameter. 18627c478bd9Sstevel@tonic-gate * 18637c478bd9Sstevel@tonic-gate * Returns PO_SUCCESS/PO_FAIL 18647c478bd9Sstevel@tonic-gate */ 18657c478bd9Sstevel@tonic-gate int 18667c478bd9Sstevel@tonic-gate log_reverse_walk(log_t *l, log_item_action_t action) 18677c478bd9Sstevel@tonic-gate { 18687c478bd9Sstevel@tonic-gate log_item_t *li, *li_prev; 18697c478bd9Sstevel@tonic-gate 18707c478bd9Sstevel@tonic-gate li = l->l_sentinel->li_prev; 18717c478bd9Sstevel@tonic-gate while (li != l->l_sentinel) { 18727c478bd9Sstevel@tonic-gate li_prev = li->li_prev; 18737c478bd9Sstevel@tonic-gate if ((action(li)) != PO_SUCCESS) 18747c478bd9Sstevel@tonic-gate return (PO_FAIL); 18757c478bd9Sstevel@tonic-gate li = li_prev; 18767c478bd9Sstevel@tonic-gate } 18777c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 18787c478bd9Sstevel@tonic-gate } 18797c478bd9Sstevel@tonic-gate 18807c478bd9Sstevel@tonic-gate /* 18817c478bd9Sstevel@tonic-gate * log_size() returns the size of the log, i.e. the number of items pending in 18827c478bd9Sstevel@tonic-gate * the log. 18837c478bd9Sstevel@tonic-gate */ 18847c478bd9Sstevel@tonic-gate uint_t 18857c478bd9Sstevel@tonic-gate log_size(log_t *l) 18867c478bd9Sstevel@tonic-gate { 18877c478bd9Sstevel@tonic-gate log_item_t *li; 18887c478bd9Sstevel@tonic-gate uint_t size = 0; 18897c478bd9Sstevel@tonic-gate 18907c478bd9Sstevel@tonic-gate for (li = l->l_sentinel->li_next; li != l->l_sentinel; li = li->li_next) 18917c478bd9Sstevel@tonic-gate size++; 18927c478bd9Sstevel@tonic-gate return (size); 18937c478bd9Sstevel@tonic-gate } 18947c478bd9Sstevel@tonic-gate 18957c478bd9Sstevel@tonic-gate /* 18967c478bd9Sstevel@tonic-gate * log_append() allocates a new log item to hold the supplied details and 18977c478bd9Sstevel@tonic-gate * appends the newly created item to the supplied log. 18987c478bd9Sstevel@tonic-gate * 18997c478bd9Sstevel@tonic-gate * Returns PO_SUCCESS/PO_FAIL 19007c478bd9Sstevel@tonic-gate */ 19017c478bd9Sstevel@tonic-gate int 19027c478bd9Sstevel@tonic-gate log_append(log_t *l, int op, void *details) 19037c478bd9Sstevel@tonic-gate { 19047c478bd9Sstevel@tonic-gate log_item_t *li; 19057c478bd9Sstevel@tonic-gate 19067c478bd9Sstevel@tonic-gate if ((li = log_item_alloc(l, op, details)) == NULL) { 19077c478bd9Sstevel@tonic-gate l->l_state = LS_UNDO; 19087c478bd9Sstevel@tonic-gate return (PO_FAIL); 19097c478bd9Sstevel@tonic-gate } 19107c478bd9Sstevel@tonic-gate /* 19117c478bd9Sstevel@tonic-gate * Link it in 19127c478bd9Sstevel@tonic-gate */ 19137c478bd9Sstevel@tonic-gate li->li_prev = l->l_sentinel->li_prev; 19147c478bd9Sstevel@tonic-gate li->li_next = l->l_sentinel; 19157c478bd9Sstevel@tonic-gate l->l_sentinel->li_prev->li_next = li; 19167c478bd9Sstevel@tonic-gate l->l_sentinel->li_prev = li; 19177c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 19187c478bd9Sstevel@tonic-gate } 19197c478bd9Sstevel@tonic-gate 19207c478bd9Sstevel@tonic-gate /* 19217c478bd9Sstevel@tonic-gate * log_item_alloc() allocates a new transaction log item. The item should be 19227c478bd9Sstevel@tonic-gate * used to store details about a transaction which may need to be undone if 19237c478bd9Sstevel@tonic-gate * commit processing fails. 19247c478bd9Sstevel@tonic-gate * 19257c478bd9Sstevel@tonic-gate * Returns a pointer to a new transaction log item or NULL. 19267c478bd9Sstevel@tonic-gate */ 19277c478bd9Sstevel@tonic-gate log_item_t * 19287c478bd9Sstevel@tonic-gate log_item_alloc(log_t *l, int op, void *details) 19297c478bd9Sstevel@tonic-gate { 19307c478bd9Sstevel@tonic-gate log_item_t *li; 19317c478bd9Sstevel@tonic-gate 19327c478bd9Sstevel@tonic-gate if ((li = malloc(sizeof (log_item_t))) == NULL) { 19337c478bd9Sstevel@tonic-gate pool_seterror(POE_SYSTEM); 19347c478bd9Sstevel@tonic-gate return (NULL); 19357c478bd9Sstevel@tonic-gate } 19367c478bd9Sstevel@tonic-gate 19377c478bd9Sstevel@tonic-gate (void) memset(li, 0, sizeof (log_item_t)); 19387c478bd9Sstevel@tonic-gate li->li_log = l; 19397c478bd9Sstevel@tonic-gate li->li_op = op; 19407c478bd9Sstevel@tonic-gate li->li_details = details; 19417c478bd9Sstevel@tonic-gate li->li_state = LS_DO; 19427c478bd9Sstevel@tonic-gate 19437c478bd9Sstevel@tonic-gate return (li); 19447c478bd9Sstevel@tonic-gate } 19457c478bd9Sstevel@tonic-gate 19467c478bd9Sstevel@tonic-gate /* 19477c478bd9Sstevel@tonic-gate * log_item_free() reclaims the resources associated with a log_item_t. 19487c478bd9Sstevel@tonic-gate */ 19497c478bd9Sstevel@tonic-gate int 19507c478bd9Sstevel@tonic-gate log_item_free(log_item_t *li) 19517c478bd9Sstevel@tonic-gate { 19527c478bd9Sstevel@tonic-gate li->li_prev->li_next = li->li_next; 19537c478bd9Sstevel@tonic-gate li->li_next->li_prev = li->li_prev; 19547c478bd9Sstevel@tonic-gate free(li); 19557c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 19567c478bd9Sstevel@tonic-gate } 19577c478bd9Sstevel@tonic-gate 19587c478bd9Sstevel@tonic-gate /* 19597c478bd9Sstevel@tonic-gate * atom_string() checks the string table to see if a string is already 19607c478bd9Sstevel@tonic-gate * stored. If it is, return a pointer to it. If not, duplicate the 19617c478bd9Sstevel@tonic-gate * string and return a pointer to the duplicate. 19627c478bd9Sstevel@tonic-gate */ 19637c478bd9Sstevel@tonic-gate const char * 19647c478bd9Sstevel@tonic-gate atom_string(const char *s) 19657c478bd9Sstevel@tonic-gate { 19667c478bd9Sstevel@tonic-gate atom_t *atom; 19677c478bd9Sstevel@tonic-gate 19687c478bd9Sstevel@tonic-gate /* 19697c478bd9Sstevel@tonic-gate * atom_init() must have completed successfully 19707c478bd9Sstevel@tonic-gate */ 19717c478bd9Sstevel@tonic-gate atom_init(); 19727c478bd9Sstevel@tonic-gate (void) mutex_lock(&_atom_lock); 19737c478bd9Sstevel@tonic-gate if ((atom = dict_get(_pv_atoms, s)) == NULL) { 19747c478bd9Sstevel@tonic-gate if ((atom = calloc(1, sizeof (atom_t))) == NULL) { 19757c478bd9Sstevel@tonic-gate pool_seterror(POE_SYSTEM); 19767c478bd9Sstevel@tonic-gate (void) mutex_unlock(&_atom_lock); 19777c478bd9Sstevel@tonic-gate return (NULL); 19787c478bd9Sstevel@tonic-gate } 19797c478bd9Sstevel@tonic-gate if ((atom->a_string = strdup(s)) == NULL) { 19807c478bd9Sstevel@tonic-gate (void) mutex_unlock(&_atom_lock); 19817c478bd9Sstevel@tonic-gate free(atom); 19827c478bd9Sstevel@tonic-gate pool_seterror(POE_SYSTEM); 19837c478bd9Sstevel@tonic-gate return (NULL); 19847c478bd9Sstevel@tonic-gate } 19857c478bd9Sstevel@tonic-gate (void) dict_put(_pv_atoms, atom->a_string, atom); 19867c478bd9Sstevel@tonic-gate } 19877c478bd9Sstevel@tonic-gate atom->a_count++; 19887c478bd9Sstevel@tonic-gate (void) mutex_unlock(&_atom_lock); 19897c478bd9Sstevel@tonic-gate return (atom->a_string); 19907c478bd9Sstevel@tonic-gate } 19917c478bd9Sstevel@tonic-gate 19927c478bd9Sstevel@tonic-gate /* 19937c478bd9Sstevel@tonic-gate * atom_free() decrements the reference count for the supplied 19947c478bd9Sstevel@tonic-gate * string. If the reference count reaches zero, then the atom is 19957c478bd9Sstevel@tonic-gate * destroyed. 19967c478bd9Sstevel@tonic-gate */ 19977c478bd9Sstevel@tonic-gate void 19987c478bd9Sstevel@tonic-gate atom_free(const char *s) 19997c478bd9Sstevel@tonic-gate { 20007c478bd9Sstevel@tonic-gate atom_t *atom; 20017c478bd9Sstevel@tonic-gate 20027c478bd9Sstevel@tonic-gate (void) mutex_lock(&_atom_lock); 20037c478bd9Sstevel@tonic-gate if ((atom = dict_get(_pv_atoms, s)) != NULL) { 20047c478bd9Sstevel@tonic-gate if (--atom->a_count == 0) { 20057c478bd9Sstevel@tonic-gate (void) dict_remove(_pv_atoms, s); 20067c478bd9Sstevel@tonic-gate free(atom->a_string); 20077c478bd9Sstevel@tonic-gate free(atom); 20087c478bd9Sstevel@tonic-gate } 20097c478bd9Sstevel@tonic-gate } 20107c478bd9Sstevel@tonic-gate (void) mutex_unlock(&_atom_lock); 20117c478bd9Sstevel@tonic-gate } 20127c478bd9Sstevel@tonic-gate 20137c478bd9Sstevel@tonic-gate #ifdef DEBUG 20147c478bd9Sstevel@tonic-gate /* 20157c478bd9Sstevel@tonic-gate * log_item_dprintf() prints the contents of the supplied log item using the 20167c478bd9Sstevel@tonic-gate * pools dprintf() trace mechanism. 20177c478bd9Sstevel@tonic-gate * 20187c478bd9Sstevel@tonic-gate * Returns PO_SUCCESS 20197c478bd9Sstevel@tonic-gate */ 20207c478bd9Sstevel@tonic-gate void 20217c478bd9Sstevel@tonic-gate log_item_dprintf(log_item_t *li) 20227c478bd9Sstevel@tonic-gate { 20237c478bd9Sstevel@tonic-gate dprintf("LOGDUMP: %d operation, %p\n", li->li_op, li->li_details); 20247c478bd9Sstevel@tonic-gate } 20257c478bd9Sstevel@tonic-gate 20267c478bd9Sstevel@tonic-gate /* 20277c478bd9Sstevel@tonic-gate * log_item_dprintf() prints the contents of the supplied log item using the 20287c478bd9Sstevel@tonic-gate * pools dprintf() trace mechanism. 20297c478bd9Sstevel@tonic-gate * 20307c478bd9Sstevel@tonic-gate * Returns PO_SUCCESS 20317c478bd9Sstevel@tonic-gate */ 20327c478bd9Sstevel@tonic-gate void 20337c478bd9Sstevel@tonic-gate pool_elem_dprintf(const pool_elem_t *pe) 20347c478bd9Sstevel@tonic-gate { 20357c478bd9Sstevel@tonic-gate if (pool_elem_class(pe) != PEC_COMP) { 20367c478bd9Sstevel@tonic-gate const char *name = elem_get_name(pe); 20377c478bd9Sstevel@tonic-gate dprintf("element type: %s name: %s\n", 20387c478bd9Sstevel@tonic-gate pool_elem_class_string(pe), name); 20397c478bd9Sstevel@tonic-gate free((void *)name); 20407c478bd9Sstevel@tonic-gate } else { 20417c478bd9Sstevel@tonic-gate id_t sys_id = elem_get_sysid(pe); 20427c478bd9Sstevel@tonic-gate dprintf("element type: %s sys_id: %d\n", 20437c478bd9Sstevel@tonic-gate pool_elem_class_string(pe), sys_id); 20447c478bd9Sstevel@tonic-gate } 20457c478bd9Sstevel@tonic-gate } 20467c478bd9Sstevel@tonic-gate #endif /* DEBUG */ 2047