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 568ae7850Sgarypen * Common Development and Distribution License (the "License"). 668ae7850Sgarypen * 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 */ 2168ae7850Sgarypen 227c478bd9Sstevel@tonic-gate /* 2368ae7850Sgarypen * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <assert.h> 307c478bd9Sstevel@tonic-gate #include <stdio.h> 317c478bd9Sstevel@tonic-gate #include <stdlib.h> 327c478bd9Sstevel@tonic-gate #include <string.h> 337c478bd9Sstevel@tonic-gate #include <thread.h> 347c478bd9Sstevel@tonic-gate #include <synch.h> 357c478bd9Sstevel@tonic-gate #include <unistd.h> 367c478bd9Sstevel@tonic-gate #include <stropts.h> 377c478bd9Sstevel@tonic-gate #include <fcntl.h> 387c478bd9Sstevel@tonic-gate #include <note.h> 397c478bd9Sstevel@tonic-gate #include <errno.h> 407c478bd9Sstevel@tonic-gate #include <ctype.h> 417c478bd9Sstevel@tonic-gate #include <libintl.h> 42*c1c0ebd5Ssl108498 #include <libscf.h> 437c478bd9Sstevel@tonic-gate #include <pool.h> 447c478bd9Sstevel@tonic-gate #include <signal.h> 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate #include <sys/pool.h> 477c478bd9Sstevel@tonic-gate #include <sys/priocntl.h> 487c478bd9Sstevel@tonic-gate #include <sys/types.h> 497c478bd9Sstevel@tonic-gate #include <sys/stat.h> 507c478bd9Sstevel@tonic-gate #include <sys/wait.h> 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate #include "pool_internal.h" 537c478bd9Sstevel@tonic-gate #include "pool_impl.h" 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate /* 567c478bd9Sstevel@tonic-gate * libpool Interface Routines 577c478bd9Sstevel@tonic-gate * 587c478bd9Sstevel@tonic-gate * pool.c implements (most of) the external interface to libpool 597c478bd9Sstevel@tonic-gate * users. Some of the interface is implemented in pool_internal.c for 607c478bd9Sstevel@tonic-gate * reasons of internal code organisation. The core requirements for 617c478bd9Sstevel@tonic-gate * pool.c are: 627c478bd9Sstevel@tonic-gate * 637c478bd9Sstevel@tonic-gate * Data Abstraction 647c478bd9Sstevel@tonic-gate * 657c478bd9Sstevel@tonic-gate * The abstraction of the actual datastore so that no details of the 667c478bd9Sstevel@tonic-gate * underlying data representation mechanism are revealed to users of 677c478bd9Sstevel@tonic-gate * the library. For instance, the fact that we use the kernel or files 687c478bd9Sstevel@tonic-gate * to store our configurations is completely abstracted via the 697c478bd9Sstevel@tonic-gate * various libpool APIs. 707c478bd9Sstevel@tonic-gate * 717c478bd9Sstevel@tonic-gate * External Interaction 727c478bd9Sstevel@tonic-gate * 737c478bd9Sstevel@tonic-gate * libpool users manipulate configuration components via the API 747c478bd9Sstevel@tonic-gate * defined in pool.h. Most functions in this file act as interceptors, 757c478bd9Sstevel@tonic-gate * validating parameters before redirecting the request into a 767c478bd9Sstevel@tonic-gate * specific datastore implementation for the actual work to be done. 777c478bd9Sstevel@tonic-gate * 787c478bd9Sstevel@tonic-gate * These main sets of requirements have driven the design so that it 797c478bd9Sstevel@tonic-gate * is possible to replace the entire datastore type without having to 807c478bd9Sstevel@tonic-gate * modify the external (or internal provider) APIs. It is possible to 817c478bd9Sstevel@tonic-gate * modify the storage technology used by libpool by implementing a new 827c478bd9Sstevel@tonic-gate * set of datastore provider operations. Simply modify the 837c478bd9Sstevel@tonic-gate * pool_conf_open() routine to establish a new datastore as the 847c478bd9Sstevel@tonic-gate * provider for a configuration. 857c478bd9Sstevel@tonic-gate * 867c478bd9Sstevel@tonic-gate * The key components in a libpool configuration are : 877c478bd9Sstevel@tonic-gate * pool_conf_t - This represents a complete configuration instance 887c478bd9Sstevel@tonic-gate * pool_t - A pool inside a configuration 897c478bd9Sstevel@tonic-gate * pool_resource_t - A resource inside a configuration 907c478bd9Sstevel@tonic-gate * pool_component_t - A component of a resource 917c478bd9Sstevel@tonic-gate * 927c478bd9Sstevel@tonic-gate */ 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate /* 957c478bd9Sstevel@tonic-gate * Used to control transfer setup. 967c478bd9Sstevel@tonic-gate */ 977c478bd9Sstevel@tonic-gate #define XFER_FAIL PO_FAIL 987c478bd9Sstevel@tonic-gate #define XFER_SUCCESS PO_SUCCESS 997c478bd9Sstevel@tonic-gate #define XFER_CONTINUE 1 1007c478bd9Sstevel@tonic-gate 10126d8ba22Sgarypen #define SMF_SVC_INSTANCE "svc:/system/pools:default" 1027c478bd9Sstevel@tonic-gate #define E_ERROR 1 /* Exit status for error */ 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate #ifndef TEXT_DOMAIN 1057c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" 1067c478bd9Sstevel@tonic-gate #endif /* TEXT_DOMAIN */ 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate const char pool_info_location[] = "/dev/pool"; 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate /* 1117c478bd9Sstevel@tonic-gate * Static data 1127c478bd9Sstevel@tonic-gate */ 1137c478bd9Sstevel@tonic-gate static const char static_location[] = "/etc/pooladm.conf"; 1147c478bd9Sstevel@tonic-gate static const char dynamic_location[] = "/dev/poolctl"; 1157c478bd9Sstevel@tonic-gate static mutex_t keylock; 1167c478bd9Sstevel@tonic-gate static thread_key_t errkey; 1177c478bd9Sstevel@tonic-gate static int keyonce = 0; 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate /* 1207c478bd9Sstevel@tonic-gate * libpool error code 1217c478bd9Sstevel@tonic-gate */ 1227c478bd9Sstevel@tonic-gate static int pool_errval = POE_OK; 1237c478bd9Sstevel@tonic-gate 1247c478bd9Sstevel@tonic-gate /* 1257c478bd9Sstevel@tonic-gate * libpool version 1267c478bd9Sstevel@tonic-gate */ 1277c478bd9Sstevel@tonic-gate static uint_t pool_workver = POOL_VER_CURRENT; 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate static const char *data_type_tags[] = { 1307c478bd9Sstevel@tonic-gate "uint", 1317c478bd9Sstevel@tonic-gate "int", 1327c478bd9Sstevel@tonic-gate "float", 1337c478bd9Sstevel@tonic-gate "boolean", 1347c478bd9Sstevel@tonic-gate "string" 1357c478bd9Sstevel@tonic-gate }; 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate /* 1387c478bd9Sstevel@tonic-gate * static functions 1397c478bd9Sstevel@tonic-gate */ 1407c478bd9Sstevel@tonic-gate static int pool_elem_remove(pool_elem_t *); 1417c478bd9Sstevel@tonic-gate static int is_valid_prop_name(const char *); 1427c478bd9Sstevel@tonic-gate static int prop_buf_build_cb(pool_conf_t *, pool_elem_t *, const char *, 1437c478bd9Sstevel@tonic-gate pool_value_t *, void *); 1447c478bd9Sstevel@tonic-gate static char *pool_base_info(const pool_elem_t *, char_buf_t *, int); 1457c478bd9Sstevel@tonic-gate static int choose_components(pool_resource_t *, pool_resource_t *, uint64_t); 1467c478bd9Sstevel@tonic-gate static int pool_conf_check(const pool_conf_t *); 1477c478bd9Sstevel@tonic-gate static void free_value_list(int, pool_value_t **); 1487c478bd9Sstevel@tonic-gate static int setup_transfer(pool_conf_t *, pool_resource_t *, pool_resource_t *, 1497c478bd9Sstevel@tonic-gate uint64_t, uint64_t *, uint64_t *); 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate /* 1527c478bd9Sstevel@tonic-gate * Return the "static" location string for libpool. 1537c478bd9Sstevel@tonic-gate */ 1547c478bd9Sstevel@tonic-gate const char * 1557c478bd9Sstevel@tonic-gate pool_static_location(void) 1567c478bd9Sstevel@tonic-gate { 1577c478bd9Sstevel@tonic-gate return (static_location); 1587c478bd9Sstevel@tonic-gate } 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gate /* 1617c478bd9Sstevel@tonic-gate * Return the "dynamic" location string for libpool. 1627c478bd9Sstevel@tonic-gate */ 1637c478bd9Sstevel@tonic-gate const char * 1647c478bd9Sstevel@tonic-gate pool_dynamic_location(void) 1657c478bd9Sstevel@tonic-gate { 1667c478bd9Sstevel@tonic-gate return (dynamic_location); 1677c478bd9Sstevel@tonic-gate } 1687c478bd9Sstevel@tonic-gate 1697c478bd9Sstevel@tonic-gate /* 1707c478bd9Sstevel@tonic-gate * Return the status for a configuration. If the configuration has 1717c478bd9Sstevel@tonic-gate * been successfully opened, then the status will be POF_VALID or 1727c478bd9Sstevel@tonic-gate * POF_DESTROY. If the configuration failed to open properly or has 1737c478bd9Sstevel@tonic-gate * been closed or removed, then the status will be POF_INVALID. 1747c478bd9Sstevel@tonic-gate */ 1757c478bd9Sstevel@tonic-gate pool_conf_state_t 1767c478bd9Sstevel@tonic-gate pool_conf_status(const pool_conf_t *conf) 1777c478bd9Sstevel@tonic-gate { 1787c478bd9Sstevel@tonic-gate return (conf->pc_state); 1797c478bd9Sstevel@tonic-gate } 1807c478bd9Sstevel@tonic-gate 1817c478bd9Sstevel@tonic-gate /* 1827c478bd9Sstevel@tonic-gate * Bind idtype id to the pool name. 1837c478bd9Sstevel@tonic-gate */ 1847c478bd9Sstevel@tonic-gate int 1857c478bd9Sstevel@tonic-gate pool_set_binding(const char *pool_name, idtype_t idtype, id_t id) 1867c478bd9Sstevel@tonic-gate { 1877c478bd9Sstevel@tonic-gate pool_conf_t *conf; 1887c478bd9Sstevel@tonic-gate int result; 1897c478bd9Sstevel@tonic-gate 1907c478bd9Sstevel@tonic-gate if ((conf = pool_conf_alloc()) == NULL) 1917c478bd9Sstevel@tonic-gate return (PO_FAIL); 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate if (pool_conf_open(conf, pool_dynamic_location(), PO_RDONLY) < 0) { 1947c478bd9Sstevel@tonic-gate pool_conf_free(conf); 1957c478bd9Sstevel@tonic-gate pool_seterror(POE_INVALID_CONF); 1967c478bd9Sstevel@tonic-gate return (PO_FAIL); 1977c478bd9Sstevel@tonic-gate } 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate result = conf->pc_prov->pc_set_binding(conf, pool_name, idtype, id); 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate (void) pool_conf_close(conf); 2027c478bd9Sstevel@tonic-gate pool_conf_free(conf); 2037c478bd9Sstevel@tonic-gate return (result); 2047c478bd9Sstevel@tonic-gate } 2057c478bd9Sstevel@tonic-gate 2067c478bd9Sstevel@tonic-gate /* 2077c478bd9Sstevel@tonic-gate * pool_get_resource_binding() returns the binding for a pid to the supplied 2087c478bd9Sstevel@tonic-gate * type of resource. If a binding cannot be determined, NULL is returned. 2097c478bd9Sstevel@tonic-gate */ 2107c478bd9Sstevel@tonic-gate char * 2117c478bd9Sstevel@tonic-gate pool_get_resource_binding(const char *sz_type, pid_t pid) 2127c478bd9Sstevel@tonic-gate { 2137c478bd9Sstevel@tonic-gate pool_conf_t *conf; 2147c478bd9Sstevel@tonic-gate char *result; 2157c478bd9Sstevel@tonic-gate pool_resource_elem_class_t type; 2167c478bd9Sstevel@tonic-gate 2177c478bd9Sstevel@tonic-gate if ((type = pool_resource_elem_class_from_string(sz_type)) == 2187c478bd9Sstevel@tonic-gate PREC_INVALID) { 2197c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 2207c478bd9Sstevel@tonic-gate return (NULL); 2217c478bd9Sstevel@tonic-gate } 2227c478bd9Sstevel@tonic-gate 2237c478bd9Sstevel@tonic-gate if ((conf = pool_conf_alloc()) == NULL) 2247c478bd9Sstevel@tonic-gate return (NULL); 2257c478bd9Sstevel@tonic-gate 2267c478bd9Sstevel@tonic-gate if (pool_conf_open(conf, pool_dynamic_location(), PO_RDONLY) 2277c478bd9Sstevel@tonic-gate != PO_SUCCESS) { 2287c478bd9Sstevel@tonic-gate pool_seterror(POE_INVALID_CONF); 2297c478bd9Sstevel@tonic-gate pool_conf_free(conf); 2307c478bd9Sstevel@tonic-gate return (NULL); 2317c478bd9Sstevel@tonic-gate } 2327c478bd9Sstevel@tonic-gate result = conf->pc_prov->pc_get_resource_binding(conf, type, pid); 2337c478bd9Sstevel@tonic-gate (void) pool_conf_close(conf); 2347c478bd9Sstevel@tonic-gate pool_conf_free(conf); 2357c478bd9Sstevel@tonic-gate return (result); 2367c478bd9Sstevel@tonic-gate } 2377c478bd9Sstevel@tonic-gate 2387c478bd9Sstevel@tonic-gate /* 2397c478bd9Sstevel@tonic-gate * pool_get_binding() returns the binding for a pid to a pool. If a 2407c478bd9Sstevel@tonic-gate * binding cannot be determined, NULL is returned. 2417c478bd9Sstevel@tonic-gate */ 2427c478bd9Sstevel@tonic-gate char * 2437c478bd9Sstevel@tonic-gate pool_get_binding(pid_t pid) 2447c478bd9Sstevel@tonic-gate { 2457c478bd9Sstevel@tonic-gate pool_conf_t *conf; 2467c478bd9Sstevel@tonic-gate char *result; 2477c478bd9Sstevel@tonic-gate 2487c478bd9Sstevel@tonic-gate if ((conf = pool_conf_alloc()) == NULL) 2497c478bd9Sstevel@tonic-gate return (NULL); 2507c478bd9Sstevel@tonic-gate 2517c478bd9Sstevel@tonic-gate if (pool_conf_open(conf, pool_dynamic_location(), PO_RDONLY) 2527c478bd9Sstevel@tonic-gate != PO_SUCCESS) { 2537c478bd9Sstevel@tonic-gate pool_seterror(POE_INVALID_CONF); 2547c478bd9Sstevel@tonic-gate pool_conf_free(conf); 2557c478bd9Sstevel@tonic-gate return (NULL); 2567c478bd9Sstevel@tonic-gate } 2577c478bd9Sstevel@tonic-gate result = conf->pc_prov->pc_get_binding(conf, pid); 2587c478bd9Sstevel@tonic-gate (void) pool_conf_close(conf); 2597c478bd9Sstevel@tonic-gate pool_conf_free(conf); 2607c478bd9Sstevel@tonic-gate return (result); 2617c478bd9Sstevel@tonic-gate } 2627c478bd9Sstevel@tonic-gate 2637c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 2647c478bd9Sstevel@tonic-gate int 2657c478bd9Sstevel@tonic-gate prop_buf_build_cb(pool_conf_t *UNUSED, pool_elem_t *pe, const char *name, 2667c478bd9Sstevel@tonic-gate pool_value_t *pval, void *user) 2677c478bd9Sstevel@tonic-gate { 2687c478bd9Sstevel@tonic-gate uint64_t u; 2697c478bd9Sstevel@tonic-gate int64_t i; 2707c478bd9Sstevel@tonic-gate uchar_t bool; 2717c478bd9Sstevel@tonic-gate const char *str; 2727c478bd9Sstevel@tonic-gate double d; 2737c478bd9Sstevel@tonic-gate char_buf_t *cb = (char_buf_t *)user; 2747c478bd9Sstevel@tonic-gate int type = pool_value_get_type(pval); 2757c478bd9Sstevel@tonic-gate 2767c478bd9Sstevel@tonic-gate /* 2777c478bd9Sstevel@tonic-gate * Ignore "type" and "<type>.name" properties as these are not 2787c478bd9Sstevel@tonic-gate * to be displayed by this function 2797c478bd9Sstevel@tonic-gate */ 2807c478bd9Sstevel@tonic-gate if (strcmp(name, c_type) == 0 || 2817c478bd9Sstevel@tonic-gate strcmp(property_name_minus_ns(pe, name), c_name) == 0) 2827c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 2837c478bd9Sstevel@tonic-gate if (append_char_buf(cb, "\n%s\t%s\t%s ", cb->cb_tab_buf, 2847c478bd9Sstevel@tonic-gate data_type_tags[type], name) == PO_FAIL) 2857c478bd9Sstevel@tonic-gate return (PO_FAIL); 2867c478bd9Sstevel@tonic-gate switch (type) { 2877c478bd9Sstevel@tonic-gate case POC_UINT: 2887c478bd9Sstevel@tonic-gate (void) pool_value_get_uint64(pval, &u); 2897c478bd9Sstevel@tonic-gate if (append_char_buf(cb, "%llu", (u_longlong_t)u) == PO_FAIL) 2907c478bd9Sstevel@tonic-gate return (PO_FAIL); 2917c478bd9Sstevel@tonic-gate break; 2927c478bd9Sstevel@tonic-gate case POC_INT: 2937c478bd9Sstevel@tonic-gate (void) pool_value_get_int64(pval, &i); 2947c478bd9Sstevel@tonic-gate if (append_char_buf(cb, "%lld", (longlong_t)i) == PO_FAIL) 2957c478bd9Sstevel@tonic-gate return (PO_FAIL); 2967c478bd9Sstevel@tonic-gate break; 2977c478bd9Sstevel@tonic-gate case POC_STRING: 2987c478bd9Sstevel@tonic-gate (void) pool_value_get_string(pval, &str); 2997c478bd9Sstevel@tonic-gate if (append_char_buf(cb, "%s", str) == PO_FAIL) 3007c478bd9Sstevel@tonic-gate return (PO_FAIL); 3017c478bd9Sstevel@tonic-gate break; 3027c478bd9Sstevel@tonic-gate case POC_BOOL: 3037c478bd9Sstevel@tonic-gate (void) pool_value_get_bool(pval, &bool); 3047c478bd9Sstevel@tonic-gate if (bool == 0) { 3057c478bd9Sstevel@tonic-gate if (append_char_buf(cb, "%s", "false") == PO_FAIL) 3067c478bd9Sstevel@tonic-gate return (PO_FAIL); 3077c478bd9Sstevel@tonic-gate } else { 3087c478bd9Sstevel@tonic-gate if (append_char_buf(cb, "%s", "true") == PO_FAIL) 3097c478bd9Sstevel@tonic-gate return (PO_FAIL); 3107c478bd9Sstevel@tonic-gate } 3117c478bd9Sstevel@tonic-gate break; 3127c478bd9Sstevel@tonic-gate case POC_DOUBLE: 3137c478bd9Sstevel@tonic-gate (void) pool_value_get_double(pval, &d); 3147c478bd9Sstevel@tonic-gate if (append_char_buf(cb, "%g", d) == PO_FAIL) 3157c478bd9Sstevel@tonic-gate return (PO_FAIL); 3167c478bd9Sstevel@tonic-gate break; 3177c478bd9Sstevel@tonic-gate case POC_INVAL: /* Do nothing */ 3187c478bd9Sstevel@tonic-gate break; 3197c478bd9Sstevel@tonic-gate default: 3207c478bd9Sstevel@tonic-gate return (PO_FAIL); 3217c478bd9Sstevel@tonic-gate } 3227c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 3237c478bd9Sstevel@tonic-gate } 3247c478bd9Sstevel@tonic-gate 3257c478bd9Sstevel@tonic-gate /* 3267c478bd9Sstevel@tonic-gate * Return a buffer which describes the element 3277c478bd9Sstevel@tonic-gate * pe is a pointer to the element 3287c478bd9Sstevel@tonic-gate * deep is PO_TRUE/PO_FALSE to indicate whether children should be included 3297c478bd9Sstevel@tonic-gate */ 3307c478bd9Sstevel@tonic-gate char * 3317c478bd9Sstevel@tonic-gate pool_base_info(const pool_elem_t *pe, char_buf_t *cb, int deep) 3327c478bd9Sstevel@tonic-gate { 3337c478bd9Sstevel@tonic-gate const char *sres; 3347c478bd9Sstevel@tonic-gate uint_t i; 3357c478bd9Sstevel@tonic-gate uint_t nelem; 3367c478bd9Sstevel@tonic-gate 3377c478bd9Sstevel@tonic-gate pool_value_t val = POOL_VALUE_INITIALIZER; 3387c478bd9Sstevel@tonic-gate pool_resource_t **rs; 3397c478bd9Sstevel@tonic-gate pool_elem_t *elem; 3407c478bd9Sstevel@tonic-gate pool_conf_t *conf = TO_CONF(pe); 3417c478bd9Sstevel@tonic-gate 3427c478bd9Sstevel@tonic-gate if (cb == NULL) { 3437c478bd9Sstevel@tonic-gate char *ret = NULL; 3447c478bd9Sstevel@tonic-gate 3457c478bd9Sstevel@tonic-gate if ((cb = alloc_char_buf(CB_DEFAULT_LEN)) == NULL) 3467c478bd9Sstevel@tonic-gate return (NULL); 3477c478bd9Sstevel@tonic-gate 3487c478bd9Sstevel@tonic-gate /* 3497c478bd9Sstevel@tonic-gate * Populate the buffer with element details 3507c478bd9Sstevel@tonic-gate */ 3517c478bd9Sstevel@tonic-gate (void) pool_base_info(pe, cb, deep); 3527c478bd9Sstevel@tonic-gate if (cb->cb_buf) 3537c478bd9Sstevel@tonic-gate ret = strdup(cb->cb_buf); 3547c478bd9Sstevel@tonic-gate free_char_buf(cb); 3557c478bd9Sstevel@tonic-gate return (ret); 3567c478bd9Sstevel@tonic-gate } 3577c478bd9Sstevel@tonic-gate 3587c478bd9Sstevel@tonic-gate if (append_char_buf(cb, "\n%s%s", cb->cb_tab_buf, 3597c478bd9Sstevel@tonic-gate pool_elem_class_string(pe)) == PO_FAIL) { 3607c478bd9Sstevel@tonic-gate return (NULL); 3617c478bd9Sstevel@tonic-gate } 3627c478bd9Sstevel@tonic-gate 3637c478bd9Sstevel@tonic-gate if (pool_get_ns_property(pe, c_name, &val) == POC_STRING) { 3647c478bd9Sstevel@tonic-gate (void) pool_value_get_string(&val, &sres); 3657c478bd9Sstevel@tonic-gate if (append_char_buf(cb, " %s", sres) == PO_FAIL) { 3667c478bd9Sstevel@tonic-gate return (NULL); 3677c478bd9Sstevel@tonic-gate } 3687c478bd9Sstevel@tonic-gate } 3697c478bd9Sstevel@tonic-gate 3707c478bd9Sstevel@tonic-gate /* 3717c478bd9Sstevel@tonic-gate * Add in some details about the element 3727c478bd9Sstevel@tonic-gate */ 3737c478bd9Sstevel@tonic-gate if (pool_walk_properties(conf, (pool_elem_t *)pe, cb, 3747c478bd9Sstevel@tonic-gate prop_buf_build_cb) == PO_FAIL) { 3757c478bd9Sstevel@tonic-gate (void) append_char_buf(cb, "\n%s%s\n", cb->cb_tab_buf, 3767c478bd9Sstevel@tonic-gate "Cannot access the properties of this element."); 3777c478bd9Sstevel@tonic-gate return (NULL); 3787c478bd9Sstevel@tonic-gate } 3797c478bd9Sstevel@tonic-gate if (append_char_buf(cb, "%s", "\n") == PO_FAIL) 3807c478bd9Sstevel@tonic-gate return (NULL); 3817c478bd9Sstevel@tonic-gate 3827c478bd9Sstevel@tonic-gate if (pe->pe_class == PEC_POOL) { 3837c478bd9Sstevel@tonic-gate /* 3847c478bd9Sstevel@tonic-gate * A shallow display of a pool only lists the resources by name 3857c478bd9Sstevel@tonic-gate */ 3867c478bd9Sstevel@tonic-gate 3877c478bd9Sstevel@tonic-gate if ((rs = pool_query_pool_resources(conf, pool_elem_pool(pe), 3887c478bd9Sstevel@tonic-gate &nelem, NULL)) == NULL) { 3897c478bd9Sstevel@tonic-gate return (NULL); 3907c478bd9Sstevel@tonic-gate } 3917c478bd9Sstevel@tonic-gate 3927c478bd9Sstevel@tonic-gate for (i = 0; i < nelem; i++) { 3937c478bd9Sstevel@tonic-gate const char *str; 3947c478bd9Sstevel@tonic-gate 3957c478bd9Sstevel@tonic-gate elem = TO_ELEM(rs[i]); 3967c478bd9Sstevel@tonic-gate 3977c478bd9Sstevel@tonic-gate if (append_char_buf(cb, "\t%s%s", cb->cb_tab_buf, 3987c478bd9Sstevel@tonic-gate pool_elem_class_string(elem)) == PO_FAIL) { 3997c478bd9Sstevel@tonic-gate free(rs); 4007c478bd9Sstevel@tonic-gate return (NULL); 4017c478bd9Sstevel@tonic-gate } 4027c478bd9Sstevel@tonic-gate 4037c478bd9Sstevel@tonic-gate if (pool_get_ns_property(elem, c_name, &val) != 4047c478bd9Sstevel@tonic-gate POC_STRING) { 4057c478bd9Sstevel@tonic-gate free(rs); 4067c478bd9Sstevel@tonic-gate pool_seterror(POE_INVALID_CONF); 4077c478bd9Sstevel@tonic-gate return (NULL); 4087c478bd9Sstevel@tonic-gate } 4097c478bd9Sstevel@tonic-gate (void) pool_value_get_string(&val, &str); 4107c478bd9Sstevel@tonic-gate if (append_char_buf(cb, "\t%s\n", str) == PO_FAIL) { 4117c478bd9Sstevel@tonic-gate free(rs); 4127c478bd9Sstevel@tonic-gate return (NULL); 4137c478bd9Sstevel@tonic-gate } 4147c478bd9Sstevel@tonic-gate } 4157c478bd9Sstevel@tonic-gate free(rs); 4167c478bd9Sstevel@tonic-gate } 4177c478bd9Sstevel@tonic-gate if (deep == PO_TRUE) { 4187c478bd9Sstevel@tonic-gate pool_t **ps; 4197c478bd9Sstevel@tonic-gate pool_component_t **cs; 4207c478bd9Sstevel@tonic-gate 4217c478bd9Sstevel@tonic-gate if (strlcat(cb->cb_tab_buf, "\t", CB_TAB_BUF_SIZE) 4227c478bd9Sstevel@tonic-gate >= CB_TAB_BUF_SIZE) { 4237c478bd9Sstevel@tonic-gate pool_seterror(POE_SYSTEM); 4247c478bd9Sstevel@tonic-gate return (NULL); 4257c478bd9Sstevel@tonic-gate } 4267c478bd9Sstevel@tonic-gate switch (pe->pe_class) { 4277c478bd9Sstevel@tonic-gate case PEC_SYSTEM: 4287c478bd9Sstevel@tonic-gate if ((ps = pool_query_pools(conf, &nelem, NULL)) != 4297c478bd9Sstevel@tonic-gate NULL) { /* process the pools */ 4307c478bd9Sstevel@tonic-gate for (i = 0; i < nelem; i++) { 4317c478bd9Sstevel@tonic-gate elem = TO_ELEM(ps[i]); 4327c478bd9Sstevel@tonic-gate if (pool_base_info(elem, cb, 4337c478bd9Sstevel@tonic-gate PO_FALSE) == NULL) { 4347c478bd9Sstevel@tonic-gate free(ps); 4357c478bd9Sstevel@tonic-gate return (NULL); 4367c478bd9Sstevel@tonic-gate } 4377c478bd9Sstevel@tonic-gate } 4387c478bd9Sstevel@tonic-gate free(ps); 4397c478bd9Sstevel@tonic-gate } 4407c478bd9Sstevel@tonic-gate if ((rs = pool_query_resources(conf, &nelem, NULL)) != 4417c478bd9Sstevel@tonic-gate NULL) { 4427c478bd9Sstevel@tonic-gate for (i = 0; i < nelem; i++) { 4437c478bd9Sstevel@tonic-gate elem = TO_ELEM(rs[i]); 4447c478bd9Sstevel@tonic-gate if (pool_base_info(elem, cb, 4457c478bd9Sstevel@tonic-gate PO_TRUE) == NULL) { 4467c478bd9Sstevel@tonic-gate free(rs); 4477c478bd9Sstevel@tonic-gate return (NULL); 4487c478bd9Sstevel@tonic-gate } 4497c478bd9Sstevel@tonic-gate } 4507c478bd9Sstevel@tonic-gate free(rs); 4517c478bd9Sstevel@tonic-gate } 4527c478bd9Sstevel@tonic-gate break; 4537c478bd9Sstevel@tonic-gate case PEC_POOL: 4547c478bd9Sstevel@tonic-gate if ((rs = pool_query_pool_resources(conf, 4557c478bd9Sstevel@tonic-gate pool_elem_pool(pe), &nelem, NULL)) == NULL) 4567c478bd9Sstevel@tonic-gate return (NULL); 4577c478bd9Sstevel@tonic-gate for (i = 0; i < nelem; i++) { 4587c478bd9Sstevel@tonic-gate elem = TO_ELEM(rs[i]); 4597c478bd9Sstevel@tonic-gate if (pool_base_info(elem, cb, PO_TRUE) == NULL) { 4607c478bd9Sstevel@tonic-gate free(rs); 4617c478bd9Sstevel@tonic-gate return (NULL); 4627c478bd9Sstevel@tonic-gate } 4637c478bd9Sstevel@tonic-gate } 4647c478bd9Sstevel@tonic-gate free(rs); 4657c478bd9Sstevel@tonic-gate break; 4667c478bd9Sstevel@tonic-gate case PEC_RES_COMP: 4677c478bd9Sstevel@tonic-gate if ((cs = pool_query_resource_components(conf, 4687c478bd9Sstevel@tonic-gate pool_elem_res(pe), &nelem, NULL)) != NULL) { 4697c478bd9Sstevel@tonic-gate for (i = 0; i < nelem; i++) { 4707c478bd9Sstevel@tonic-gate elem = TO_ELEM(cs[i]); 4717c478bd9Sstevel@tonic-gate if (pool_base_info(elem, cb, 4727c478bd9Sstevel@tonic-gate PO_FALSE) == NULL) { 4737c478bd9Sstevel@tonic-gate free(cs); 4747c478bd9Sstevel@tonic-gate return (NULL); 4757c478bd9Sstevel@tonic-gate } 4767c478bd9Sstevel@tonic-gate } 4777c478bd9Sstevel@tonic-gate free(cs); 4787c478bd9Sstevel@tonic-gate } 4797c478bd9Sstevel@tonic-gate break; 4807c478bd9Sstevel@tonic-gate case PEC_RES_AGG: 4817c478bd9Sstevel@tonic-gate case PEC_COMP: 4827c478bd9Sstevel@tonic-gate break; 4837c478bd9Sstevel@tonic-gate default: 4847c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 4857c478bd9Sstevel@tonic-gate break; 4867c478bd9Sstevel@tonic-gate } 4877c478bd9Sstevel@tonic-gate if (cb->cb_tab_buf[0] != 0) 4887c478bd9Sstevel@tonic-gate cb->cb_tab_buf[strlen(cb->cb_tab_buf) - 1] = 0; 4897c478bd9Sstevel@tonic-gate } 4907c478bd9Sstevel@tonic-gate return (cb->cb_buf); 4917c478bd9Sstevel@tonic-gate } 4927c478bd9Sstevel@tonic-gate 4937c478bd9Sstevel@tonic-gate /* 4947c478bd9Sstevel@tonic-gate * Returns The information on the specified pool or NULL. 4957c478bd9Sstevel@tonic-gate * 4967c478bd9Sstevel@tonic-gate * Errors If the status of the conf is INVALID or the supplied 4977c478bd9Sstevel@tonic-gate * value of deep is illegal, POE_BADPARAM. 4987c478bd9Sstevel@tonic-gate * 4997c478bd9Sstevel@tonic-gate * The caller is responsible for free(3c)ing the string returned. 5007c478bd9Sstevel@tonic-gate */ 5017c478bd9Sstevel@tonic-gate char * 5027c478bd9Sstevel@tonic-gate pool_info(const pool_conf_t *conf, const pool_t *pool, int deep) 5037c478bd9Sstevel@tonic-gate { 5047c478bd9Sstevel@tonic-gate pool_elem_t *pe; 5057c478bd9Sstevel@tonic-gate 5067c478bd9Sstevel@tonic-gate pe = TO_ELEM(pool); 5077c478bd9Sstevel@tonic-gate 5087c478bd9Sstevel@tonic-gate if (TO_CONF(pe) != conf) { 5097c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 5107c478bd9Sstevel@tonic-gate return (NULL); 5117c478bd9Sstevel@tonic-gate } 5127c478bd9Sstevel@tonic-gate 5137c478bd9Sstevel@tonic-gate if (pool_conf_status(conf) == POF_INVALID || (deep & ~1)) { 5147c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 5157c478bd9Sstevel@tonic-gate return (NULL); 5167c478bd9Sstevel@tonic-gate } 5177c478bd9Sstevel@tonic-gate 5187c478bd9Sstevel@tonic-gate return (pool_base_info(pe, NULL, deep)); 5197c478bd9Sstevel@tonic-gate } 5207c478bd9Sstevel@tonic-gate 5217c478bd9Sstevel@tonic-gate /* 5227c478bd9Sstevel@tonic-gate * Returns The information on the specified resource or NULL. 5237c478bd9Sstevel@tonic-gate * 5247c478bd9Sstevel@tonic-gate * Errors If the status of the conf is INVALID or the supplied 5257c478bd9Sstevel@tonic-gate * value of deep is illegal, POE_BADPARAM. 5267c478bd9Sstevel@tonic-gate * 5277c478bd9Sstevel@tonic-gate * The caller is responsible for free(3c)ing the string returned. 5287c478bd9Sstevel@tonic-gate */ 5297c478bd9Sstevel@tonic-gate char * 5307c478bd9Sstevel@tonic-gate pool_resource_info(const pool_conf_t *conf, const pool_resource_t *res, 5317c478bd9Sstevel@tonic-gate int deep) 5327c478bd9Sstevel@tonic-gate { 5337c478bd9Sstevel@tonic-gate pool_elem_t *pe; 5347c478bd9Sstevel@tonic-gate 5357c478bd9Sstevel@tonic-gate pe = TO_ELEM(res); 5367c478bd9Sstevel@tonic-gate 5377c478bd9Sstevel@tonic-gate if (TO_CONF(pe) != conf) { 5387c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 5397c478bd9Sstevel@tonic-gate return (NULL); 5407c478bd9Sstevel@tonic-gate } 5417c478bd9Sstevel@tonic-gate 5427c478bd9Sstevel@tonic-gate if (pool_conf_status(conf) == POF_INVALID || (deep & ~1)) { 5437c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 5447c478bd9Sstevel@tonic-gate return (NULL); 5457c478bd9Sstevel@tonic-gate } 5467c478bd9Sstevel@tonic-gate 5477c478bd9Sstevel@tonic-gate return (pool_base_info(pe, NULL, deep)); 5487c478bd9Sstevel@tonic-gate } 5497c478bd9Sstevel@tonic-gate 5507c478bd9Sstevel@tonic-gate /* 5517c478bd9Sstevel@tonic-gate * Returns The information on the specified component or NULL. 5527c478bd9Sstevel@tonic-gate * 5537c478bd9Sstevel@tonic-gate * Errors If the status of the conf is INVALID or the supplied 5547c478bd9Sstevel@tonic-gate * value of deep is illegal, POE_BADPARAM. 5557c478bd9Sstevel@tonic-gate * 5567c478bd9Sstevel@tonic-gate * The caller is responsible for free(3c)ing the string returned. 5577c478bd9Sstevel@tonic-gate */ 5587c478bd9Sstevel@tonic-gate char * 5597c478bd9Sstevel@tonic-gate pool_component_info(const pool_conf_t *conf, const pool_component_t *comp, 5607c478bd9Sstevel@tonic-gate int deep) 5617c478bd9Sstevel@tonic-gate { 5627c478bd9Sstevel@tonic-gate pool_elem_t *pe; 5637c478bd9Sstevel@tonic-gate 5647c478bd9Sstevel@tonic-gate pe = TO_ELEM(comp); 5657c478bd9Sstevel@tonic-gate 5667c478bd9Sstevel@tonic-gate if (TO_CONF(pe) != conf) { 5677c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 5687c478bd9Sstevel@tonic-gate return (NULL); 5697c478bd9Sstevel@tonic-gate } 5707c478bd9Sstevel@tonic-gate 5717c478bd9Sstevel@tonic-gate if (pool_conf_status(conf) == POF_INVALID || (deep & ~1)) { 5727c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 5737c478bd9Sstevel@tonic-gate return (NULL); 5747c478bd9Sstevel@tonic-gate } 5757c478bd9Sstevel@tonic-gate 5767c478bd9Sstevel@tonic-gate return (pool_base_info(pe, NULL, deep)); 5777c478bd9Sstevel@tonic-gate } 5787c478bd9Sstevel@tonic-gate 5797c478bd9Sstevel@tonic-gate /* 5807c478bd9Sstevel@tonic-gate * Returns The information on the specified conf or NULL. 5817c478bd9Sstevel@tonic-gate * 5827c478bd9Sstevel@tonic-gate * Errors If the status of the conf is INVALID or the supplied 5837c478bd9Sstevel@tonic-gate * value of deep is illegal, POE_BADPARAM. 5847c478bd9Sstevel@tonic-gate * 5857c478bd9Sstevel@tonic-gate * The caller is responsible for free(3c)ing the string returned. 5867c478bd9Sstevel@tonic-gate */ 5877c478bd9Sstevel@tonic-gate char * 5887c478bd9Sstevel@tonic-gate pool_conf_info(const pool_conf_t *conf, int deep) 5897c478bd9Sstevel@tonic-gate { 5907c478bd9Sstevel@tonic-gate pool_elem_t *pe; 5917c478bd9Sstevel@tonic-gate 5927c478bd9Sstevel@tonic-gate if (pool_conf_status(conf) == POF_INVALID || (deep & ~1)) { 5937c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 5947c478bd9Sstevel@tonic-gate return (NULL); 5957c478bd9Sstevel@tonic-gate } 5967c478bd9Sstevel@tonic-gate if ((pe = pool_conf_to_elem(conf)) == NULL) { 5977c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 5987c478bd9Sstevel@tonic-gate return (NULL); 5997c478bd9Sstevel@tonic-gate } 6007c478bd9Sstevel@tonic-gate return (pool_base_info(pe, NULL, deep)); 6017c478bd9Sstevel@tonic-gate } 6027c478bd9Sstevel@tonic-gate 6037c478bd9Sstevel@tonic-gate 6047c478bd9Sstevel@tonic-gate /* 6057c478bd9Sstevel@tonic-gate * Set the thread specific error value. 6067c478bd9Sstevel@tonic-gate */ 6077c478bd9Sstevel@tonic-gate void 6087c478bd9Sstevel@tonic-gate pool_seterror(int errval) 6097c478bd9Sstevel@tonic-gate { 6107c478bd9Sstevel@tonic-gate if (thr_main()) { 6117c478bd9Sstevel@tonic-gate pool_errval = errval; 6127c478bd9Sstevel@tonic-gate return; 6137c478bd9Sstevel@tonic-gate } 6147c478bd9Sstevel@tonic-gate if (keyonce == 0) { 6157c478bd9Sstevel@tonic-gate (void) mutex_lock(&keylock); 6167c478bd9Sstevel@tonic-gate if (keyonce == 0) { 6177c478bd9Sstevel@tonic-gate (void) thr_keycreate(&errkey, 0); 6187c478bd9Sstevel@tonic-gate keyonce++; 6197c478bd9Sstevel@tonic-gate } 6207c478bd9Sstevel@tonic-gate (void) mutex_unlock(&keylock); 6217c478bd9Sstevel@tonic-gate } 6227c478bd9Sstevel@tonic-gate (void) thr_setspecific(errkey, (void *)(intptr_t)errval); 6237c478bd9Sstevel@tonic-gate } 6247c478bd9Sstevel@tonic-gate 6257c478bd9Sstevel@tonic-gate /* 6267c478bd9Sstevel@tonic-gate * Return the current value of the error code. 6277c478bd9Sstevel@tonic-gate * Returns: int error code 6287c478bd9Sstevel@tonic-gate */ 6297c478bd9Sstevel@tonic-gate int 6307c478bd9Sstevel@tonic-gate pool_error(void) 6317c478bd9Sstevel@tonic-gate { 6327c478bd9Sstevel@tonic-gate void *errval; 6337c478bd9Sstevel@tonic-gate 6347c478bd9Sstevel@tonic-gate if (thr_main()) 6357c478bd9Sstevel@tonic-gate return (pool_errval); 6367c478bd9Sstevel@tonic-gate if (keyonce == 0) 6377c478bd9Sstevel@tonic-gate return (POE_OK); 6387c478bd9Sstevel@tonic-gate (void) thr_getspecific(errkey, &errval); 6397c478bd9Sstevel@tonic-gate return ((intptr_t)errval); 6407c478bd9Sstevel@tonic-gate } 6417c478bd9Sstevel@tonic-gate 6427c478bd9Sstevel@tonic-gate /* 6437c478bd9Sstevel@tonic-gate * Return the text represenation for the current value of the error code. 6447c478bd9Sstevel@tonic-gate * Returns: const char * error string 6457c478bd9Sstevel@tonic-gate */ 6467c478bd9Sstevel@tonic-gate const char * 6477c478bd9Sstevel@tonic-gate pool_strerror(int error) 6487c478bd9Sstevel@tonic-gate { 6497c478bd9Sstevel@tonic-gate char *str; 6507c478bd9Sstevel@tonic-gate 6517c478bd9Sstevel@tonic-gate switch (error) { 6527c478bd9Sstevel@tonic-gate case POE_OK: 6537c478bd9Sstevel@tonic-gate str = dgettext(TEXT_DOMAIN, "Operation successful"); 6547c478bd9Sstevel@tonic-gate break; 6557c478bd9Sstevel@tonic-gate case POE_BAD_PROP_TYPE: 6567c478bd9Sstevel@tonic-gate str = dgettext(TEXT_DOMAIN, 6577c478bd9Sstevel@tonic-gate "Attempted to retrieve the wrong property type"); 6587c478bd9Sstevel@tonic-gate break; 6597c478bd9Sstevel@tonic-gate case POE_INVALID_CONF: 6607c478bd9Sstevel@tonic-gate str = dgettext(TEXT_DOMAIN, "Invalid configuration"); 6617c478bd9Sstevel@tonic-gate break; 6627c478bd9Sstevel@tonic-gate case POE_NOTSUP: 6637c478bd9Sstevel@tonic-gate str = dgettext(TEXT_DOMAIN, "Operation is not supported"); 6647c478bd9Sstevel@tonic-gate break; 6657c478bd9Sstevel@tonic-gate case POE_INVALID_SEARCH: 6667c478bd9Sstevel@tonic-gate str = dgettext(TEXT_DOMAIN, "Invalid search"); 6677c478bd9Sstevel@tonic-gate break; 6687c478bd9Sstevel@tonic-gate case POE_BADPARAM: 6697c478bd9Sstevel@tonic-gate str = dgettext(TEXT_DOMAIN, "Bad parameter supplied"); 6707c478bd9Sstevel@tonic-gate break; 6717c478bd9Sstevel@tonic-gate case POE_PUTPROP: 6727c478bd9Sstevel@tonic-gate str = dgettext(TEXT_DOMAIN, "Error putting property"); 6737c478bd9Sstevel@tonic-gate break; 6747c478bd9Sstevel@tonic-gate case POE_DATASTORE: 6757c478bd9Sstevel@tonic-gate str = dgettext(TEXT_DOMAIN, "Pools repository error"); 6767c478bd9Sstevel@tonic-gate break; 6777c478bd9Sstevel@tonic-gate case POE_SYSTEM: 6787c478bd9Sstevel@tonic-gate str = dgettext(TEXT_DOMAIN, "System error"); 6797c478bd9Sstevel@tonic-gate break; 6807c478bd9Sstevel@tonic-gate case POE_ACCESS: 6817c478bd9Sstevel@tonic-gate str = dgettext(TEXT_DOMAIN, "Permission denied"); 6827c478bd9Sstevel@tonic-gate break; 6837c478bd9Sstevel@tonic-gate default: 6847c478bd9Sstevel@tonic-gate errno = ESRCH; 6857c478bd9Sstevel@tonic-gate str = NULL; 6867c478bd9Sstevel@tonic-gate } 6877c478bd9Sstevel@tonic-gate return (str); 6887c478bd9Sstevel@tonic-gate } 6897c478bd9Sstevel@tonic-gate 6907c478bd9Sstevel@tonic-gate int 6917c478bd9Sstevel@tonic-gate pool_get_status(int *state) 6927c478bd9Sstevel@tonic-gate { 6937c478bd9Sstevel@tonic-gate int fd; 6947c478bd9Sstevel@tonic-gate pool_status_t status; 6957c478bd9Sstevel@tonic-gate 6967c478bd9Sstevel@tonic-gate if ((fd = open(pool_info_location, O_RDONLY)) < 0) { 6977c478bd9Sstevel@tonic-gate pool_seterror(POE_SYSTEM); 6987c478bd9Sstevel@tonic-gate return (PO_FAIL); 6997c478bd9Sstevel@tonic-gate } 7007c478bd9Sstevel@tonic-gate if (ioctl(fd, POOL_STATUSQ, &status) < 0) { 7017c478bd9Sstevel@tonic-gate (void) close(fd); 7027c478bd9Sstevel@tonic-gate pool_seterror(POE_SYSTEM); 7037c478bd9Sstevel@tonic-gate return (PO_FAIL); 7047c478bd9Sstevel@tonic-gate } 7057c478bd9Sstevel@tonic-gate (void) close(fd); 7067c478bd9Sstevel@tonic-gate 7077c478bd9Sstevel@tonic-gate *state = status.ps_io_state; 7087c478bd9Sstevel@tonic-gate 7097c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 7107c478bd9Sstevel@tonic-gate } 7117c478bd9Sstevel@tonic-gate 7127c478bd9Sstevel@tonic-gate int 7137c478bd9Sstevel@tonic-gate pool_set_status(int state) 7147c478bd9Sstevel@tonic-gate { 7157c478bd9Sstevel@tonic-gate int old_state; 7167c478bd9Sstevel@tonic-gate 7177c478bd9Sstevel@tonic-gate if (pool_get_status(&old_state) != PO_SUCCESS) { 7187c478bd9Sstevel@tonic-gate pool_seterror(POE_SYSTEM); 7197c478bd9Sstevel@tonic-gate return (PO_FAIL); 7207c478bd9Sstevel@tonic-gate } 7217c478bd9Sstevel@tonic-gate 7227c478bd9Sstevel@tonic-gate if (old_state != state) { 7237c478bd9Sstevel@tonic-gate int fd; 7247c478bd9Sstevel@tonic-gate pool_status_t status; 725*c1c0ebd5Ssl108498 char *fmri; 7267c478bd9Sstevel@tonic-gate 72726d8ba22Sgarypen /* 72826d8ba22Sgarypen * Changing the status of pools is performed by enabling 72926d8ba22Sgarypen * or disabling the pools service instance. If this 73026d8ba22Sgarypen * function has not been invoked by startd then we simply 73126d8ba22Sgarypen * enable/disable the service and return success. 73226d8ba22Sgarypen * 73326d8ba22Sgarypen * There is no way to specify that state changes must be 73426d8ba22Sgarypen * synchronous using the library API as yet, so we use 73526d8ba22Sgarypen * the -s option provided by svcadm. 73626d8ba22Sgarypen */ 737*c1c0ebd5Ssl108498 fmri = getenv("SMF_FMRI"); 738*c1c0ebd5Ssl108498 if (fmri == NULL) { 73926d8ba22Sgarypen FILE *p; 740fb30ca63Sgarypen char *cmd; 741fb30ca63Sgarypen 742*c1c0ebd5Ssl108498 if (state != 0) { 743fb30ca63Sgarypen cmd = "/usr/sbin/svcadm enable -s " \ 74426d8ba22Sgarypen SMF_SVC_INSTANCE; 74526d8ba22Sgarypen } else { 746fb30ca63Sgarypen cmd = "/usr/sbin/svcadm disable -s " \ 74726d8ba22Sgarypen SMF_SVC_INSTANCE; 748fb30ca63Sgarypen } 749fb30ca63Sgarypen if ((p = popen(cmd, "wF")) == NULL || pclose(p) != 0) { 750fb30ca63Sgarypen pool_seterror(POE_SYSTEM); 75126d8ba22Sgarypen return (PO_FAIL); 7527c478bd9Sstevel@tonic-gate } 75326d8ba22Sgarypen return (PO_SUCCESS); 7547c478bd9Sstevel@tonic-gate } 7557c478bd9Sstevel@tonic-gate 7567c478bd9Sstevel@tonic-gate if ((fd = open(pool_dynamic_location(), O_RDWR | O_EXCL)) < 0) { 7577c478bd9Sstevel@tonic-gate pool_seterror(POE_SYSTEM); 7587c478bd9Sstevel@tonic-gate return (PO_FAIL); 7597c478bd9Sstevel@tonic-gate } 7607c478bd9Sstevel@tonic-gate 761*c1c0ebd5Ssl108498 /* 762*c1c0ebd5Ssl108498 * If pools are being enabled/disabled by another smf service, 763*c1c0ebd5Ssl108498 * enable the smf service instance. This must be done 764*c1c0ebd5Ssl108498 * asynchronously as one service cannot synchronously 765*c1c0ebd5Ssl108498 * enable/disable another. 766*c1c0ebd5Ssl108498 */ 767*c1c0ebd5Ssl108498 if (strcmp(fmri, SMF_SVC_INSTANCE) != 0) { 768*c1c0ebd5Ssl108498 int res; 769*c1c0ebd5Ssl108498 770*c1c0ebd5Ssl108498 if (state != 0) 771*c1c0ebd5Ssl108498 res = smf_enable_instance(SMF_SVC_INSTANCE, 0); 772*c1c0ebd5Ssl108498 else 773*c1c0ebd5Ssl108498 res = smf_disable_instance(SMF_SVC_INSTANCE, 0); 774*c1c0ebd5Ssl108498 775*c1c0ebd5Ssl108498 if (res != 0) { 776*c1c0ebd5Ssl108498 (void) close(fd); 777*c1c0ebd5Ssl108498 pool_seterror(POE_SYSTEM); 778*c1c0ebd5Ssl108498 return (PO_FAIL); 779*c1c0ebd5Ssl108498 } 780*c1c0ebd5Ssl108498 } 7817c478bd9Sstevel@tonic-gate status.ps_io_state = state; 7827c478bd9Sstevel@tonic-gate 7837c478bd9Sstevel@tonic-gate if (ioctl(fd, POOL_STATUS, &status) < 0) { 7847c478bd9Sstevel@tonic-gate (void) close(fd); 7857c478bd9Sstevel@tonic-gate pool_seterror(POE_SYSTEM); 7867c478bd9Sstevel@tonic-gate return (PO_FAIL); 7877c478bd9Sstevel@tonic-gate } 7887c478bd9Sstevel@tonic-gate 7897c478bd9Sstevel@tonic-gate (void) close(fd); 7907c478bd9Sstevel@tonic-gate 7917c478bd9Sstevel@tonic-gate } 7927c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 7937c478bd9Sstevel@tonic-gate } 7947c478bd9Sstevel@tonic-gate 7957c478bd9Sstevel@tonic-gate /* 7967c478bd9Sstevel@tonic-gate * General Data Provider Independent Access Methods 7977c478bd9Sstevel@tonic-gate */ 7987c478bd9Sstevel@tonic-gate 7997c478bd9Sstevel@tonic-gate /* 8007c478bd9Sstevel@tonic-gate * Property manipulation code. 8017c478bd9Sstevel@tonic-gate * 8027c478bd9Sstevel@tonic-gate * The pool_(get|rm|set)_property() functions consult the plugins before 8037c478bd9Sstevel@tonic-gate * looking at the actual configuration. This allows plugins to provide 8047c478bd9Sstevel@tonic-gate * "virtual" properties that may not exist in the configuration file per se, 8057c478bd9Sstevel@tonic-gate * but behave like regular properties. This also allows plugins to reserve 8067c478bd9Sstevel@tonic-gate * certain properties as read-only, non-removable, etc. 8077c478bd9Sstevel@tonic-gate * 8087c478bd9Sstevel@tonic-gate * A negative value returned from the plugin denotes error, 0 means that the 8097c478bd9Sstevel@tonic-gate * property request should be forwarded to the backend, and 1 means the request 8107c478bd9Sstevel@tonic-gate * was satisfied by the plugin and should not be processed further. 8117c478bd9Sstevel@tonic-gate * 8127c478bd9Sstevel@tonic-gate * The (get|rm|set)_property() functions bypass the plugin layer completely, 8137c478bd9Sstevel@tonic-gate * and hence should not be generally used. 8147c478bd9Sstevel@tonic-gate */ 8157c478bd9Sstevel@tonic-gate 8167c478bd9Sstevel@tonic-gate /* 8177c478bd9Sstevel@tonic-gate * Return true if the string passed in matches the pattern 8187c478bd9Sstevel@tonic-gate * [A-Za-z][A-Za-z0-9,._-]* 8197c478bd9Sstevel@tonic-gate */ 8207c478bd9Sstevel@tonic-gate int 8217c478bd9Sstevel@tonic-gate is_valid_name(const char *name) 8227c478bd9Sstevel@tonic-gate { 8237c478bd9Sstevel@tonic-gate int i; 8247c478bd9Sstevel@tonic-gate char c; 8257c478bd9Sstevel@tonic-gate 8267c478bd9Sstevel@tonic-gate if (name == NULL) 8277c478bd9Sstevel@tonic-gate return (PO_FALSE); 8287c478bd9Sstevel@tonic-gate if (!isalpha(name[0])) 8297c478bd9Sstevel@tonic-gate return (PO_FALSE); 8307c478bd9Sstevel@tonic-gate for (i = 1; (c = name[i]) != '\0'; i++) { 8317c478bd9Sstevel@tonic-gate if (!isalnum(c) && c != ',' && c != '.' && c != '_' && c != '-') 8327c478bd9Sstevel@tonic-gate return (PO_FALSE); 8337c478bd9Sstevel@tonic-gate } 8347c478bd9Sstevel@tonic-gate return (PO_TRUE); 8357c478bd9Sstevel@tonic-gate } 8367c478bd9Sstevel@tonic-gate 8377c478bd9Sstevel@tonic-gate /* 8387c478bd9Sstevel@tonic-gate * Return true if the string passed in matches the pattern 8397c478bd9Sstevel@tonic-gate * [A-Za-z_][A-Za-z0-9,._-]* 8407c478bd9Sstevel@tonic-gate * A property name starting with a '_' is an "invisible" property that does not 8417c478bd9Sstevel@tonic-gate * show up in a property walk. 8427c478bd9Sstevel@tonic-gate */ 8437c478bd9Sstevel@tonic-gate int 8447c478bd9Sstevel@tonic-gate is_valid_prop_name(const char *prop_name) 8457c478bd9Sstevel@tonic-gate { 8467c478bd9Sstevel@tonic-gate int i; 8477c478bd9Sstevel@tonic-gate char c; 8487c478bd9Sstevel@tonic-gate 8497c478bd9Sstevel@tonic-gate if (prop_name == NULL) 8507c478bd9Sstevel@tonic-gate return (PO_FALSE); 8517c478bd9Sstevel@tonic-gate if (!isalpha(prop_name[0]) && prop_name[0] != '_') 8527c478bd9Sstevel@tonic-gate return (PO_FALSE); 8537c478bd9Sstevel@tonic-gate for (i = 1; (c = prop_name[i]) != '\0'; i++) { 8547c478bd9Sstevel@tonic-gate if (!isalnum(c) && c != ',' && c != '.' && c != '_' && c != '-') 8557c478bd9Sstevel@tonic-gate return (PO_FALSE); 8567c478bd9Sstevel@tonic-gate } 8577c478bd9Sstevel@tonic-gate return (PO_TRUE); 8587c478bd9Sstevel@tonic-gate } 8597c478bd9Sstevel@tonic-gate 8607c478bd9Sstevel@tonic-gate /* 8617c478bd9Sstevel@tonic-gate * Return the specified property value. 8627c478bd9Sstevel@tonic-gate * 8637c478bd9Sstevel@tonic-gate * POC_INVAL is returned if an error is detected and the error code is updated 8647c478bd9Sstevel@tonic-gate * to indicate the cause of the error. 8657c478bd9Sstevel@tonic-gate */ 8667c478bd9Sstevel@tonic-gate pool_value_class_t 8677c478bd9Sstevel@tonic-gate pool_get_property(const pool_conf_t *conf, const pool_elem_t *pe, 8687c478bd9Sstevel@tonic-gate const char *name, pool_value_t *val) 8697c478bd9Sstevel@tonic-gate { 8707c478bd9Sstevel@tonic-gate const pool_prop_t *prop_info; 8717c478bd9Sstevel@tonic-gate 8727c478bd9Sstevel@tonic-gate if (pool_conf_status(conf) == POF_INVALID) { 8737c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 8747c478bd9Sstevel@tonic-gate return (POC_INVAL); 8757c478bd9Sstevel@tonic-gate } 8767c478bd9Sstevel@tonic-gate if (pool_value_set_name(val, name) != PO_SUCCESS) { 8777c478bd9Sstevel@tonic-gate return (POC_INVAL); 8787c478bd9Sstevel@tonic-gate } 8797c478bd9Sstevel@tonic-gate /* 8807c478bd9Sstevel@tonic-gate * Check to see if this is a property we are managing. If it 8817c478bd9Sstevel@tonic-gate * is and it has an interceptor installed for property 8827c478bd9Sstevel@tonic-gate * retrieval, use it. 8837c478bd9Sstevel@tonic-gate */ 8847c478bd9Sstevel@tonic-gate if ((prop_info = provider_get_prop(pe, name)) != NULL && 8857c478bd9Sstevel@tonic-gate prop_info->pp_op.ppo_get_value != NULL) { 8867c478bd9Sstevel@tonic-gate if (prop_info->pp_op.ppo_get_value(pe, val) == PO_FAIL) 8877c478bd9Sstevel@tonic-gate return (POC_INVAL); 8887c478bd9Sstevel@tonic-gate else 8897c478bd9Sstevel@tonic-gate return (pool_value_get_type(val)); 8907c478bd9Sstevel@tonic-gate } 8917c478bd9Sstevel@tonic-gate return (pe->pe_get_prop(pe, name, val)); 8927c478bd9Sstevel@tonic-gate } 8937c478bd9Sstevel@tonic-gate 8947c478bd9Sstevel@tonic-gate /* 8957c478bd9Sstevel@tonic-gate * Return the specified property value with the namespace prepended. 8967c478bd9Sstevel@tonic-gate * e.g. If this function is used to get the property "name" on a pool, it will 8977c478bd9Sstevel@tonic-gate * attempt to retrieve "pool.name". 8987c478bd9Sstevel@tonic-gate * 8997c478bd9Sstevel@tonic-gate * POC_INVAL is returned if an error is detected and the error code is updated 9007c478bd9Sstevel@tonic-gate * to indicate the cause of the error. 9017c478bd9Sstevel@tonic-gate */ 9027c478bd9Sstevel@tonic-gate pool_value_class_t 9037c478bd9Sstevel@tonic-gate pool_get_ns_property(const pool_elem_t *pe, const char *name, pool_value_t *val) 9047c478bd9Sstevel@tonic-gate { 9057c478bd9Sstevel@tonic-gate int ret; 9067c478bd9Sstevel@tonic-gate char_buf_t *cb; 9077c478bd9Sstevel@tonic-gate 9087c478bd9Sstevel@tonic-gate if ((cb = alloc_char_buf(CB_DEFAULT_LEN)) == NULL) 9097c478bd9Sstevel@tonic-gate return (POC_INVAL); 9107c478bd9Sstevel@tonic-gate if (set_char_buf(cb, "%s.%s", pool_elem_class_string(pe), name) == 9117c478bd9Sstevel@tonic-gate PO_FAIL) { 9127c478bd9Sstevel@tonic-gate free_char_buf(cb); 9137c478bd9Sstevel@tonic-gate return (POC_INVAL); 9147c478bd9Sstevel@tonic-gate } 9157c478bd9Sstevel@tonic-gate ret = pool_get_property(TO_CONF(pe), pe, cb->cb_buf, val); 9167c478bd9Sstevel@tonic-gate free_char_buf(cb); 9177c478bd9Sstevel@tonic-gate return (ret); 9187c478bd9Sstevel@tonic-gate } 9197c478bd9Sstevel@tonic-gate 9207c478bd9Sstevel@tonic-gate /* 9217c478bd9Sstevel@tonic-gate * Update the specified property value. 9227c478bd9Sstevel@tonic-gate * 9237c478bd9Sstevel@tonic-gate * PO_FAIL is returned if an error is detected and the error code is updated 9247c478bd9Sstevel@tonic-gate * to indicate the cause of the error. 9257c478bd9Sstevel@tonic-gate */ 9267c478bd9Sstevel@tonic-gate int 9277c478bd9Sstevel@tonic-gate pool_put_property(pool_conf_t *conf, pool_elem_t *pe, const char *name, 9287c478bd9Sstevel@tonic-gate const pool_value_t *val) 9297c478bd9Sstevel@tonic-gate { 9307c478bd9Sstevel@tonic-gate const pool_prop_t *prop_info; 9317c478bd9Sstevel@tonic-gate 9327c478bd9Sstevel@tonic-gate if (pool_conf_check(conf) != PO_SUCCESS) 9337c478bd9Sstevel@tonic-gate return (PO_FAIL); 9347c478bd9Sstevel@tonic-gate 9357c478bd9Sstevel@tonic-gate if (TO_CONF(pe) != conf) { 9367c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 9377c478bd9Sstevel@tonic-gate return (NULL); 9387c478bd9Sstevel@tonic-gate } 9397c478bd9Sstevel@tonic-gate 9400209230bSgjelinek /* Don't allow (re)setting of the "temporary" property */ 9410209230bSgjelinek if (!is_valid_prop_name(name) || strstr(name, ".temporary") != NULL) { 9427c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 9437c478bd9Sstevel@tonic-gate return (PO_FAIL); 9447c478bd9Sstevel@tonic-gate } 9450209230bSgjelinek 9460209230bSgjelinek /* Don't allow rename of temporary pools/resources */ 9470209230bSgjelinek if (strstr(name, ".name") != NULL && elem_is_tmp(pe)) { 9480209230bSgjelinek boolean_t rename = B_TRUE; 9490209230bSgjelinek pool_value_t *pv = pool_value_alloc(); 9500209230bSgjelinek 9510209230bSgjelinek if (pe->pe_get_prop(pe, name, pv) != POC_INVAL) { 9520209230bSgjelinek const char *s1 = NULL; 9530209230bSgjelinek const char *s2 = NULL; 9540209230bSgjelinek 9550209230bSgjelinek (void) pool_value_get_string(pv, &s1); 9560209230bSgjelinek (void) pool_value_get_string(val, &s2); 9570209230bSgjelinek if (s1 != NULL && s2 != NULL && strcmp(s1, s2) == 0) 9580209230bSgjelinek rename = B_FALSE; 9590209230bSgjelinek } 9600209230bSgjelinek pool_value_free(pv); 9610209230bSgjelinek 9620209230bSgjelinek if (rename) { 9630209230bSgjelinek pool_seterror(POE_BADPARAM); 9640209230bSgjelinek return (PO_FAIL); 9650209230bSgjelinek } 9660209230bSgjelinek } 9670209230bSgjelinek 9687c478bd9Sstevel@tonic-gate /* 9697c478bd9Sstevel@tonic-gate * Check to see if this is a property we are managing. If it is, 9707c478bd9Sstevel@tonic-gate * ensure that we are happy with what the user is doing. 9717c478bd9Sstevel@tonic-gate */ 9727c478bd9Sstevel@tonic-gate if ((prop_info = provider_get_prop(pe, name)) != NULL) { 9737c478bd9Sstevel@tonic-gate if (prop_is_readonly(prop_info) == PO_TRUE) { 9747c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 9757c478bd9Sstevel@tonic-gate return (PO_FAIL); 9767c478bd9Sstevel@tonic-gate } 9777c478bd9Sstevel@tonic-gate if (prop_info->pp_op.ppo_set_value && 9787c478bd9Sstevel@tonic-gate prop_info->pp_op.ppo_set_value(pe, val) == PO_FAIL) 9797c478bd9Sstevel@tonic-gate return (PO_FAIL); 9807c478bd9Sstevel@tonic-gate } 9817c478bd9Sstevel@tonic-gate 9827c478bd9Sstevel@tonic-gate return (pe->pe_put_prop(pe, name, val)); 9837c478bd9Sstevel@tonic-gate } 9847c478bd9Sstevel@tonic-gate 9857c478bd9Sstevel@tonic-gate /* 9860209230bSgjelinek * Set temporary property to flag as a temporary element. 9870209230bSgjelinek * 9880209230bSgjelinek * PO_FAIL is returned if an error is detected and the error code is updated 9890209230bSgjelinek * to indicate the cause of the error. 9900209230bSgjelinek */ 9910209230bSgjelinek int 9920209230bSgjelinek pool_set_temporary(pool_conf_t *conf, pool_elem_t *pe) 9930209230bSgjelinek { 9940209230bSgjelinek int res; 9950209230bSgjelinek char name[128]; 9960209230bSgjelinek pool_value_t *val; 9970209230bSgjelinek 9980209230bSgjelinek if (pool_conf_check(conf) != PO_SUCCESS) 9990209230bSgjelinek return (PO_FAIL); 10000209230bSgjelinek 10010209230bSgjelinek if (TO_CONF(pe) != conf) { 10020209230bSgjelinek pool_seterror(POE_BADPARAM); 10030209230bSgjelinek return (PO_FAIL); 10040209230bSgjelinek } 10050209230bSgjelinek 10060209230bSgjelinek /* create property name based on element type */ 10070209230bSgjelinek if (snprintf(name, sizeof (name), "%s.temporary", 10080209230bSgjelinek pool_elem_class_string(pe)) > sizeof (name)) { 10090209230bSgjelinek pool_seterror(POE_SYSTEM); 10100209230bSgjelinek return (PO_FAIL); 10110209230bSgjelinek } 10120209230bSgjelinek 10130209230bSgjelinek if ((val = pool_value_alloc()) == NULL) 10140209230bSgjelinek return (PO_FAIL); 10150209230bSgjelinek 10160209230bSgjelinek pool_value_set_bool(val, (uchar_t)1); 10170209230bSgjelinek 10180209230bSgjelinek res = pe->pe_put_prop(pe, name, val); 10190209230bSgjelinek 10200209230bSgjelinek pool_value_free(val); 10210209230bSgjelinek 10220209230bSgjelinek return (res); 10230209230bSgjelinek } 10240209230bSgjelinek 10250209230bSgjelinek /* 10267c478bd9Sstevel@tonic-gate * Update the specified property value with the namespace prepended. 10277c478bd9Sstevel@tonic-gate * e.g. If this function is used to update the property "name" on a pool, it 10287c478bd9Sstevel@tonic-gate * will attempt to update "pool.name". 10297c478bd9Sstevel@tonic-gate * 10307c478bd9Sstevel@tonic-gate * PO_FAIL is returned if an error is detected and the error code is updated 10317c478bd9Sstevel@tonic-gate * to indicate the cause of the error. 10327c478bd9Sstevel@tonic-gate */ 10337c478bd9Sstevel@tonic-gate int 10347c478bd9Sstevel@tonic-gate pool_put_ns_property(pool_elem_t *pe, const char *name, 10357c478bd9Sstevel@tonic-gate const pool_value_t *val) 10367c478bd9Sstevel@tonic-gate { 10377c478bd9Sstevel@tonic-gate char_buf_t *cb; 10387c478bd9Sstevel@tonic-gate int ret; 10397c478bd9Sstevel@tonic-gate 10407c478bd9Sstevel@tonic-gate if ((cb = alloc_char_buf(CB_DEFAULT_LEN)) == NULL) 10417c478bd9Sstevel@tonic-gate return (PO_FAIL); 10427c478bd9Sstevel@tonic-gate if (set_char_buf(cb, "%s.%s", pool_elem_class_string(pe), name) == 10437c478bd9Sstevel@tonic-gate PO_FAIL) { 10447c478bd9Sstevel@tonic-gate free_char_buf(cb); 10457c478bd9Sstevel@tonic-gate return (PO_FAIL); 10467c478bd9Sstevel@tonic-gate } 10477c478bd9Sstevel@tonic-gate ret = pool_put_property(TO_CONF(pe), pe, cb->cb_buf, val); 10487c478bd9Sstevel@tonic-gate free_char_buf(cb); 10497c478bd9Sstevel@tonic-gate return (ret); 10507c478bd9Sstevel@tonic-gate } 10517c478bd9Sstevel@tonic-gate 10527c478bd9Sstevel@tonic-gate /* 10537c478bd9Sstevel@tonic-gate * Update the specified property value. Do not use the property 10547c478bd9Sstevel@tonic-gate * protection mechanism. This function should only be used for cases 10557c478bd9Sstevel@tonic-gate * where the library must bypass the normal property protection 10567c478bd9Sstevel@tonic-gate * mechanism. The only known use is to update properties in the static 10577c478bd9Sstevel@tonic-gate * configuration when performing a commit. 10587c478bd9Sstevel@tonic-gate * 10597c478bd9Sstevel@tonic-gate * PO_FAIL is returned if an error is detected and the error code is 10607c478bd9Sstevel@tonic-gate * updated to indicate the cause of the error. 10617c478bd9Sstevel@tonic-gate */ 10627c478bd9Sstevel@tonic-gate int 10637c478bd9Sstevel@tonic-gate pool_put_any_property(pool_elem_t *pe, const char *name, 10647c478bd9Sstevel@tonic-gate const pool_value_t *val) 10657c478bd9Sstevel@tonic-gate { 10667c478bd9Sstevel@tonic-gate if (!is_valid_prop_name(name)) { 10677c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 10687c478bd9Sstevel@tonic-gate return (PO_FAIL); 10697c478bd9Sstevel@tonic-gate } 10707c478bd9Sstevel@tonic-gate 10717c478bd9Sstevel@tonic-gate return (pe->pe_put_prop(pe, name, val)); 10727c478bd9Sstevel@tonic-gate } 10737c478bd9Sstevel@tonic-gate 10747c478bd9Sstevel@tonic-gate /* 10757c478bd9Sstevel@tonic-gate * Update the specified property value with the namespace prepended. 10767c478bd9Sstevel@tonic-gate * e.g. If this function is used to update the property "name" on a pool, it 10777c478bd9Sstevel@tonic-gate * will attempt to update "pool.name". 10787c478bd9Sstevel@tonic-gate * 10797c478bd9Sstevel@tonic-gate * PO_FAIL is returned if an error is detected and the error code is updated 10807c478bd9Sstevel@tonic-gate * to indicate the cause of the error. 10817c478bd9Sstevel@tonic-gate */ 10827c478bd9Sstevel@tonic-gate int 10837c478bd9Sstevel@tonic-gate pool_put_any_ns_property(pool_elem_t *pe, const char *name, 10847c478bd9Sstevel@tonic-gate const pool_value_t *val) 10857c478bd9Sstevel@tonic-gate { 10867c478bd9Sstevel@tonic-gate char_buf_t *cb; 10877c478bd9Sstevel@tonic-gate int ret; 10887c478bd9Sstevel@tonic-gate 10897c478bd9Sstevel@tonic-gate if ((cb = alloc_char_buf(CB_DEFAULT_LEN)) == NULL) 10907c478bd9Sstevel@tonic-gate return (PO_FAIL); 10917c478bd9Sstevel@tonic-gate if (set_char_buf(cb, "%s.%s", pool_elem_class_string(pe), name) == 10927c478bd9Sstevel@tonic-gate PO_FAIL) { 10937c478bd9Sstevel@tonic-gate free_char_buf(cb); 10947c478bd9Sstevel@tonic-gate return (PO_FAIL); 10957c478bd9Sstevel@tonic-gate } 10967c478bd9Sstevel@tonic-gate ret = pool_put_any_property(pe, cb->cb_buf, val); 10977c478bd9Sstevel@tonic-gate free_char_buf(cb); 10987c478bd9Sstevel@tonic-gate return (ret); 10997c478bd9Sstevel@tonic-gate } 11007c478bd9Sstevel@tonic-gate 11017c478bd9Sstevel@tonic-gate /* 11027c478bd9Sstevel@tonic-gate * Remove the specified property value. Note that some properties are 11037c478bd9Sstevel@tonic-gate * mandatory and thus failure to remove these properties is inevitable. 11047c478bd9Sstevel@tonic-gate * PO_FAIL is returned if an error is detected and the error code is updated 11057c478bd9Sstevel@tonic-gate * to indicate the cause of the error. 11067c478bd9Sstevel@tonic-gate */ 11077c478bd9Sstevel@tonic-gate int 11087c478bd9Sstevel@tonic-gate pool_rm_property(pool_conf_t *conf, pool_elem_t *pe, const char *name) 11097c478bd9Sstevel@tonic-gate { 11107c478bd9Sstevel@tonic-gate const pool_prop_t *prop_info; 11117c478bd9Sstevel@tonic-gate 11127c478bd9Sstevel@tonic-gate if (pool_conf_check(conf) != PO_SUCCESS) 11137c478bd9Sstevel@tonic-gate return (PO_FAIL); 11147c478bd9Sstevel@tonic-gate 11157c478bd9Sstevel@tonic-gate if (TO_CONF(pe) != conf) { 11167c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 11177c478bd9Sstevel@tonic-gate return (NULL); 11187c478bd9Sstevel@tonic-gate } 11197c478bd9Sstevel@tonic-gate 11200209230bSgjelinek /* Don't allow removal of the "temporary" property */ 11210209230bSgjelinek if (strstr(name, ".temporary") != NULL) { 11220209230bSgjelinek pool_seterror(POE_BADPARAM); 11230209230bSgjelinek return (PO_FAIL); 11240209230bSgjelinek } 11250209230bSgjelinek 11267c478bd9Sstevel@tonic-gate /* 11277c478bd9Sstevel@tonic-gate * Check to see if this is a property we are managing. If it is, 11287c478bd9Sstevel@tonic-gate * ensure that we are happy with what the user is doing. 11297c478bd9Sstevel@tonic-gate */ 11307c478bd9Sstevel@tonic-gate if ((prop_info = provider_get_prop(pe, name)) != NULL) { 11317c478bd9Sstevel@tonic-gate if (prop_is_optional(prop_info) == PO_FALSE) { 11327c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 11337c478bd9Sstevel@tonic-gate return (PO_FAIL); 11347c478bd9Sstevel@tonic-gate } 11357c478bd9Sstevel@tonic-gate } 11367c478bd9Sstevel@tonic-gate return (pe->pe_rm_prop(pe, name)); 11377c478bd9Sstevel@tonic-gate } 11387c478bd9Sstevel@tonic-gate 11397c478bd9Sstevel@tonic-gate /* 11407c478bd9Sstevel@tonic-gate * Check if the supplied name is a namespace protected property for the supplied 11417c478bd9Sstevel@tonic-gate * element, pe. If it is, return the prefix, otherwise just return NULL. 11427c478bd9Sstevel@tonic-gate */ 11437c478bd9Sstevel@tonic-gate const char * 11447c478bd9Sstevel@tonic-gate is_ns_property(const pool_elem_t *pe, const char *name) 11457c478bd9Sstevel@tonic-gate { 11467c478bd9Sstevel@tonic-gate const char *prefix; 11477c478bd9Sstevel@tonic-gate 11487c478bd9Sstevel@tonic-gate if ((prefix = pool_elem_class_string(pe)) != NULL) { 11497c478bd9Sstevel@tonic-gate if (strncmp(name, prefix, strlen(prefix)) == 0) 11507c478bd9Sstevel@tonic-gate return (prefix); 11517c478bd9Sstevel@tonic-gate } 11527c478bd9Sstevel@tonic-gate return (NULL); 11537c478bd9Sstevel@tonic-gate } 11547c478bd9Sstevel@tonic-gate 11557c478bd9Sstevel@tonic-gate /* 11567c478bd9Sstevel@tonic-gate * Check if the supplied name is a namespace protected property for the supplied 11577c478bd9Sstevel@tonic-gate * element, pe. If it is, return the property name with the namespace stripped, 11587c478bd9Sstevel@tonic-gate * otherwise just return the name. 11597c478bd9Sstevel@tonic-gate */ 11607c478bd9Sstevel@tonic-gate const char * 11617c478bd9Sstevel@tonic-gate property_name_minus_ns(const pool_elem_t *pe, const char *name) 11627c478bd9Sstevel@tonic-gate { 11637c478bd9Sstevel@tonic-gate const char *prefix; 11647c478bd9Sstevel@tonic-gate if ((prefix = is_ns_property(pe, name)) != NULL) { 11657c478bd9Sstevel@tonic-gate return (name + strlen(prefix) + 1); 11667c478bd9Sstevel@tonic-gate } 11677c478bd9Sstevel@tonic-gate return (name); 11687c478bd9Sstevel@tonic-gate } 11697c478bd9Sstevel@tonic-gate 11707c478bd9Sstevel@tonic-gate /* 11717c478bd9Sstevel@tonic-gate * Create an element to represent a pool and add it to the supplied 11727c478bd9Sstevel@tonic-gate * configuration. 11737c478bd9Sstevel@tonic-gate */ 11747c478bd9Sstevel@tonic-gate pool_t * 11757c478bd9Sstevel@tonic-gate pool_create(pool_conf_t *conf, const char *name) 11767c478bd9Sstevel@tonic-gate { 11777c478bd9Sstevel@tonic-gate pool_elem_t *pe; 11787c478bd9Sstevel@tonic-gate pool_value_t val = POOL_VALUE_INITIALIZER; 11797c478bd9Sstevel@tonic-gate const pool_prop_t *default_props; 11807c478bd9Sstevel@tonic-gate 11817c478bd9Sstevel@tonic-gate if (pool_conf_check(conf) != PO_SUCCESS) 11827c478bd9Sstevel@tonic-gate return (NULL); 11837c478bd9Sstevel@tonic-gate 11847c478bd9Sstevel@tonic-gate if (!is_valid_name(name) || pool_get_pool(conf, name) != NULL) { 11857c478bd9Sstevel@tonic-gate /* 11867c478bd9Sstevel@tonic-gate * A pool with the same name exists. Reject. 11877c478bd9Sstevel@tonic-gate */ 11887c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 11897c478bd9Sstevel@tonic-gate return (NULL); 11907c478bd9Sstevel@tonic-gate } 11917c478bd9Sstevel@tonic-gate if ((pe = conf->pc_prov->pc_elem_create(conf, PEC_POOL, PREC_INVALID, 11927c478bd9Sstevel@tonic-gate PCEC_INVALID)) == NULL) { 11937c478bd9Sstevel@tonic-gate pool_seterror(POE_INVALID_CONF); 11947c478bd9Sstevel@tonic-gate return (NULL); 11957c478bd9Sstevel@tonic-gate } 11967c478bd9Sstevel@tonic-gate if ((default_props = provider_get_props(pe)) != NULL) { 11977c478bd9Sstevel@tonic-gate int i; 11987c478bd9Sstevel@tonic-gate for (i = 0; default_props[i].pp_pname != NULL; i++) { 11997c478bd9Sstevel@tonic-gate if (prop_is_init(&default_props[i]) && 12007c478bd9Sstevel@tonic-gate (pool_put_any_property(pe, 12017c478bd9Sstevel@tonic-gate default_props[i].pp_pname, 12027c478bd9Sstevel@tonic-gate &default_props[i].pp_value) == PO_FAIL)) { 12037c478bd9Sstevel@tonic-gate (void) pool_destroy(conf, pool_elem_pool(pe)); 12047c478bd9Sstevel@tonic-gate return (NULL); 12057c478bd9Sstevel@tonic-gate } 12067c478bd9Sstevel@tonic-gate } 12077c478bd9Sstevel@tonic-gate } 12087c478bd9Sstevel@tonic-gate if (pool_value_set_string(&val, name) != PO_SUCCESS) { 12097c478bd9Sstevel@tonic-gate (void) pool_destroy(conf, pool_elem_pool(pe)); 12107c478bd9Sstevel@tonic-gate pool_seterror(POE_SYSTEM); 12117c478bd9Sstevel@tonic-gate return (NULL); 12127c478bd9Sstevel@tonic-gate } 12137c478bd9Sstevel@tonic-gate if (pool_put_property(conf, pe, "pool.name", &val) == PO_FAIL) { 12147c478bd9Sstevel@tonic-gate (void) pool_destroy(conf, pool_elem_pool(pe)); 12157c478bd9Sstevel@tonic-gate pool_seterror(POE_PUTPROP); 12167c478bd9Sstevel@tonic-gate return (NULL); 12177c478bd9Sstevel@tonic-gate } 12180209230bSgjelinek 12190209230bSgjelinek /* 12200209230bSgjelinek * If we are creating a temporary pool configuration, flag the pool. 12210209230bSgjelinek */ 12220209230bSgjelinek if (conf->pc_prov->pc_oflags & PO_TEMP) { 12230209230bSgjelinek if (pool_set_temporary(conf, pe) == PO_FAIL) { 12240209230bSgjelinek (void) pool_destroy(conf, pool_elem_pool(pe)); 12250209230bSgjelinek return (NULL); 12260209230bSgjelinek } 12270209230bSgjelinek } 12280209230bSgjelinek 12297c478bd9Sstevel@tonic-gate return (pool_elem_pool(pe)); 12307c478bd9Sstevel@tonic-gate } 12317c478bd9Sstevel@tonic-gate 12327c478bd9Sstevel@tonic-gate /* 12337c478bd9Sstevel@tonic-gate * Create an element to represent a res. 12347c478bd9Sstevel@tonic-gate */ 12357c478bd9Sstevel@tonic-gate pool_resource_t * 12367c478bd9Sstevel@tonic-gate pool_resource_create(pool_conf_t *conf, const char *sz_type, const char *name) 12377c478bd9Sstevel@tonic-gate { 12387c478bd9Sstevel@tonic-gate pool_elem_t *pe; 12397c478bd9Sstevel@tonic-gate pool_value_t val = POOL_VALUE_INITIALIZER; 12407c478bd9Sstevel@tonic-gate const pool_prop_t *default_props; 12417c478bd9Sstevel@tonic-gate pool_resource_t **resources; 12427c478bd9Sstevel@tonic-gate int is_default = 0; 12437c478bd9Sstevel@tonic-gate uint_t nelem; 12447c478bd9Sstevel@tonic-gate pool_elem_class_t elem_class; 12457c478bd9Sstevel@tonic-gate pool_resource_elem_class_t type; 12467c478bd9Sstevel@tonic-gate pool_value_t *props[] = { NULL, NULL }; 12477c478bd9Sstevel@tonic-gate 12487c478bd9Sstevel@tonic-gate if (pool_conf_check(conf) != PO_SUCCESS) 12497c478bd9Sstevel@tonic-gate return (NULL); 12507c478bd9Sstevel@tonic-gate 12517c478bd9Sstevel@tonic-gate if ((type = pool_resource_elem_class_from_string(sz_type)) == 12527c478bd9Sstevel@tonic-gate PREC_INVALID) { 12537c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 12547c478bd9Sstevel@tonic-gate return (NULL); 12557c478bd9Sstevel@tonic-gate } 12567c478bd9Sstevel@tonic-gate 12577c478bd9Sstevel@tonic-gate if (strcmp(sz_type, "pset") != 0) { 12587c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 12597c478bd9Sstevel@tonic-gate return (NULL); 12607c478bd9Sstevel@tonic-gate } 12617c478bd9Sstevel@tonic-gate 12627c478bd9Sstevel@tonic-gate if (!is_valid_name(name) || pool_get_resource(conf, sz_type, name) != 12637c478bd9Sstevel@tonic-gate NULL) { 12647c478bd9Sstevel@tonic-gate /* 12657c478bd9Sstevel@tonic-gate * Resources must be unique by name+type. 12667c478bd9Sstevel@tonic-gate */ 12677c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 12687c478bd9Sstevel@tonic-gate return (NULL); 12697c478bd9Sstevel@tonic-gate } 12707c478bd9Sstevel@tonic-gate 12717c478bd9Sstevel@tonic-gate props[0] = &val; 12727c478bd9Sstevel@tonic-gate 12737c478bd9Sstevel@tonic-gate if (pool_value_set_string(props[0], sz_type) != PO_SUCCESS || 12747c478bd9Sstevel@tonic-gate pool_value_set_name(props[0], c_type) != PO_SUCCESS) { 12757c478bd9Sstevel@tonic-gate return (NULL); 12767c478bd9Sstevel@tonic-gate } 12777c478bd9Sstevel@tonic-gate 12787c478bd9Sstevel@tonic-gate if ((resources = pool_query_resources(conf, &nelem, props)) == NULL) { 12797c478bd9Sstevel@tonic-gate /* 12807c478bd9Sstevel@tonic-gate * This is the first representative of this type; when it's 12817c478bd9Sstevel@tonic-gate * created it should be created with 'default' = 'true'. 12827c478bd9Sstevel@tonic-gate */ 12837c478bd9Sstevel@tonic-gate is_default = 1; 12847c478bd9Sstevel@tonic-gate } else { 12857c478bd9Sstevel@tonic-gate free(resources); 12867c478bd9Sstevel@tonic-gate } 12877c478bd9Sstevel@tonic-gate /* 12887c478bd9Sstevel@tonic-gate * TODO: If Additional PEC_RES_COMP types are added to 12897c478bd9Sstevel@tonic-gate * pool_impl.h, this would need to be extended. 12907c478bd9Sstevel@tonic-gate */ 12917c478bd9Sstevel@tonic-gate switch (type) { 12927c478bd9Sstevel@tonic-gate case PREC_PSET: 12937c478bd9Sstevel@tonic-gate elem_class = PEC_RES_COMP; 12947c478bd9Sstevel@tonic-gate break; 12957c478bd9Sstevel@tonic-gate default: 12967c478bd9Sstevel@tonic-gate elem_class = PEC_RES_AGG; 12977c478bd9Sstevel@tonic-gate break; 12987c478bd9Sstevel@tonic-gate } 12997c478bd9Sstevel@tonic-gate if ((pe = conf->pc_prov->pc_elem_create(conf, elem_class, type, 13007c478bd9Sstevel@tonic-gate PCEC_INVALID)) == NULL) { 13017c478bd9Sstevel@tonic-gate pool_seterror(POE_INVALID_CONF); 13027c478bd9Sstevel@tonic-gate return (NULL); 13037c478bd9Sstevel@tonic-gate } 13047c478bd9Sstevel@tonic-gate 13057c478bd9Sstevel@tonic-gate /* 13067c478bd9Sstevel@tonic-gate * The plugins contain a list of default properties and their values 13077c478bd9Sstevel@tonic-gate * for resources. The resource returned, hence, is fully initialized. 13087c478bd9Sstevel@tonic-gate */ 13097c478bd9Sstevel@tonic-gate if ((default_props = provider_get_props(pe)) != NULL) { 13107c478bd9Sstevel@tonic-gate int i; 13117c478bd9Sstevel@tonic-gate for (i = 0; default_props[i].pp_pname != NULL; i++) { 13127c478bd9Sstevel@tonic-gate if (prop_is_init(&default_props[i]) && 13137c478bd9Sstevel@tonic-gate pool_put_any_property(pe, default_props[i].pp_pname, 13147c478bd9Sstevel@tonic-gate &default_props[i].pp_value) == PO_FAIL) { 13157c478bd9Sstevel@tonic-gate (void) pool_resource_destroy(conf, 13167c478bd9Sstevel@tonic-gate pool_elem_res(pe)); 13177c478bd9Sstevel@tonic-gate return (NULL); 13187c478bd9Sstevel@tonic-gate } 13197c478bd9Sstevel@tonic-gate } 13207c478bd9Sstevel@tonic-gate } 13217c478bd9Sstevel@tonic-gate if (pool_value_set_string(&val, name) != PO_SUCCESS || 13227c478bd9Sstevel@tonic-gate pool_put_ns_property(pe, "name", &val) != PO_SUCCESS) { 13237c478bd9Sstevel@tonic-gate (void) pool_resource_destroy(conf, pool_elem_res(pe)); 13247c478bd9Sstevel@tonic-gate return (NULL); 13257c478bd9Sstevel@tonic-gate } 13267c478bd9Sstevel@tonic-gate if (is_default) { 13277c478bd9Sstevel@tonic-gate pool_value_set_bool(&val, PO_TRUE); 13287c478bd9Sstevel@tonic-gate if (pool_put_any_ns_property(pe, "default", &val) != 13297c478bd9Sstevel@tonic-gate PO_SUCCESS) { 13307c478bd9Sstevel@tonic-gate (void) pool_resource_destroy(conf, pool_elem_res(pe)); 13317c478bd9Sstevel@tonic-gate return (NULL); 13327c478bd9Sstevel@tonic-gate } 13337c478bd9Sstevel@tonic-gate } 13340209230bSgjelinek 13350209230bSgjelinek /* 13360209230bSgjelinek * If we are creating a temporary pool configuration, flag the resource. 13370209230bSgjelinek */ 13380209230bSgjelinek if (conf->pc_prov->pc_oflags & PO_TEMP) { 13390209230bSgjelinek if (pool_set_temporary(conf, pe) != PO_SUCCESS) { 13400209230bSgjelinek (void) pool_resource_destroy(conf, pool_elem_res(pe)); 13410209230bSgjelinek return (NULL); 13420209230bSgjelinek } 13430209230bSgjelinek } 13440209230bSgjelinek 13457c478bd9Sstevel@tonic-gate return (pool_elem_res(pe)); 13467c478bd9Sstevel@tonic-gate } 13477c478bd9Sstevel@tonic-gate 13487c478bd9Sstevel@tonic-gate /* 13497c478bd9Sstevel@tonic-gate * Create an element to represent a resource component. 13507c478bd9Sstevel@tonic-gate */ 13517c478bd9Sstevel@tonic-gate pool_component_t * 13527c478bd9Sstevel@tonic-gate pool_component_create(pool_conf_t *conf, const pool_resource_t *res, 13537c478bd9Sstevel@tonic-gate int64_t sys_id) 13547c478bd9Sstevel@tonic-gate { 13557c478bd9Sstevel@tonic-gate pool_elem_t *pe; 13567c478bd9Sstevel@tonic-gate pool_value_t val = POOL_VALUE_INITIALIZER; 13577c478bd9Sstevel@tonic-gate const pool_prop_t *default_props; 13587c478bd9Sstevel@tonic-gate char refbuf[KEY_BUFFER_SIZE]; 13597c478bd9Sstevel@tonic-gate 13607c478bd9Sstevel@tonic-gate if ((pe = conf->pc_prov->pc_elem_create(conf, PEC_COMP, 13617c478bd9Sstevel@tonic-gate PREC_INVALID, PCEC_CPU)) == NULL) { 13627c478bd9Sstevel@tonic-gate pool_seterror(POE_INVALID_CONF); 13637c478bd9Sstevel@tonic-gate return (NULL); 13647c478bd9Sstevel@tonic-gate } 13657c478bd9Sstevel@tonic-gate /* 13667c478bd9Sstevel@tonic-gate * TODO: If additional PEC_COMP types are added in pool_impl.h, 13677c478bd9Sstevel@tonic-gate * this would need to be extended. 13687c478bd9Sstevel@tonic-gate */ 13697c478bd9Sstevel@tonic-gate pe->pe_component_class = PCEC_CPU; 13707c478bd9Sstevel@tonic-gate /* Now set the container for this comp */ 13717c478bd9Sstevel@tonic-gate if (pool_set_container(TO_ELEM(res), pe) == PO_FAIL) { 13727c478bd9Sstevel@tonic-gate (void) pool_component_destroy(pool_elem_comp(pe)); 13737c478bd9Sstevel@tonic-gate return (NULL); 13747c478bd9Sstevel@tonic-gate } 13757c478bd9Sstevel@tonic-gate /* 13767c478bd9Sstevel@tonic-gate * The plugins contain a list of default properties and their values 13777c478bd9Sstevel@tonic-gate * for resources. The resource returned, hence, is fully initialized. 13787c478bd9Sstevel@tonic-gate */ 13797c478bd9Sstevel@tonic-gate if ((default_props = provider_get_props(pe)) != NULL) { 13807c478bd9Sstevel@tonic-gate int i; 13817c478bd9Sstevel@tonic-gate for (i = 0; default_props[i].pp_pname != NULL; i++) { 13827c478bd9Sstevel@tonic-gate if (prop_is_init(&default_props[i]) && 13837c478bd9Sstevel@tonic-gate pool_put_any_property(pe, 13847c478bd9Sstevel@tonic-gate default_props[i].pp_pname, 13857c478bd9Sstevel@tonic-gate &default_props[i].pp_value) == PO_FAIL) { 13867c478bd9Sstevel@tonic-gate (void) pool_component_destroy( 13877c478bd9Sstevel@tonic-gate pool_elem_comp(pe)); 13887c478bd9Sstevel@tonic-gate return (NULL); 13897c478bd9Sstevel@tonic-gate } 13907c478bd9Sstevel@tonic-gate } 13917c478bd9Sstevel@tonic-gate } 13927c478bd9Sstevel@tonic-gate /* 13937c478bd9Sstevel@tonic-gate * Set additional attributes/properties on component. 13947c478bd9Sstevel@tonic-gate */ 13957c478bd9Sstevel@tonic-gate pool_value_set_int64(&val, sys_id); 13967c478bd9Sstevel@tonic-gate if (pool_put_any_ns_property(pe, c_sys_prop, &val) != PO_SUCCESS) { 13977c478bd9Sstevel@tonic-gate (void) pool_component_destroy(pool_elem_comp(pe)); 13987c478bd9Sstevel@tonic-gate return (NULL); 13997c478bd9Sstevel@tonic-gate } 14007c478bd9Sstevel@tonic-gate if (snprintf(refbuf, KEY_BUFFER_SIZE, "%s_%lld", 14017c478bd9Sstevel@tonic-gate pool_elem_class_string(pe), sys_id) > KEY_BUFFER_SIZE) { 14027c478bd9Sstevel@tonic-gate (void) pool_component_destroy(pool_elem_comp(pe)); 14037c478bd9Sstevel@tonic-gate return (NULL); 14047c478bd9Sstevel@tonic-gate } 14057c478bd9Sstevel@tonic-gate if (pool_value_set_string(&val, refbuf) != PO_SUCCESS) { 14067c478bd9Sstevel@tonic-gate (void) pool_component_destroy(pool_elem_comp(pe)); 14077c478bd9Sstevel@tonic-gate return (NULL); 14087c478bd9Sstevel@tonic-gate } 14097c478bd9Sstevel@tonic-gate if (pool_put_any_ns_property(pe, c_ref_id, &val) != PO_SUCCESS) { 14107c478bd9Sstevel@tonic-gate (void) pool_component_destroy(pool_elem_comp(pe)); 14117c478bd9Sstevel@tonic-gate return (NULL); 14127c478bd9Sstevel@tonic-gate } 14137c478bd9Sstevel@tonic-gate return (pool_elem_comp(pe)); 14147c478bd9Sstevel@tonic-gate } 14157c478bd9Sstevel@tonic-gate 14167c478bd9Sstevel@tonic-gate /* 14177c478bd9Sstevel@tonic-gate * Return the location of a configuration. 14187c478bd9Sstevel@tonic-gate */ 14197c478bd9Sstevel@tonic-gate const char * 14207c478bd9Sstevel@tonic-gate pool_conf_location(const pool_conf_t *conf) 14217c478bd9Sstevel@tonic-gate { 14227c478bd9Sstevel@tonic-gate if (pool_conf_status(conf) == POF_INVALID) { 14237c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 14247c478bd9Sstevel@tonic-gate return (NULL); 14257c478bd9Sstevel@tonic-gate } 14267c478bd9Sstevel@tonic-gate return (conf->pc_location); 14277c478bd9Sstevel@tonic-gate } 14287c478bd9Sstevel@tonic-gate /* 14297c478bd9Sstevel@tonic-gate * Close a configuration, freeing all associated resources. Once a 14307c478bd9Sstevel@tonic-gate * configuration is closed, it can no longer be used. 14317c478bd9Sstevel@tonic-gate */ 14327c478bd9Sstevel@tonic-gate int 14337c478bd9Sstevel@tonic-gate pool_conf_close(pool_conf_t *conf) 14347c478bd9Sstevel@tonic-gate { 14357c478bd9Sstevel@tonic-gate int rv; 14367c478bd9Sstevel@tonic-gate 14377c478bd9Sstevel@tonic-gate if (pool_conf_status(conf) == POF_INVALID) { 14387c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 14397c478bd9Sstevel@tonic-gate return (PO_FAIL); 14407c478bd9Sstevel@tonic-gate } 14417c478bd9Sstevel@tonic-gate rv = conf->pc_prov->pc_close(conf); 14427c478bd9Sstevel@tonic-gate conf->pc_prov = NULL; 14437c478bd9Sstevel@tonic-gate free((void *)conf->pc_location); 14447c478bd9Sstevel@tonic-gate conf->pc_location = NULL; 14457c478bd9Sstevel@tonic-gate conf->pc_state = POF_INVALID; 14467c478bd9Sstevel@tonic-gate return (rv); 14477c478bd9Sstevel@tonic-gate } 14487c478bd9Sstevel@tonic-gate 14497c478bd9Sstevel@tonic-gate /* 14507c478bd9Sstevel@tonic-gate * Remove a configuration, freeing all associated resources. Once a 14517c478bd9Sstevel@tonic-gate * configuration is removed, it can no longer be accessed and is forever 14527c478bd9Sstevel@tonic-gate * gone. 14537c478bd9Sstevel@tonic-gate */ 14547c478bd9Sstevel@tonic-gate int 14557c478bd9Sstevel@tonic-gate pool_conf_remove(pool_conf_t *conf) 14567c478bd9Sstevel@tonic-gate { 14577c478bd9Sstevel@tonic-gate int rv; 14587c478bd9Sstevel@tonic-gate 14597c478bd9Sstevel@tonic-gate if (pool_conf_status(conf) == POF_INVALID) { 14607c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 14617c478bd9Sstevel@tonic-gate return (PO_FAIL); 14627c478bd9Sstevel@tonic-gate } 14637c478bd9Sstevel@tonic-gate rv = conf->pc_prov->pc_remove(conf); 14647c478bd9Sstevel@tonic-gate conf->pc_state = POF_INVALID; 14657c478bd9Sstevel@tonic-gate return (rv); 14667c478bd9Sstevel@tonic-gate } 14677c478bd9Sstevel@tonic-gate 14687c478bd9Sstevel@tonic-gate /* 14697c478bd9Sstevel@tonic-gate * pool_conf_alloc() allocate the resources to represent a configuration. 14707c478bd9Sstevel@tonic-gate */ 14717c478bd9Sstevel@tonic-gate pool_conf_t * 14727c478bd9Sstevel@tonic-gate pool_conf_alloc(void) 14737c478bd9Sstevel@tonic-gate { 14747c478bd9Sstevel@tonic-gate pool_conf_t *conf; 14757c478bd9Sstevel@tonic-gate 14767c478bd9Sstevel@tonic-gate if ((conf = calloc(1, sizeof (pool_conf_t))) == NULL) { 14777c478bd9Sstevel@tonic-gate pool_seterror(POE_SYSTEM); 14787c478bd9Sstevel@tonic-gate return (NULL); 14797c478bd9Sstevel@tonic-gate } 14807c478bd9Sstevel@tonic-gate conf->pc_state = POF_INVALID; 14817c478bd9Sstevel@tonic-gate return (conf); 14827c478bd9Sstevel@tonic-gate } 14837c478bd9Sstevel@tonic-gate 14847c478bd9Sstevel@tonic-gate /* 14857c478bd9Sstevel@tonic-gate * pool_conf_free() frees the resources associated with a configuration. 14867c478bd9Sstevel@tonic-gate */ 14877c478bd9Sstevel@tonic-gate void 14887c478bd9Sstevel@tonic-gate pool_conf_free(pool_conf_t *conf) 14897c478bd9Sstevel@tonic-gate { 14907c478bd9Sstevel@tonic-gate free(conf); 14917c478bd9Sstevel@tonic-gate } 14927c478bd9Sstevel@tonic-gate 14937c478bd9Sstevel@tonic-gate /* 14947c478bd9Sstevel@tonic-gate * pool_conf_open() opens a configuration, establishing all required 14957c478bd9Sstevel@tonic-gate * connections to the data source. 14967c478bd9Sstevel@tonic-gate */ 14977c478bd9Sstevel@tonic-gate int 14987c478bd9Sstevel@tonic-gate pool_conf_open(pool_conf_t *conf, const char *location, int oflags) 14997c478bd9Sstevel@tonic-gate { 15007c478bd9Sstevel@tonic-gate /* 15017c478bd9Sstevel@tonic-gate * Since you can't do anything to a pool configuration without opening 15027c478bd9Sstevel@tonic-gate * it, this represents a good point to intialise structures that would 15037c478bd9Sstevel@tonic-gate * otherwise need to be initialised in a .init section. 15047c478bd9Sstevel@tonic-gate */ 15057c478bd9Sstevel@tonic-gate internal_init(); 15067c478bd9Sstevel@tonic-gate 15077c478bd9Sstevel@tonic-gate if (pool_conf_status(conf) != POF_INVALID) { 15087c478bd9Sstevel@tonic-gate /* 15097c478bd9Sstevel@tonic-gate * Already opened configuration, return PO_FAIL 15107c478bd9Sstevel@tonic-gate */ 15117c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 15127c478bd9Sstevel@tonic-gate return (PO_FAIL); 15137c478bd9Sstevel@tonic-gate } 15140209230bSgjelinek if (oflags & ~(PO_RDONLY | PO_RDWR | PO_CREAT | PO_DISCO | PO_UPDATE | 15150209230bSgjelinek PO_TEMP)) { 15167c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 15177c478bd9Sstevel@tonic-gate return (PO_FAIL); 15187c478bd9Sstevel@tonic-gate } 15197c478bd9Sstevel@tonic-gate 15207c478bd9Sstevel@tonic-gate /* 15217c478bd9Sstevel@tonic-gate * Creating a configuration implies read-write access, so make 15227c478bd9Sstevel@tonic-gate * sure that PO_RDWR is set in addition if PO_CREAT is set. 15237c478bd9Sstevel@tonic-gate */ 15247c478bd9Sstevel@tonic-gate if (oflags & PO_CREAT) 15257c478bd9Sstevel@tonic-gate oflags |= PO_RDWR; 15267c478bd9Sstevel@tonic-gate 15270209230bSgjelinek /* location is ignored when creating a temporary configuration */ 15280209230bSgjelinek if (oflags & PO_TEMP) 15290209230bSgjelinek location = ""; 15300209230bSgjelinek 15317c478bd9Sstevel@tonic-gate if ((conf->pc_location = strdup(location)) == NULL) { 15327c478bd9Sstevel@tonic-gate pool_seterror(POE_SYSTEM); 15337c478bd9Sstevel@tonic-gate return (PO_FAIL); 15347c478bd9Sstevel@tonic-gate } 15357c478bd9Sstevel@tonic-gate /* 15367c478bd9Sstevel@tonic-gate * This is the crossover point into the actual data provider 15377c478bd9Sstevel@tonic-gate * implementation, allocate a data provider of the appropriate 15380209230bSgjelinek * type for your data storage medium. In this case it's either a kernel 15390209230bSgjelinek * or xml data provider. To use a different data provider, write some 15400209230bSgjelinek * code to implement all the required interfaces and then change the 15410209230bSgjelinek * following code to allocate a data provider which uses your new code. 15420209230bSgjelinek * All data provider routines can be static, apart from the allocation 15430209230bSgjelinek * routine. 15440209230bSgjelinek * 15450209230bSgjelinek * For temporary pools (PO_TEMP) we start with a copy of the current 15460209230bSgjelinek * dynamic configuration and do all of the updates in-memory. 15477c478bd9Sstevel@tonic-gate */ 15480209230bSgjelinek if (oflags & PO_TEMP) { 15490209230bSgjelinek if (pool_knl_connection_alloc(conf, PO_TEMP) != PO_SUCCESS) { 15500209230bSgjelinek conf->pc_state = POF_INVALID; 15510209230bSgjelinek return (PO_FAIL); 15520209230bSgjelinek } 15530209230bSgjelinek /* set rdwr flag so we can updated the in-memory config. */ 15540209230bSgjelinek conf->pc_prov->pc_oflags |= PO_RDWR; 15550209230bSgjelinek 15560209230bSgjelinek } else if (strcmp(location, pool_dynamic_location()) == 0) { 15577c478bd9Sstevel@tonic-gate if (pool_knl_connection_alloc(conf, oflags) != PO_SUCCESS) { 15587c478bd9Sstevel@tonic-gate conf->pc_state = POF_INVALID; 15597c478bd9Sstevel@tonic-gate return (PO_FAIL); 15607c478bd9Sstevel@tonic-gate } 15617c478bd9Sstevel@tonic-gate } else { 15627c478bd9Sstevel@tonic-gate if (pool_xml_connection_alloc(conf, oflags) != PO_SUCCESS) { 15637c478bd9Sstevel@tonic-gate conf->pc_state = POF_INVALID; 15647c478bd9Sstevel@tonic-gate return (PO_FAIL); 15657c478bd9Sstevel@tonic-gate } 15667c478bd9Sstevel@tonic-gate } 15677c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 15687c478bd9Sstevel@tonic-gate } 15697c478bd9Sstevel@tonic-gate 15707c478bd9Sstevel@tonic-gate /* 15717c478bd9Sstevel@tonic-gate * Rollback a configuration. This will undo all changes to the configuration 15727c478bd9Sstevel@tonic-gate * since the last time pool_conf_commit was called. 15737c478bd9Sstevel@tonic-gate */ 15747c478bd9Sstevel@tonic-gate int 15757c478bd9Sstevel@tonic-gate pool_conf_rollback(pool_conf_t *conf) 15767c478bd9Sstevel@tonic-gate { 15777c478bd9Sstevel@tonic-gate if (pool_conf_status(conf) == POF_INVALID) { 15787c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 15797c478bd9Sstevel@tonic-gate return (PO_FAIL); 15807c478bd9Sstevel@tonic-gate } 15817c478bd9Sstevel@tonic-gate return (conf->pc_prov->pc_rollback(conf)); 15827c478bd9Sstevel@tonic-gate } 15837c478bd9Sstevel@tonic-gate 15847c478bd9Sstevel@tonic-gate /* 15857c478bd9Sstevel@tonic-gate * Commit a configuration. This will apply all changes to the 15867c478bd9Sstevel@tonic-gate * configuration to the permanent data store. The active parameter 15877c478bd9Sstevel@tonic-gate * indicates whether the configuration should be used to update the 15887c478bd9Sstevel@tonic-gate * dynamic configuration from the supplied (static) configuration or 15897c478bd9Sstevel@tonic-gate * whether it should be written back to persistent store. 15907c478bd9Sstevel@tonic-gate */ 15917c478bd9Sstevel@tonic-gate int 15927c478bd9Sstevel@tonic-gate pool_conf_commit(pool_conf_t *conf, int active) 15937c478bd9Sstevel@tonic-gate { 15947c478bd9Sstevel@tonic-gate int retval; 15957c478bd9Sstevel@tonic-gate 15967c478bd9Sstevel@tonic-gate if (pool_conf_status(conf) == POF_INVALID) { 15977c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 15987c478bd9Sstevel@tonic-gate return (PO_FAIL); 15997c478bd9Sstevel@tonic-gate } 16007c478bd9Sstevel@tonic-gate if (active) { 16017c478bd9Sstevel@tonic-gate int oflags; 16027c478bd9Sstevel@tonic-gate 16037c478bd9Sstevel@tonic-gate if (conf_is_dynamic(conf) == PO_TRUE) { 16047c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 16057c478bd9Sstevel@tonic-gate return (PO_FAIL); 16067c478bd9Sstevel@tonic-gate } 16077c478bd9Sstevel@tonic-gate /* 16087c478bd9Sstevel@tonic-gate * Pretend that the configuration was opened PO_RDWR 16097c478bd9Sstevel@tonic-gate * so that a configuration which was opened PO_RDONLY 16107c478bd9Sstevel@tonic-gate * can be committed. The original flags are preserved 16117c478bd9Sstevel@tonic-gate * in oflags and restored after pool_conf_commit_sys() 16127c478bd9Sstevel@tonic-gate * returns. 16137c478bd9Sstevel@tonic-gate */ 16147c478bd9Sstevel@tonic-gate oflags = conf->pc_prov->pc_oflags; 16157c478bd9Sstevel@tonic-gate conf->pc_prov->pc_oflags |= PO_RDWR; 16167c478bd9Sstevel@tonic-gate retval = pool_conf_commit_sys(conf, active); 16177c478bd9Sstevel@tonic-gate conf->pc_prov->pc_oflags = oflags; 16187c478bd9Sstevel@tonic-gate } else { 16197c478bd9Sstevel@tonic-gate /* 16207c478bd9Sstevel@tonic-gate * Write the configuration back to the backing store. 16217c478bd9Sstevel@tonic-gate */ 16227c478bd9Sstevel@tonic-gate retval = conf->pc_prov->pc_commit(conf); 16237c478bd9Sstevel@tonic-gate } 16247c478bd9Sstevel@tonic-gate return (retval); 16257c478bd9Sstevel@tonic-gate } 16267c478bd9Sstevel@tonic-gate 16277c478bd9Sstevel@tonic-gate /* 16287c478bd9Sstevel@tonic-gate * Export a configuration. This will export a configuration in the specified 16297c478bd9Sstevel@tonic-gate * format (fmt) to the specified location. 16307c478bd9Sstevel@tonic-gate */ 16317c478bd9Sstevel@tonic-gate int 16327c478bd9Sstevel@tonic-gate pool_conf_export(const pool_conf_t *conf, const char *location, 16337c478bd9Sstevel@tonic-gate pool_export_format_t fmt) 16347c478bd9Sstevel@tonic-gate { 16357c478bd9Sstevel@tonic-gate if (pool_conf_status(conf) == POF_INVALID) { 16367c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 16377c478bd9Sstevel@tonic-gate return (PO_FAIL); 16387c478bd9Sstevel@tonic-gate } 16397c478bd9Sstevel@tonic-gate return (conf->pc_prov->pc_export(conf, location, fmt)); 16407c478bd9Sstevel@tonic-gate } 16417c478bd9Sstevel@tonic-gate 16427c478bd9Sstevel@tonic-gate /* 16437c478bd9Sstevel@tonic-gate * Validate a configuration. This will validate a configuration at the 16447c478bd9Sstevel@tonic-gate * specified level. 16457c478bd9Sstevel@tonic-gate */ 16467c478bd9Sstevel@tonic-gate int 16477c478bd9Sstevel@tonic-gate pool_conf_validate(const pool_conf_t *conf, pool_valid_level_t level) 16487c478bd9Sstevel@tonic-gate { 16497c478bd9Sstevel@tonic-gate if (pool_conf_status(conf) == POF_INVALID) { 16507c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 16517c478bd9Sstevel@tonic-gate return (PO_FAIL); 16527c478bd9Sstevel@tonic-gate } 16537c478bd9Sstevel@tonic-gate return (conf->pc_prov->pc_validate(conf, level)); 16547c478bd9Sstevel@tonic-gate } 16557c478bd9Sstevel@tonic-gate 16567c478bd9Sstevel@tonic-gate /* 16577c478bd9Sstevel@tonic-gate * Update the snapshot of a configuration. This can only be used on a 16587c478bd9Sstevel@tonic-gate * dynamic configuration. 16597c478bd9Sstevel@tonic-gate */ 16607c478bd9Sstevel@tonic-gate int 16617c478bd9Sstevel@tonic-gate pool_conf_update(const pool_conf_t *conf, int *changed) 16627c478bd9Sstevel@tonic-gate { 16637c478bd9Sstevel@tonic-gate if (pool_conf_status(conf) == POF_INVALID || 16647c478bd9Sstevel@tonic-gate conf_is_dynamic(conf) == PO_FALSE) { 16657c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 16667c478bd9Sstevel@tonic-gate return (PO_FAIL); 16677c478bd9Sstevel@tonic-gate } 16687c478bd9Sstevel@tonic-gate /* 16697c478bd9Sstevel@tonic-gate * Since this function only makes sense for dynamic 16707c478bd9Sstevel@tonic-gate * configurations, just call directly into the appropriate 16717c478bd9Sstevel@tonic-gate * function. This could be added into the pool_connection_t 16727c478bd9Sstevel@tonic-gate * interface if it was ever required. 16737c478bd9Sstevel@tonic-gate */ 16747c478bd9Sstevel@tonic-gate if (changed) 16757c478bd9Sstevel@tonic-gate *changed = 0; 16767c478bd9Sstevel@tonic-gate return (pool_knl_update((pool_conf_t *)conf, changed)); 16777c478bd9Sstevel@tonic-gate } 16787c478bd9Sstevel@tonic-gate 16797c478bd9Sstevel@tonic-gate /* 16807c478bd9Sstevel@tonic-gate * Walk the properties of the supplied elem, calling the user supplied 16817c478bd9Sstevel@tonic-gate * function repeatedly as long as the user function returns 16827c478bd9Sstevel@tonic-gate * PO_SUCCESS. 16837c478bd9Sstevel@tonic-gate */ 16847c478bd9Sstevel@tonic-gate int 16857c478bd9Sstevel@tonic-gate pool_walk_properties(pool_conf_t *conf, pool_elem_t *elem, void *arg, 16867c478bd9Sstevel@tonic-gate int (*prop_callback)(pool_conf_t *, pool_elem_t *, const char *, 16877c478bd9Sstevel@tonic-gate pool_value_t *, void *)) 16887c478bd9Sstevel@tonic-gate { 16897c478bd9Sstevel@tonic-gate return (pool_walk_any_properties(conf, elem, arg, prop_callback, 0)); 16907c478bd9Sstevel@tonic-gate } 16917c478bd9Sstevel@tonic-gate 16927c478bd9Sstevel@tonic-gate void 16937c478bd9Sstevel@tonic-gate free_value_list(int npvals, pool_value_t **pvals) 16947c478bd9Sstevel@tonic-gate { 16957c478bd9Sstevel@tonic-gate int j; 16967c478bd9Sstevel@tonic-gate 16977c478bd9Sstevel@tonic-gate for (j = 0; j < npvals; j++) { 16987c478bd9Sstevel@tonic-gate if (pvals[j]) 16997c478bd9Sstevel@tonic-gate pool_value_free(pvals[j]); 17007c478bd9Sstevel@tonic-gate } 17017c478bd9Sstevel@tonic-gate free(pvals); 17027c478bd9Sstevel@tonic-gate } 17037c478bd9Sstevel@tonic-gate 17047c478bd9Sstevel@tonic-gate /* 17057c478bd9Sstevel@tonic-gate * Walk the properties of the supplied elem, calling the user supplied 17067c478bd9Sstevel@tonic-gate * function repeatedly as long as the user function returns 17077c478bd9Sstevel@tonic-gate * PO_SUCCESS. 17087c478bd9Sstevel@tonic-gate * The list of properties to be walked is retrieved from the element 17097c478bd9Sstevel@tonic-gate */ 17107c478bd9Sstevel@tonic-gate int 17117c478bd9Sstevel@tonic-gate pool_walk_any_properties(pool_conf_t *conf, pool_elem_t *elem, void *arg, 17127c478bd9Sstevel@tonic-gate int (*prop_callback)(pool_conf_t *, pool_elem_t *, const char *, 17137c478bd9Sstevel@tonic-gate pool_value_t *, void *), int any) 17147c478bd9Sstevel@tonic-gate { 17157c478bd9Sstevel@tonic-gate pool_value_t **pvals; 17167c478bd9Sstevel@tonic-gate int i; 17177c478bd9Sstevel@tonic-gate const pool_prop_t *props = provider_get_props(elem); 17187c478bd9Sstevel@tonic-gate uint_t npvals; 17197c478bd9Sstevel@tonic-gate 17207c478bd9Sstevel@tonic-gate if (pool_conf_status(conf) == POF_INVALID) { 17217c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 17227c478bd9Sstevel@tonic-gate return (PO_FAIL); 17237c478bd9Sstevel@tonic-gate } 17247c478bd9Sstevel@tonic-gate 17257c478bd9Sstevel@tonic-gate if (props == NULL) { 17267c478bd9Sstevel@tonic-gate pool_seterror(POE_INVALID_CONF); 17277c478bd9Sstevel@tonic-gate return (PO_FAIL); 17287c478bd9Sstevel@tonic-gate } 17297c478bd9Sstevel@tonic-gate 17307c478bd9Sstevel@tonic-gate if ((pvals = elem->pe_get_props(elem, &npvals)) == NULL) 17317c478bd9Sstevel@tonic-gate return (PO_FAIL); 17327c478bd9Sstevel@tonic-gate 17337c478bd9Sstevel@tonic-gate /* 17347c478bd9Sstevel@tonic-gate * Now walk the managed properties. As we find managed 17357c478bd9Sstevel@tonic-gate * properties removed them from the list of all properties to 17367c478bd9Sstevel@tonic-gate * prevent duplication. 17377c478bd9Sstevel@tonic-gate */ 17387c478bd9Sstevel@tonic-gate for (i = 0; props[i].pp_pname != NULL; i++) { 17397c478bd9Sstevel@tonic-gate int j; 17407c478bd9Sstevel@tonic-gate 17417c478bd9Sstevel@tonic-gate /* 17427c478bd9Sstevel@tonic-gate * Special processing for type 17437c478bd9Sstevel@tonic-gate */ 17447c478bd9Sstevel@tonic-gate if (strcmp(props[i].pp_pname, c_type) == 0) { 17457c478bd9Sstevel@tonic-gate pool_value_t val = POOL_VALUE_INITIALIZER; 17467c478bd9Sstevel@tonic-gate 17477c478bd9Sstevel@tonic-gate if (pool_value_set_name(&val, props[i].pp_pname) == 17487c478bd9Sstevel@tonic-gate PO_FAIL) { 17497c478bd9Sstevel@tonic-gate free_value_list(npvals, pvals); 17507c478bd9Sstevel@tonic-gate return (PO_FAIL); 17517c478bd9Sstevel@tonic-gate } 17527c478bd9Sstevel@tonic-gate if (props[i].pp_op.ppo_get_value(elem, &val) == 17537c478bd9Sstevel@tonic-gate PO_FAIL) { 17547c478bd9Sstevel@tonic-gate free_value_list(npvals, pvals); 17557c478bd9Sstevel@tonic-gate return (PO_FAIL); 17567c478bd9Sstevel@tonic-gate } 17577c478bd9Sstevel@tonic-gate if (any == 1 || prop_is_hidden(&props[i]) == PO_FALSE) { 17587c478bd9Sstevel@tonic-gate if (prop_callback(conf, elem, props[i].pp_pname, 17597c478bd9Sstevel@tonic-gate &val, arg) != PO_SUCCESS) { 17607c478bd9Sstevel@tonic-gate free_value_list(npvals, pvals); 17617c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 17627c478bd9Sstevel@tonic-gate return (PO_FAIL); 17637c478bd9Sstevel@tonic-gate } 17647c478bd9Sstevel@tonic-gate } 17657c478bd9Sstevel@tonic-gate continue; 17667c478bd9Sstevel@tonic-gate } 17677c478bd9Sstevel@tonic-gate 17687c478bd9Sstevel@tonic-gate for (j = 0; j < npvals; j++) { 17697c478bd9Sstevel@tonic-gate if (pvals[j] && strcmp(pool_value_get_name(pvals[j]), 17707c478bd9Sstevel@tonic-gate props[i].pp_pname) == 0) 17717c478bd9Sstevel@tonic-gate break; 17727c478bd9Sstevel@tonic-gate } 17737c478bd9Sstevel@tonic-gate /* 17747c478bd9Sstevel@tonic-gate * If we have found the property, then j < npvals. Process it 17757c478bd9Sstevel@tonic-gate * according to our property attributes. Otherwise, it's not 17767c478bd9Sstevel@tonic-gate * a managed property, so just ignore it until later. 17777c478bd9Sstevel@tonic-gate */ 17787c478bd9Sstevel@tonic-gate if (j < npvals) { 17797c478bd9Sstevel@tonic-gate if (any == 1 || prop_is_hidden(&props[i]) == PO_FALSE) { 17807c478bd9Sstevel@tonic-gate if (props[i].pp_op.ppo_get_value) { 17817c478bd9Sstevel@tonic-gate if (pool_value_set_name(pvals[j], 17827c478bd9Sstevel@tonic-gate props[i].pp_pname) == PO_FAIL) { 17837c478bd9Sstevel@tonic-gate free_value_list(npvals, pvals); 17847c478bd9Sstevel@tonic-gate return (PO_FAIL); 17857c478bd9Sstevel@tonic-gate } 17867c478bd9Sstevel@tonic-gate if (props[i].pp_op.ppo_get_value(elem, 17877c478bd9Sstevel@tonic-gate pvals[j]) == PO_FAIL) { 17887c478bd9Sstevel@tonic-gate free_value_list(npvals, pvals); 17897c478bd9Sstevel@tonic-gate return (PO_FAIL); 17907c478bd9Sstevel@tonic-gate } 17917c478bd9Sstevel@tonic-gate } 17927c478bd9Sstevel@tonic-gate if (prop_callback(conf, elem, props[i].pp_pname, 17937c478bd9Sstevel@tonic-gate pvals[j], arg) != PO_SUCCESS) { 17947c478bd9Sstevel@tonic-gate free_value_list(npvals, pvals); 17957c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 17967c478bd9Sstevel@tonic-gate return (PO_FAIL); 17977c478bd9Sstevel@tonic-gate } 17987c478bd9Sstevel@tonic-gate } 17997c478bd9Sstevel@tonic-gate pool_value_free(pvals[j]); 18007c478bd9Sstevel@tonic-gate pvals[j] = NULL; 18017c478bd9Sstevel@tonic-gate } 18027c478bd9Sstevel@tonic-gate } 18037c478bd9Sstevel@tonic-gate for (i = 0; i < npvals; i++) { 18047c478bd9Sstevel@tonic-gate if (pvals[i]) { 18057c478bd9Sstevel@tonic-gate const char *name = pool_value_get_name(pvals[i]); 18067c478bd9Sstevel@tonic-gate char *qname = strrchr(name, '.'); 18077c478bd9Sstevel@tonic-gate if ((qname && qname[1] != '_') || 18087c478bd9Sstevel@tonic-gate (!qname && name[0] != '_')) { 18097c478bd9Sstevel@tonic-gate if (prop_callback(conf, elem, name, pvals[i], 18107c478bd9Sstevel@tonic-gate arg) != PO_SUCCESS) { 18117c478bd9Sstevel@tonic-gate free_value_list(npvals, pvals); 18127c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 18137c478bd9Sstevel@tonic-gate return (PO_FAIL); 18147c478bd9Sstevel@tonic-gate } 18157c478bd9Sstevel@tonic-gate } 18167c478bd9Sstevel@tonic-gate pool_value_free(pvals[i]); 18177c478bd9Sstevel@tonic-gate pvals[i] = NULL; 18187c478bd9Sstevel@tonic-gate } 18197c478bd9Sstevel@tonic-gate } 18207c478bd9Sstevel@tonic-gate free(pvals); 18217c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 18227c478bd9Sstevel@tonic-gate } 18237c478bd9Sstevel@tonic-gate 18247c478bd9Sstevel@tonic-gate /* 18257c478bd9Sstevel@tonic-gate * Return a pool, searching the supplied configuration for a pool with the 18267c478bd9Sstevel@tonic-gate * supplied name. The search is case sensitive. 18277c478bd9Sstevel@tonic-gate */ 18287c478bd9Sstevel@tonic-gate pool_t * 18297c478bd9Sstevel@tonic-gate pool_get_pool(const pool_conf_t *conf, const char *name) 18307c478bd9Sstevel@tonic-gate { 18317c478bd9Sstevel@tonic-gate pool_value_t *props[] = { NULL, NULL }; 18327c478bd9Sstevel@tonic-gate pool_t **rs; 18337c478bd9Sstevel@tonic-gate pool_t *ret; 18347c478bd9Sstevel@tonic-gate uint_t size = 0; 18357c478bd9Sstevel@tonic-gate pool_value_t val = POOL_VALUE_INITIALIZER; 18367c478bd9Sstevel@tonic-gate 18377c478bd9Sstevel@tonic-gate props[0] = &val; 18387c478bd9Sstevel@tonic-gate 18397c478bd9Sstevel@tonic-gate if (pool_conf_status(conf) == POF_INVALID) { 18407c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 18417c478bd9Sstevel@tonic-gate return (NULL); 18427c478bd9Sstevel@tonic-gate } 18437c478bd9Sstevel@tonic-gate 18447c478bd9Sstevel@tonic-gate if (pool_value_set_name(props[0], "pool.name") != PO_SUCCESS || 18457c478bd9Sstevel@tonic-gate pool_value_set_string(props[0], name) != PO_SUCCESS) { 18467c478bd9Sstevel@tonic-gate return (NULL); 18477c478bd9Sstevel@tonic-gate } 18487c478bd9Sstevel@tonic-gate rs = pool_query_pools(conf, &size, props); 18497c478bd9Sstevel@tonic-gate if (rs == NULL) { /* Can't find a pool to match the name */ 18507c478bd9Sstevel@tonic-gate return (NULL); 18517c478bd9Sstevel@tonic-gate } 18527c478bd9Sstevel@tonic-gate if (size != 1) { 18537c478bd9Sstevel@tonic-gate free(rs); 18547c478bd9Sstevel@tonic-gate pool_seterror(POE_INVALID_CONF); 18557c478bd9Sstevel@tonic-gate return (NULL); 18567c478bd9Sstevel@tonic-gate } 18577c478bd9Sstevel@tonic-gate ret = rs[0]; 18587c478bd9Sstevel@tonic-gate free(rs); 18597c478bd9Sstevel@tonic-gate return (ret); 18607c478bd9Sstevel@tonic-gate } 18617c478bd9Sstevel@tonic-gate 18627c478bd9Sstevel@tonic-gate /* 18637c478bd9Sstevel@tonic-gate * Return a result set of pools, searching the supplied configuration 18647c478bd9Sstevel@tonic-gate * for pools which match the supplied property criteria. props is a null 18657c478bd9Sstevel@tonic-gate * terminated list of properties which will be used to match qualifying 18667c478bd9Sstevel@tonic-gate * pools. size is updated with the size of the pool 18677c478bd9Sstevel@tonic-gate */ 18687c478bd9Sstevel@tonic-gate pool_t ** 18697c478bd9Sstevel@tonic-gate pool_query_pools(const pool_conf_t *conf, uint_t *size, pool_value_t **props) 18707c478bd9Sstevel@tonic-gate { 18717c478bd9Sstevel@tonic-gate pool_result_set_t *rs; 18727c478bd9Sstevel@tonic-gate pool_elem_t *pe; 18737c478bd9Sstevel@tonic-gate pool_t **result = NULL; 18747c478bd9Sstevel@tonic-gate int i = 0; 18757c478bd9Sstevel@tonic-gate 18767c478bd9Sstevel@tonic-gate if (pool_conf_status(conf) == POF_INVALID) { 18777c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 18787c478bd9Sstevel@tonic-gate return (NULL); 18797c478bd9Sstevel@tonic-gate } 18807c478bd9Sstevel@tonic-gate rs = pool_exec_query(conf, NULL, NULL, PEC_QRY_POOL, props); 18817c478bd9Sstevel@tonic-gate if (rs == NULL) { 18827c478bd9Sstevel@tonic-gate return (NULL); 18837c478bd9Sstevel@tonic-gate } 18847c478bd9Sstevel@tonic-gate if ((*size = pool_rs_count(rs)) == 0) { 18857c478bd9Sstevel@tonic-gate (void) pool_rs_close(rs); 18867c478bd9Sstevel@tonic-gate return (NULL); 18877c478bd9Sstevel@tonic-gate } 18887c478bd9Sstevel@tonic-gate if ((result = malloc(sizeof (pool_t *) * (*size + 1))) == NULL) { 18897c478bd9Sstevel@tonic-gate pool_seterror(POE_SYSTEM); 18907c478bd9Sstevel@tonic-gate (void) pool_rs_close(rs); 18917c478bd9Sstevel@tonic-gate return (NULL); 18927c478bd9Sstevel@tonic-gate } 18937c478bd9Sstevel@tonic-gate (void) memset(result, 0, sizeof (pool_t *) * (*size + 1)); 18947c478bd9Sstevel@tonic-gate for (pe = rs->prs_next(rs); pe != NULL; pe = rs->prs_next(rs)) { 18957c478bd9Sstevel@tonic-gate if (pool_elem_class(pe) != PEC_POOL) { 18967c478bd9Sstevel@tonic-gate pool_seterror(POE_INVALID_CONF); 18977c478bd9Sstevel@tonic-gate free(result); 18987c478bd9Sstevel@tonic-gate (void) pool_rs_close(rs); 18997c478bd9Sstevel@tonic-gate return (NULL); 19007c478bd9Sstevel@tonic-gate } 19017c478bd9Sstevel@tonic-gate result[i++] = pool_elem_pool(pe); 19027c478bd9Sstevel@tonic-gate } 19037c478bd9Sstevel@tonic-gate (void) pool_rs_close(rs); 19047c478bd9Sstevel@tonic-gate return (result); 19057c478bd9Sstevel@tonic-gate } 19067c478bd9Sstevel@tonic-gate 19077c478bd9Sstevel@tonic-gate /* 19087c478bd9Sstevel@tonic-gate * Return an res, searching the supplied configuration for an res with the 19097c478bd9Sstevel@tonic-gate * supplied name. The search is case sensitive. 19107c478bd9Sstevel@tonic-gate */ 19117c478bd9Sstevel@tonic-gate pool_resource_t * 19127c478bd9Sstevel@tonic-gate pool_get_resource(const pool_conf_t *conf, const char *sz_type, 19137c478bd9Sstevel@tonic-gate const char *name) 19147c478bd9Sstevel@tonic-gate { 19157c478bd9Sstevel@tonic-gate pool_value_t *props[] = { NULL, NULL, NULL }; 19167c478bd9Sstevel@tonic-gate pool_resource_t **rs; 19177c478bd9Sstevel@tonic-gate pool_resource_t *ret; 19187c478bd9Sstevel@tonic-gate uint_t size = 0; 19197c478bd9Sstevel@tonic-gate char_buf_t *cb = NULL; 19207c478bd9Sstevel@tonic-gate pool_value_t val0 = POOL_VALUE_INITIALIZER; 19217c478bd9Sstevel@tonic-gate pool_value_t val1 = POOL_VALUE_INITIALIZER; 19227c478bd9Sstevel@tonic-gate 19237c478bd9Sstevel@tonic-gate if (pool_conf_status(conf) == POF_INVALID) { 19247c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 19257c478bd9Sstevel@tonic-gate return (NULL); 19267c478bd9Sstevel@tonic-gate } 19277c478bd9Sstevel@tonic-gate 19287c478bd9Sstevel@tonic-gate if (sz_type == NULL) { 19297c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 19307c478bd9Sstevel@tonic-gate return (NULL); 19317c478bd9Sstevel@tonic-gate } 19327c478bd9Sstevel@tonic-gate 19337c478bd9Sstevel@tonic-gate props[0] = &val0; 19347c478bd9Sstevel@tonic-gate props[1] = &val1; 19357c478bd9Sstevel@tonic-gate 19367c478bd9Sstevel@tonic-gate if (pool_value_set_string(props[0], sz_type) != PO_SUCCESS || 19377c478bd9Sstevel@tonic-gate pool_value_set_name(props[0], c_type) != PO_SUCCESS) 19387c478bd9Sstevel@tonic-gate return (NULL); 19397c478bd9Sstevel@tonic-gate 19407c478bd9Sstevel@tonic-gate if ((cb = alloc_char_buf(CB_DEFAULT_LEN)) == NULL) { 19417c478bd9Sstevel@tonic-gate return (NULL); 19427c478bd9Sstevel@tonic-gate } 19437c478bd9Sstevel@tonic-gate if (set_char_buf(cb, "%s.name", sz_type) != PO_SUCCESS) { 19447c478bd9Sstevel@tonic-gate free_char_buf(cb); 19457c478bd9Sstevel@tonic-gate return (NULL); 19467c478bd9Sstevel@tonic-gate } 19477c478bd9Sstevel@tonic-gate if (pool_value_set_name(props[1], cb->cb_buf) != PO_SUCCESS) { 19487c478bd9Sstevel@tonic-gate free_char_buf(cb); 19497c478bd9Sstevel@tonic-gate return (NULL); 19507c478bd9Sstevel@tonic-gate } 19517c478bd9Sstevel@tonic-gate if (pool_value_set_string(props[1], name) != PO_SUCCESS) { 19527c478bd9Sstevel@tonic-gate free_char_buf(cb); 19537c478bd9Sstevel@tonic-gate return (NULL); 19547c478bd9Sstevel@tonic-gate } 19557c478bd9Sstevel@tonic-gate free_char_buf(cb); 19567c478bd9Sstevel@tonic-gate rs = pool_query_resources(conf, &size, props); 19577c478bd9Sstevel@tonic-gate if (rs == NULL) { 19587c478bd9Sstevel@tonic-gate return (NULL); 19597c478bd9Sstevel@tonic-gate } 19607c478bd9Sstevel@tonic-gate if (size != 1) { 19617c478bd9Sstevel@tonic-gate free(rs); 19627c478bd9Sstevel@tonic-gate pool_seterror(POE_INVALID_CONF); 19637c478bd9Sstevel@tonic-gate return (NULL); 19647c478bd9Sstevel@tonic-gate } 19657c478bd9Sstevel@tonic-gate ret = rs[0]; 19667c478bd9Sstevel@tonic-gate free(rs); 19677c478bd9Sstevel@tonic-gate return (ret); 19687c478bd9Sstevel@tonic-gate } 19697c478bd9Sstevel@tonic-gate 19707c478bd9Sstevel@tonic-gate /* 19717c478bd9Sstevel@tonic-gate * Return a result set of res (actually as pool_elem_ts), searching the 19727c478bd9Sstevel@tonic-gate * supplied configuration for res which match the supplied property 19737c478bd9Sstevel@tonic-gate * criteria. props is a null terminated list of properties which will be used 19747c478bd9Sstevel@tonic-gate * to match qualifying res. 19757c478bd9Sstevel@tonic-gate */ 19767c478bd9Sstevel@tonic-gate pool_resource_t ** 19777c478bd9Sstevel@tonic-gate pool_query_resources(const pool_conf_t *conf, uint_t *size, 19787c478bd9Sstevel@tonic-gate pool_value_t **props) 19797c478bd9Sstevel@tonic-gate { 19807c478bd9Sstevel@tonic-gate pool_result_set_t *rs; 19817c478bd9Sstevel@tonic-gate pool_elem_t *pe; 19827c478bd9Sstevel@tonic-gate pool_resource_t **result = NULL; 19837c478bd9Sstevel@tonic-gate int i = 0; 19847c478bd9Sstevel@tonic-gate 19857c478bd9Sstevel@tonic-gate if (pool_conf_status(conf) == POF_INVALID) { 19867c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 19877c478bd9Sstevel@tonic-gate return (NULL); 19887c478bd9Sstevel@tonic-gate } 19897c478bd9Sstevel@tonic-gate 19907c478bd9Sstevel@tonic-gate *size = 0; 19917c478bd9Sstevel@tonic-gate 19927c478bd9Sstevel@tonic-gate rs = pool_exec_query(conf, NULL, NULL, PEC_QRY_RES, props); 19937c478bd9Sstevel@tonic-gate if (rs == NULL) { 19947c478bd9Sstevel@tonic-gate return (NULL); 19957c478bd9Sstevel@tonic-gate } 19967c478bd9Sstevel@tonic-gate if ((*size = pool_rs_count(rs)) == 0) { 19977c478bd9Sstevel@tonic-gate (void) pool_rs_close(rs); 19987c478bd9Sstevel@tonic-gate return (NULL); 19997c478bd9Sstevel@tonic-gate } 20007c478bd9Sstevel@tonic-gate if ((result = malloc(sizeof (pool_resource_t *) * (*size + 1))) 20017c478bd9Sstevel@tonic-gate == NULL) { 20027c478bd9Sstevel@tonic-gate pool_seterror(POE_SYSTEM); 20037c478bd9Sstevel@tonic-gate (void) pool_rs_close(rs); 20047c478bd9Sstevel@tonic-gate return (NULL); 20057c478bd9Sstevel@tonic-gate } 20067c478bd9Sstevel@tonic-gate (void) memset(result, 0, sizeof (pool_resource_t *) * (*size + 1)); 20077c478bd9Sstevel@tonic-gate for (pe = rs->prs_next(rs); pe != NULL; pe = rs->prs_next(rs)) { 20087c478bd9Sstevel@tonic-gate if (pool_elem_class(pe) != PEC_RES_COMP && 20097c478bd9Sstevel@tonic-gate pool_elem_class(pe) != PEC_RES_AGG) { 20107c478bd9Sstevel@tonic-gate pool_seterror(POE_INVALID_CONF); 20117c478bd9Sstevel@tonic-gate free(result); 20127c478bd9Sstevel@tonic-gate (void) pool_rs_close(rs); 20137c478bd9Sstevel@tonic-gate return (NULL); 20147c478bd9Sstevel@tonic-gate } 20157c478bd9Sstevel@tonic-gate result[i++] = pool_elem_res(pe); 20167c478bd9Sstevel@tonic-gate } 20177c478bd9Sstevel@tonic-gate (void) pool_rs_close(rs); 20187c478bd9Sstevel@tonic-gate return (result); 20197c478bd9Sstevel@tonic-gate } 20207c478bd9Sstevel@tonic-gate 20217c478bd9Sstevel@tonic-gate /* 20227c478bd9Sstevel@tonic-gate * Return a result set of comp (actually as pool_elem_ts), searching the 20237c478bd9Sstevel@tonic-gate * supplied configuration for comp which match the supplied property 20247c478bd9Sstevel@tonic-gate * criteria. props is a null terminated list of properties which will be used 20257c478bd9Sstevel@tonic-gate * to match qualifying comp. 20267c478bd9Sstevel@tonic-gate */ 20277c478bd9Sstevel@tonic-gate pool_component_t ** 20287c478bd9Sstevel@tonic-gate pool_query_components(const pool_conf_t *conf, uint_t *size, 20297c478bd9Sstevel@tonic-gate pool_value_t **props) 20307c478bd9Sstevel@tonic-gate { 20317c478bd9Sstevel@tonic-gate return (pool_query_resource_components(conf, NULL, size, props)); 20327c478bd9Sstevel@tonic-gate } 20337c478bd9Sstevel@tonic-gate 20347c478bd9Sstevel@tonic-gate /* 20357c478bd9Sstevel@tonic-gate * Destroy a pool. If the pool cannot be found or removed an error is 20367c478bd9Sstevel@tonic-gate * returned. This is basically a wrapper around pool_elem_remove to ensure 20377c478bd9Sstevel@tonic-gate * some type safety for the pool subtype. 20387c478bd9Sstevel@tonic-gate */ 20397c478bd9Sstevel@tonic-gate int 20407c478bd9Sstevel@tonic-gate pool_destroy(pool_conf_t *conf, pool_t *pp) 20417c478bd9Sstevel@tonic-gate { 20427c478bd9Sstevel@tonic-gate pool_elem_t *pe; 20437c478bd9Sstevel@tonic-gate 20447c478bd9Sstevel@tonic-gate if (pool_conf_check(conf) != PO_SUCCESS) 20457c478bd9Sstevel@tonic-gate return (PO_FAIL); 20467c478bd9Sstevel@tonic-gate 20477c478bd9Sstevel@tonic-gate pe = TO_ELEM(pp); 20487c478bd9Sstevel@tonic-gate 20497c478bd9Sstevel@tonic-gate /* 20507c478bd9Sstevel@tonic-gate * Cannot destroy the default pool. 20517c478bd9Sstevel@tonic-gate */ 20527c478bd9Sstevel@tonic-gate if (elem_is_default(pe) == PO_TRUE) { 20537c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 20547c478bd9Sstevel@tonic-gate return (PO_FAIL); 20557c478bd9Sstevel@tonic-gate } 20567c478bd9Sstevel@tonic-gate if (pool_elem_remove(pe) != PO_SUCCESS) 20577c478bd9Sstevel@tonic-gate return (PO_FAIL); 20587c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 20597c478bd9Sstevel@tonic-gate } 20607c478bd9Sstevel@tonic-gate 20617c478bd9Sstevel@tonic-gate /* 20627c478bd9Sstevel@tonic-gate * Destroy an res. If the res cannot be found or removed an error is 20637c478bd9Sstevel@tonic-gate * returned. This is basically a wrapper around pool_elem_remove to ensure 20647c478bd9Sstevel@tonic-gate * some type safety for the res subtype. 20657c478bd9Sstevel@tonic-gate */ 20667c478bd9Sstevel@tonic-gate int 20677c478bd9Sstevel@tonic-gate pool_resource_destroy(pool_conf_t *conf, pool_resource_t *prs) 20687c478bd9Sstevel@tonic-gate { 20697c478bd9Sstevel@tonic-gate pool_elem_t *pe; 20707c478bd9Sstevel@tonic-gate pool_component_t **rl; 20717c478bd9Sstevel@tonic-gate uint_t res_size; 20727c478bd9Sstevel@tonic-gate pool_t **pl; 20737c478bd9Sstevel@tonic-gate uint_t npool; 20747c478bd9Sstevel@tonic-gate int i; 20757c478bd9Sstevel@tonic-gate 20767c478bd9Sstevel@tonic-gate if (pool_conf_check(conf) != PO_SUCCESS) 20777c478bd9Sstevel@tonic-gate return (PO_FAIL); 20787c478bd9Sstevel@tonic-gate 20797c478bd9Sstevel@tonic-gate pe = TO_ELEM(prs); 20807c478bd9Sstevel@tonic-gate 20817c478bd9Sstevel@tonic-gate if (resource_is_system(prs) == PO_TRUE) { 20827c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 20837c478bd9Sstevel@tonic-gate return (PO_FAIL); 20847c478bd9Sstevel@tonic-gate } 20857c478bd9Sstevel@tonic-gate /* 20867c478bd9Sstevel@tonic-gate * Walk all the pools and dissociate any pools which are using 20877c478bd9Sstevel@tonic-gate * this resource. 20887c478bd9Sstevel@tonic-gate */ 20897c478bd9Sstevel@tonic-gate if ((pl = pool_query_pools(conf, &npool, NULL)) != NULL) { 20907c478bd9Sstevel@tonic-gate for (i = 0; i < npool; i++) { 20917c478bd9Sstevel@tonic-gate pool_resource_t **rl; 20927c478bd9Sstevel@tonic-gate uint_t nres; 20937c478bd9Sstevel@tonic-gate int j; 20947c478bd9Sstevel@tonic-gate 20957c478bd9Sstevel@tonic-gate if ((rl = pool_query_pool_resources(conf, pl[i], &nres, 20967c478bd9Sstevel@tonic-gate NULL)) != NULL) { 20977c478bd9Sstevel@tonic-gate for (j = 0; j < nres; j++) { 20987c478bd9Sstevel@tonic-gate if (rl[j] == prs) { 20997c478bd9Sstevel@tonic-gate if (pool_dissociate(conf, pl[i], 21007c478bd9Sstevel@tonic-gate rl[j]) != PO_SUCCESS) { 21017c478bd9Sstevel@tonic-gate free(rl); 21027c478bd9Sstevel@tonic-gate free(pl); 21037c478bd9Sstevel@tonic-gate return (PO_FAIL); 21047c478bd9Sstevel@tonic-gate } 21057c478bd9Sstevel@tonic-gate break; 21067c478bd9Sstevel@tonic-gate } 21077c478bd9Sstevel@tonic-gate } 21087c478bd9Sstevel@tonic-gate free(rl); 21097c478bd9Sstevel@tonic-gate } 21107c478bd9Sstevel@tonic-gate } 21117c478bd9Sstevel@tonic-gate free(pl); 21127c478bd9Sstevel@tonic-gate } 21137c478bd9Sstevel@tonic-gate if (pe->pe_class == PEC_RES_COMP) { 21147c478bd9Sstevel@tonic-gate pool_resource_t *default_set_res; 21157c478bd9Sstevel@tonic-gate 21167c478bd9Sstevel@tonic-gate /* 21177c478bd9Sstevel@tonic-gate * Use the xtransfer option to move comp around 21187c478bd9Sstevel@tonic-gate */ 21197c478bd9Sstevel@tonic-gate default_set_res = (pool_resource_t *)get_default_resource(prs); 21207c478bd9Sstevel@tonic-gate 21217c478bd9Sstevel@tonic-gate if ((rl = pool_query_resource_components(conf, prs, &res_size, 21227c478bd9Sstevel@tonic-gate NULL)) != NULL) { 21237c478bd9Sstevel@tonic-gate int ostate = conf->pc_state; 21247c478bd9Sstevel@tonic-gate conf->pc_state = POF_DESTROY; 21257c478bd9Sstevel@tonic-gate if (pool_resource_xtransfer(conf, prs, default_set_res, 21267c478bd9Sstevel@tonic-gate rl) == PO_FAIL) { 21277c478bd9Sstevel@tonic-gate free(rl); 21287c478bd9Sstevel@tonic-gate conf->pc_state = ostate; 21297c478bd9Sstevel@tonic-gate return (PO_FAIL); 21307c478bd9Sstevel@tonic-gate } 21317c478bd9Sstevel@tonic-gate conf->pc_state = ostate; 21327c478bd9Sstevel@tonic-gate free(rl); 21337c478bd9Sstevel@tonic-gate } 21347c478bd9Sstevel@tonic-gate } 21357c478bd9Sstevel@tonic-gate if (pool_elem_remove(pe) != PO_SUCCESS) 21367c478bd9Sstevel@tonic-gate return (PO_FAIL); 21377c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 21387c478bd9Sstevel@tonic-gate } 21397c478bd9Sstevel@tonic-gate 21407c478bd9Sstevel@tonic-gate /* 21417c478bd9Sstevel@tonic-gate * Destroy a comp. If the comp cannot be found or removed an error is 21427c478bd9Sstevel@tonic-gate * returned. This is basically a wrapper around pool_elem_remove to ensure 21437c478bd9Sstevel@tonic-gate * some type safety for the comp subtype. 21447c478bd9Sstevel@tonic-gate */ 21457c478bd9Sstevel@tonic-gate int 21467c478bd9Sstevel@tonic-gate pool_component_destroy(pool_component_t *pr) 21477c478bd9Sstevel@tonic-gate { 21487c478bd9Sstevel@tonic-gate pool_elem_t *pe = TO_ELEM(pr); 21497c478bd9Sstevel@tonic-gate 21507c478bd9Sstevel@tonic-gate if (pool_elem_remove(pe) != PO_SUCCESS) 21517c478bd9Sstevel@tonic-gate return (PO_FAIL); 21527c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 21537c478bd9Sstevel@tonic-gate } 21547c478bd9Sstevel@tonic-gate 21557c478bd9Sstevel@tonic-gate /* 21567c478bd9Sstevel@tonic-gate * Remove a pool_elem_t from a configuration. This has been "hidden" away as 21577c478bd9Sstevel@tonic-gate * a static routine since the only elements which are currently being removed 21587c478bd9Sstevel@tonic-gate * are pools, res & comp and the wrapper functions above provide type-safe 21597c478bd9Sstevel@tonic-gate * access. However, if there is a need to remove other types of elements 21607c478bd9Sstevel@tonic-gate * then this could be promoted to pool_impl.h or more wrappers could 21617c478bd9Sstevel@tonic-gate * be added to pool_impl.h. 21627c478bd9Sstevel@tonic-gate */ 21637c478bd9Sstevel@tonic-gate int 21647c478bd9Sstevel@tonic-gate pool_elem_remove(pool_elem_t *pe) 21657c478bd9Sstevel@tonic-gate { 21667c478bd9Sstevel@tonic-gate return (pe->pe_remove(pe)); 21677c478bd9Sstevel@tonic-gate } 21687c478bd9Sstevel@tonic-gate 21697c478bd9Sstevel@tonic-gate /* 21707c478bd9Sstevel@tonic-gate * Execute a query to search for a qualifying set of elements. 21717c478bd9Sstevel@tonic-gate */ 21727c478bd9Sstevel@tonic-gate pool_result_set_t * 21737c478bd9Sstevel@tonic-gate pool_exec_query(const pool_conf_t *conf, const pool_elem_t *src, 21747c478bd9Sstevel@tonic-gate const char *src_attr, pool_elem_class_t classes, pool_value_t **props) 21757c478bd9Sstevel@tonic-gate { 21767c478bd9Sstevel@tonic-gate return (conf->pc_prov->pc_exec_query(conf, src, src_attr, classes, 21777c478bd9Sstevel@tonic-gate props)); 21787c478bd9Sstevel@tonic-gate } 21797c478bd9Sstevel@tonic-gate 21807c478bd9Sstevel@tonic-gate /* 21817c478bd9Sstevel@tonic-gate * Get the next result from a result set of elements. 21827c478bd9Sstevel@tonic-gate */ 21837c478bd9Sstevel@tonic-gate pool_elem_t * 21847c478bd9Sstevel@tonic-gate pool_rs_next(pool_result_set_t *set) 21857c478bd9Sstevel@tonic-gate { 21867c478bd9Sstevel@tonic-gate return (set->prs_next(set)); 21877c478bd9Sstevel@tonic-gate } 21887c478bd9Sstevel@tonic-gate 21897c478bd9Sstevel@tonic-gate /* 21907c478bd9Sstevel@tonic-gate * Get the previous result from a result set of elements. 21917c478bd9Sstevel@tonic-gate */ 21927c478bd9Sstevel@tonic-gate pool_elem_t * 21937c478bd9Sstevel@tonic-gate pool_rs_prev(pool_result_set_t *set) 21947c478bd9Sstevel@tonic-gate { 21957c478bd9Sstevel@tonic-gate return (set->prs_prev(set)); 21967c478bd9Sstevel@tonic-gate } 21977c478bd9Sstevel@tonic-gate 21987c478bd9Sstevel@tonic-gate /* 21997c478bd9Sstevel@tonic-gate * Get the first result from a result set of elements. 22007c478bd9Sstevel@tonic-gate */ 22017c478bd9Sstevel@tonic-gate pool_elem_t * 22027c478bd9Sstevel@tonic-gate pool_rs_first(pool_result_set_t *set) 22037c478bd9Sstevel@tonic-gate { 22047c478bd9Sstevel@tonic-gate return (set->prs_first(set)); 22057c478bd9Sstevel@tonic-gate } 22067c478bd9Sstevel@tonic-gate 22077c478bd9Sstevel@tonic-gate /* 22087c478bd9Sstevel@tonic-gate * Get the last result from a result set of elements. 22097c478bd9Sstevel@tonic-gate */ 22107c478bd9Sstevel@tonic-gate pool_elem_t * 22117c478bd9Sstevel@tonic-gate pool_rs_last(pool_result_set_t *set) 22127c478bd9Sstevel@tonic-gate { 22137c478bd9Sstevel@tonic-gate return (set->prs_last(set)); 22147c478bd9Sstevel@tonic-gate } 22157c478bd9Sstevel@tonic-gate 22167c478bd9Sstevel@tonic-gate 22177c478bd9Sstevel@tonic-gate /* 22187c478bd9Sstevel@tonic-gate * Get the count for a result set of elements. 22197c478bd9Sstevel@tonic-gate */ 22207c478bd9Sstevel@tonic-gate int 22217c478bd9Sstevel@tonic-gate pool_rs_count(pool_result_set_t *set) 22227c478bd9Sstevel@tonic-gate { 22237c478bd9Sstevel@tonic-gate return (set->prs_count(set)); 22247c478bd9Sstevel@tonic-gate } 22257c478bd9Sstevel@tonic-gate 22267c478bd9Sstevel@tonic-gate /* 22277c478bd9Sstevel@tonic-gate * Get the index for a result set of elements. 22287c478bd9Sstevel@tonic-gate */ 22297c478bd9Sstevel@tonic-gate int 22307c478bd9Sstevel@tonic-gate pool_rs_get_index(pool_result_set_t *set) 22317c478bd9Sstevel@tonic-gate { 22327c478bd9Sstevel@tonic-gate return (set->prs_get_index(set)); 22337c478bd9Sstevel@tonic-gate } 22347c478bd9Sstevel@tonic-gate 22357c478bd9Sstevel@tonic-gate /* 22367c478bd9Sstevel@tonic-gate * Set the index for a result set of elements. 22377c478bd9Sstevel@tonic-gate */ 22387c478bd9Sstevel@tonic-gate int 22397c478bd9Sstevel@tonic-gate pool_rs_set_index(pool_result_set_t *set, int index) 22407c478bd9Sstevel@tonic-gate { 22417c478bd9Sstevel@tonic-gate return (set->prs_set_index(set, index)); 22427c478bd9Sstevel@tonic-gate } 22437c478bd9Sstevel@tonic-gate 22447c478bd9Sstevel@tonic-gate /* 22457c478bd9Sstevel@tonic-gate * Close a result set of elements, freeing all associated resources. 22467c478bd9Sstevel@tonic-gate */ 22477c478bd9Sstevel@tonic-gate int 22487c478bd9Sstevel@tonic-gate pool_rs_close(pool_result_set_t *set) 22497c478bd9Sstevel@tonic-gate { 22507c478bd9Sstevel@tonic-gate return (set->prs_close(set)); 22517c478bd9Sstevel@tonic-gate } 22527c478bd9Sstevel@tonic-gate 22537c478bd9Sstevel@tonic-gate /* 22547c478bd9Sstevel@tonic-gate * When transferring resource components using pool_resource_transfer, 22557c478bd9Sstevel@tonic-gate * this function is invoked to choose which actual components will be 22567c478bd9Sstevel@tonic-gate * transferred. 22577c478bd9Sstevel@tonic-gate */ 22587c478bd9Sstevel@tonic-gate int 22597c478bd9Sstevel@tonic-gate choose_components(pool_resource_t *src, pool_resource_t *dst, uint64_t size) 22607c478bd9Sstevel@tonic-gate { 22617c478bd9Sstevel@tonic-gate pool_component_t **components = NULL, *moved[] = { NULL, NULL }; 22627c478bd9Sstevel@tonic-gate int i; 22637c478bd9Sstevel@tonic-gate uint_t ncomponent; 22647c478bd9Sstevel@tonic-gate pool_conf_t *conf = TO_CONF(TO_ELEM(src)); 22657c478bd9Sstevel@tonic-gate 22667c478bd9Sstevel@tonic-gate if (size == 0) 22677c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 22687c478bd9Sstevel@tonic-gate /* 22697c478bd9Sstevel@tonic-gate * Get the component list from our src component. 22707c478bd9Sstevel@tonic-gate */ 22717c478bd9Sstevel@tonic-gate if ((components = pool_query_resource_components(conf, src, &ncomponent, 22727c478bd9Sstevel@tonic-gate NULL)) == NULL) { 22737c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 22747c478bd9Sstevel@tonic-gate return (PO_FAIL); 22757c478bd9Sstevel@tonic-gate } 22767c478bd9Sstevel@tonic-gate qsort(components, ncomponent, sizeof (pool_elem_t *), 22777c478bd9Sstevel@tonic-gate qsort_elem_compare); 22787c478bd9Sstevel@tonic-gate /* 22797c478bd9Sstevel@tonic-gate * Components that aren't specifically requested by the resource 22807c478bd9Sstevel@tonic-gate * should be transferred out first. 22817c478bd9Sstevel@tonic-gate */ 22827c478bd9Sstevel@tonic-gate for (i = 0; size > 0 && components[i] != NULL; i++) { 22837c478bd9Sstevel@tonic-gate if (!cpu_is_requested(components[i])) { 22847c478bd9Sstevel@tonic-gate moved[0] = components[i]; 22857c478bd9Sstevel@tonic-gate if (pool_resource_xtransfer(conf, src, dst, moved) == 22867c478bd9Sstevel@tonic-gate PO_SUCCESS) { 22877c478bd9Sstevel@tonic-gate size--; 22887c478bd9Sstevel@tonic-gate } 22897c478bd9Sstevel@tonic-gate } 22907c478bd9Sstevel@tonic-gate } 22917c478bd9Sstevel@tonic-gate 22927c478bd9Sstevel@tonic-gate /* 22937c478bd9Sstevel@tonic-gate * If we couldn't find enough "un-requested" components, select random 22947c478bd9Sstevel@tonic-gate * requested components. 22957c478bd9Sstevel@tonic-gate */ 22967c478bd9Sstevel@tonic-gate for (i = 0; size > 0 && components[i] != NULL; i++) { 22977c478bd9Sstevel@tonic-gate if (cpu_is_requested(components[i])) { 22987c478bd9Sstevel@tonic-gate moved[0] = components[i]; 22997c478bd9Sstevel@tonic-gate if (pool_resource_xtransfer(conf, src, dst, moved) == 23007c478bd9Sstevel@tonic-gate PO_SUCCESS) { 23017c478bd9Sstevel@tonic-gate size--; 23027c478bd9Sstevel@tonic-gate } 23037c478bd9Sstevel@tonic-gate } 23047c478bd9Sstevel@tonic-gate } 23057c478bd9Sstevel@tonic-gate 23067c478bd9Sstevel@tonic-gate free(components); 23077c478bd9Sstevel@tonic-gate /* 23087c478bd9Sstevel@tonic-gate * If we couldn't transfer out all the resources we asked for, then 23097c478bd9Sstevel@tonic-gate * return error. 23107c478bd9Sstevel@tonic-gate */ 23117c478bd9Sstevel@tonic-gate return (size == 0 ? PO_SUCCESS : PO_FAIL); 23127c478bd9Sstevel@tonic-gate } 23137c478bd9Sstevel@tonic-gate 23147c478bd9Sstevel@tonic-gate /* 23157c478bd9Sstevel@tonic-gate * Common processing for a resource transfer (xfer or xxfer). 23167c478bd9Sstevel@tonic-gate * 23177c478bd9Sstevel@tonic-gate * - Return XFER_CONTINUE if the transfer should proceeed 23187c478bd9Sstevel@tonic-gate * - Return XFER_FAIL if the transfer should be stopped in failure 23197c478bd9Sstevel@tonic-gate * - Return XFER_SUCCESS if the transfer should be stopped in success 23207c478bd9Sstevel@tonic-gate */ 23217c478bd9Sstevel@tonic-gate int 23227c478bd9Sstevel@tonic-gate setup_transfer(pool_conf_t *conf, pool_resource_t *src, pool_resource_t *tgt, 23237c478bd9Sstevel@tonic-gate uint64_t size, uint64_t *src_size, uint64_t *tgt_size) 23247c478bd9Sstevel@tonic-gate { 23257c478bd9Sstevel@tonic-gate uint64_t src_min; 23267c478bd9Sstevel@tonic-gate uint64_t tgt_max; 23277c478bd9Sstevel@tonic-gate 23287c478bd9Sstevel@tonic-gate if (pool_conf_check(conf) != PO_SUCCESS) 23297c478bd9Sstevel@tonic-gate return (XFER_FAIL); 23307c478bd9Sstevel@tonic-gate 23317c478bd9Sstevel@tonic-gate /* 23327c478bd9Sstevel@tonic-gate * Makes sure the two resources are of the same type 23337c478bd9Sstevel@tonic-gate */ 23347c478bd9Sstevel@tonic-gate if (pool_resource_elem_class(TO_ELEM(src)) != 23357c478bd9Sstevel@tonic-gate pool_resource_elem_class(TO_ELEM(tgt))) { 23367c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 23377c478bd9Sstevel@tonic-gate return (XFER_FAIL); 23387c478bd9Sstevel@tonic-gate } 23397c478bd9Sstevel@tonic-gate 23407c478bd9Sstevel@tonic-gate /* 23417c478bd9Sstevel@tonic-gate * Transferring to yourself is a no-op 23427c478bd9Sstevel@tonic-gate */ 23437c478bd9Sstevel@tonic-gate if (src == tgt) 23447c478bd9Sstevel@tonic-gate return (XFER_SUCCESS); 23457c478bd9Sstevel@tonic-gate 23467c478bd9Sstevel@tonic-gate /* 23477c478bd9Sstevel@tonic-gate * Transferring nothing is a no-op 23487c478bd9Sstevel@tonic-gate */ 23497c478bd9Sstevel@tonic-gate if (size == 0) 23507c478bd9Sstevel@tonic-gate return (XFER_SUCCESS); 23517c478bd9Sstevel@tonic-gate 23527c478bd9Sstevel@tonic-gate if (resource_get_min(src, &src_min) != PO_SUCCESS || 23537c478bd9Sstevel@tonic-gate resource_get_size(src, src_size) != PO_SUCCESS || 23547c478bd9Sstevel@tonic-gate resource_get_max(tgt, &tgt_max) != PO_SUCCESS || 23557c478bd9Sstevel@tonic-gate resource_get_size(tgt, tgt_size) != PO_SUCCESS) { 23567c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 23577c478bd9Sstevel@tonic-gate return (XFER_FAIL); 23587c478bd9Sstevel@tonic-gate } 23597c478bd9Sstevel@tonic-gate if (pool_conf_status(conf) != POF_DESTROY) { 23607c478bd9Sstevel@tonic-gate /* 23617c478bd9Sstevel@tonic-gate * src_size - donating >= src.min 23627c478bd9Sstevel@tonic-gate * size + receiving <= tgt.max (except for default) 23637c478bd9Sstevel@tonic-gate */ 23647c478bd9Sstevel@tonic-gate #ifdef DEBUG 23657c478bd9Sstevel@tonic-gate dprintf("conf is %s\n", pool_conf_location(conf)); 23667c478bd9Sstevel@tonic-gate dprintf("setup_transfer: src_size %llu\n", *src_size); 23677c478bd9Sstevel@tonic-gate pool_elem_dprintf(TO_ELEM(src)); 23687c478bd9Sstevel@tonic-gate dprintf("setup_transfer: tgt_size %llu\n", *tgt_size); 23697c478bd9Sstevel@tonic-gate pool_elem_dprintf(TO_ELEM(tgt)); 23707c478bd9Sstevel@tonic-gate #endif /* DEBUG */ 23717c478bd9Sstevel@tonic-gate if (*src_size - size < src_min || 23727c478bd9Sstevel@tonic-gate (resource_is_default(tgt) == PO_FALSE && 23737c478bd9Sstevel@tonic-gate *tgt_size + size > tgt_max)) { 23747c478bd9Sstevel@tonic-gate pool_seterror(POE_INVALID_CONF); 23757c478bd9Sstevel@tonic-gate return (XFER_FAIL); 23767c478bd9Sstevel@tonic-gate } 23777c478bd9Sstevel@tonic-gate } 23787c478bd9Sstevel@tonic-gate return (XFER_CONTINUE); 23797c478bd9Sstevel@tonic-gate } 23807c478bd9Sstevel@tonic-gate 23817c478bd9Sstevel@tonic-gate /* 23827c478bd9Sstevel@tonic-gate * Transfer resource quantities from one resource set to another. 23837c478bd9Sstevel@tonic-gate */ 23847c478bd9Sstevel@tonic-gate int 23857c478bd9Sstevel@tonic-gate pool_resource_transfer(pool_conf_t *conf, pool_resource_t *src, 23867c478bd9Sstevel@tonic-gate pool_resource_t *tgt, uint64_t size) 23877c478bd9Sstevel@tonic-gate { 23887c478bd9Sstevel@tonic-gate uint64_t src_size; 23897c478bd9Sstevel@tonic-gate uint64_t tgt_size; 23907c478bd9Sstevel@tonic-gate int ret; 23917c478bd9Sstevel@tonic-gate 23927c478bd9Sstevel@tonic-gate if ((ret = setup_transfer(conf, src, tgt, size, &src_size, &tgt_size)) 23937c478bd9Sstevel@tonic-gate != XFER_CONTINUE) 23947c478bd9Sstevel@tonic-gate return (ret); 23957c478bd9Sstevel@tonic-gate /* 23967c478bd9Sstevel@tonic-gate * If this resource is a res_comp we must call move components 23977c478bd9Sstevel@tonic-gate */ 23987c478bd9Sstevel@tonic-gate if (pool_elem_class(TO_ELEM(src)) == PEC_RES_COMP) 23997c478bd9Sstevel@tonic-gate return (choose_components(src, tgt, size)); 24007c478bd9Sstevel@tonic-gate /* 24017c478bd9Sstevel@tonic-gate * Now do the transfer. 24027c478bd9Sstevel@tonic-gate */ 24037c478bd9Sstevel@tonic-gate ret = conf->pc_prov->pc_res_xfer(src, tgt, size); 24047c478bd9Sstevel@tonic-gate /* 24057c478bd9Sstevel@tonic-gate * Modify the sizes of the resource sets if the process was 24067c478bd9Sstevel@tonic-gate * successful 24077c478bd9Sstevel@tonic-gate */ 24087c478bd9Sstevel@tonic-gate if (ret == PO_SUCCESS) { 24097c478bd9Sstevel@tonic-gate pool_value_t val = POOL_VALUE_INITIALIZER; 24107c478bd9Sstevel@tonic-gate 24117c478bd9Sstevel@tonic-gate src_size -= size; 24127c478bd9Sstevel@tonic-gate tgt_size += size; 24137c478bd9Sstevel@tonic-gate pool_value_set_uint64(&val, src_size); 24147c478bd9Sstevel@tonic-gate (void) pool_put_any_ns_property(TO_ELEM(src), c_size_prop, 24157c478bd9Sstevel@tonic-gate &val); 24167c478bd9Sstevel@tonic-gate pool_value_set_uint64(&val, tgt_size); 24177c478bd9Sstevel@tonic-gate (void) pool_put_any_ns_property(TO_ELEM(tgt), c_size_prop, 24187c478bd9Sstevel@tonic-gate &val); 24197c478bd9Sstevel@tonic-gate } 24207c478bd9Sstevel@tonic-gate return (ret); 24217c478bd9Sstevel@tonic-gate } 24227c478bd9Sstevel@tonic-gate 24237c478bd9Sstevel@tonic-gate /* 24247c478bd9Sstevel@tonic-gate * Transfer resource components from one resource set to another. 24257c478bd9Sstevel@tonic-gate */ 24267c478bd9Sstevel@tonic-gate int 24277c478bd9Sstevel@tonic-gate pool_resource_xtransfer(pool_conf_t *conf, pool_resource_t *src, 24287c478bd9Sstevel@tonic-gate pool_resource_t *tgt, 24297c478bd9Sstevel@tonic-gate pool_component_t **rl) 24307c478bd9Sstevel@tonic-gate { 24317c478bd9Sstevel@tonic-gate int i; 24327c478bd9Sstevel@tonic-gate uint64_t src_size; 24337c478bd9Sstevel@tonic-gate uint64_t tgt_size; 24347c478bd9Sstevel@tonic-gate uint64_t size; 24357c478bd9Sstevel@tonic-gate int ret; 24367c478bd9Sstevel@tonic-gate 24377c478bd9Sstevel@tonic-gate /* 24387c478bd9Sstevel@tonic-gate * Make sure the components are all contained in 'src'. This 24397c478bd9Sstevel@tonic-gate * processing must be done before setup_transfer so that size 24407c478bd9Sstevel@tonic-gate * is known. 24417c478bd9Sstevel@tonic-gate */ 24427c478bd9Sstevel@tonic-gate for (i = 0; rl[i] != NULL; i++) { 24437c478bd9Sstevel@tonic-gate #ifdef DEBUG 24447c478bd9Sstevel@tonic-gate dprintf("resource xtransfer\n"); 24457c478bd9Sstevel@tonic-gate dprintf("in conf %s\n", pool_conf_location(conf)); 24467c478bd9Sstevel@tonic-gate dprintf("transferring component\n"); 24477c478bd9Sstevel@tonic-gate pool_elem_dprintf(TO_ELEM(rl[i])); 24487c478bd9Sstevel@tonic-gate dprintf("from\n"); 24497c478bd9Sstevel@tonic-gate pool_elem_dprintf(TO_ELEM(src)); 24507c478bd9Sstevel@tonic-gate dprintf("to\n"); 24517c478bd9Sstevel@tonic-gate pool_elem_dprintf(TO_ELEM(tgt)); 24527c478bd9Sstevel@tonic-gate #endif /* DEBUG */ 24537c478bd9Sstevel@tonic-gate 24547c478bd9Sstevel@tonic-gate if (pool_get_owning_resource(conf, rl[i]) != src) { 24557c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 24567c478bd9Sstevel@tonic-gate return (PO_FAIL); 24577c478bd9Sstevel@tonic-gate } 24587c478bd9Sstevel@tonic-gate } 24597c478bd9Sstevel@tonic-gate 24607c478bd9Sstevel@tonic-gate size = (uint64_t)i; 24617c478bd9Sstevel@tonic-gate 24627c478bd9Sstevel@tonic-gate if ((ret = setup_transfer(conf, src, tgt, size, &src_size, &tgt_size)) 24637c478bd9Sstevel@tonic-gate != XFER_CONTINUE) 24647c478bd9Sstevel@tonic-gate return (ret); 24657c478bd9Sstevel@tonic-gate 24667c478bd9Sstevel@tonic-gate ret = conf->pc_prov->pc_res_xxfer(src, tgt, rl); 24677c478bd9Sstevel@tonic-gate /* 24687c478bd9Sstevel@tonic-gate * Modify the sizes of the resource sets if the process was 24697c478bd9Sstevel@tonic-gate * successful 24707c478bd9Sstevel@tonic-gate */ 24717c478bd9Sstevel@tonic-gate if (ret == PO_SUCCESS) { 24727c478bd9Sstevel@tonic-gate pool_value_t val = POOL_VALUE_INITIALIZER; 24737c478bd9Sstevel@tonic-gate 24747c478bd9Sstevel@tonic-gate #ifdef DEBUG 24757c478bd9Sstevel@tonic-gate dprintf("src_size %llu\n", src_size); 24767c478bd9Sstevel@tonic-gate dprintf("tgt_size %llu\n", tgt_size); 24777c478bd9Sstevel@tonic-gate dprintf("size %llu\n", size); 24787c478bd9Sstevel@tonic-gate #endif /* DEBUG */ 24797c478bd9Sstevel@tonic-gate src_size -= size; 24807c478bd9Sstevel@tonic-gate tgt_size += size; 24817c478bd9Sstevel@tonic-gate pool_value_set_uint64(&val, src_size); 24827c478bd9Sstevel@tonic-gate (void) pool_put_any_ns_property(TO_ELEM(src), c_size_prop, 24837c478bd9Sstevel@tonic-gate &val); 24847c478bd9Sstevel@tonic-gate pool_value_set_uint64(&val, tgt_size); 24857c478bd9Sstevel@tonic-gate (void) pool_put_any_ns_property(TO_ELEM(tgt), c_size_prop, 24867c478bd9Sstevel@tonic-gate &val); 24877c478bd9Sstevel@tonic-gate } 24887c478bd9Sstevel@tonic-gate return (ret); 24897c478bd9Sstevel@tonic-gate } 24907c478bd9Sstevel@tonic-gate 24917c478bd9Sstevel@tonic-gate /* 24927c478bd9Sstevel@tonic-gate * Find the owning resource for a resource component. 24937c478bd9Sstevel@tonic-gate */ 24947c478bd9Sstevel@tonic-gate pool_resource_t * 24957c478bd9Sstevel@tonic-gate pool_get_owning_resource(const pool_conf_t *conf, const pool_component_t *comp) 24967c478bd9Sstevel@tonic-gate { 24977c478bd9Sstevel@tonic-gate if (pool_conf_status(conf) == POF_INVALID) { 24987c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 24997c478bd9Sstevel@tonic-gate return (NULL); 25007c478bd9Sstevel@tonic-gate } 25017c478bd9Sstevel@tonic-gate return (pool_elem_res(pool_get_container(TO_ELEM(comp)))); 25027c478bd9Sstevel@tonic-gate } 25037c478bd9Sstevel@tonic-gate 25047c478bd9Sstevel@tonic-gate /* 25057c478bd9Sstevel@tonic-gate * pool_get_container() returns the container of pc. 25067c478bd9Sstevel@tonic-gate */ 25077c478bd9Sstevel@tonic-gate pool_elem_t * 25087c478bd9Sstevel@tonic-gate pool_get_container(const pool_elem_t *pc) 25097c478bd9Sstevel@tonic-gate { 25107c478bd9Sstevel@tonic-gate return (pc->pe_get_container(pc)); 25117c478bd9Sstevel@tonic-gate } 25127c478bd9Sstevel@tonic-gate 25137c478bd9Sstevel@tonic-gate /* 25147c478bd9Sstevel@tonic-gate * pool_set_container() moves pc so that it is contained by pp. 25157c478bd9Sstevel@tonic-gate * 25167c478bd9Sstevel@tonic-gate * Returns PO_SUCCESS/PO_FAIL 25177c478bd9Sstevel@tonic-gate */ 25187c478bd9Sstevel@tonic-gate int 25197c478bd9Sstevel@tonic-gate pool_set_container(pool_elem_t *pp, pool_elem_t *pc) 25207c478bd9Sstevel@tonic-gate { 25217c478bd9Sstevel@tonic-gate return (pc->pe_set_container(pp, pc)); 25227c478bd9Sstevel@tonic-gate } 25237c478bd9Sstevel@tonic-gate 25247c478bd9Sstevel@tonic-gate /* 25257c478bd9Sstevel@tonic-gate * Conversion routines for converting to and from elem and it's various 25267c478bd9Sstevel@tonic-gate * subtypes of system, pool, res and comp. 25277c478bd9Sstevel@tonic-gate */ 25287c478bd9Sstevel@tonic-gate pool_elem_t * 25297c478bd9Sstevel@tonic-gate pool_system_elem(const pool_system_t *ph) 25307c478bd9Sstevel@tonic-gate { 25317c478bd9Sstevel@tonic-gate return ((pool_elem_t *)ph); 25327c478bd9Sstevel@tonic-gate } 25337c478bd9Sstevel@tonic-gate 25347c478bd9Sstevel@tonic-gate pool_elem_t * 25357c478bd9Sstevel@tonic-gate pool_conf_to_elem(const pool_conf_t *conf) 25367c478bd9Sstevel@tonic-gate { 25377c478bd9Sstevel@tonic-gate pool_system_t *sys; 25387c478bd9Sstevel@tonic-gate 25397c478bd9Sstevel@tonic-gate if (pool_conf_status(conf) == POF_INVALID) { 25407c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 25417c478bd9Sstevel@tonic-gate return (NULL); 25427c478bd9Sstevel@tonic-gate } 25437c478bd9Sstevel@tonic-gate if ((sys = pool_conf_system(conf)) == NULL) { 25447c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 25457c478bd9Sstevel@tonic-gate return (NULL); 25467c478bd9Sstevel@tonic-gate } 25477c478bd9Sstevel@tonic-gate return (pool_system_elem(sys)); 25487c478bd9Sstevel@tonic-gate } 25497c478bd9Sstevel@tonic-gate 25507c478bd9Sstevel@tonic-gate pool_elem_t * 25517c478bd9Sstevel@tonic-gate pool_to_elem(const pool_conf_t *conf, const pool_t *pp) 25527c478bd9Sstevel@tonic-gate { 25537c478bd9Sstevel@tonic-gate if (pool_conf_status(conf) == POF_INVALID) { 25547c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 25557c478bd9Sstevel@tonic-gate return (NULL); 25567c478bd9Sstevel@tonic-gate } 25577c478bd9Sstevel@tonic-gate return ((pool_elem_t *)pp); 25587c478bd9Sstevel@tonic-gate } 25597c478bd9Sstevel@tonic-gate 25607c478bd9Sstevel@tonic-gate pool_elem_t * 25617c478bd9Sstevel@tonic-gate pool_resource_to_elem(const pool_conf_t *conf, const pool_resource_t *prs) 25627c478bd9Sstevel@tonic-gate { 25637c478bd9Sstevel@tonic-gate if (pool_conf_status(conf) == POF_INVALID) { 25647c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 25657c478bd9Sstevel@tonic-gate return (NULL); 25667c478bd9Sstevel@tonic-gate } 25677c478bd9Sstevel@tonic-gate return ((pool_elem_t *)prs); 25687c478bd9Sstevel@tonic-gate } 25697c478bd9Sstevel@tonic-gate 25707c478bd9Sstevel@tonic-gate pool_elem_t * 25717c478bd9Sstevel@tonic-gate pool_component_to_elem(const pool_conf_t *conf, const pool_component_t *pr) 25727c478bd9Sstevel@tonic-gate { 25737c478bd9Sstevel@tonic-gate if (pool_conf_status(conf) == POF_INVALID) { 25747c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 25757c478bd9Sstevel@tonic-gate return (NULL); 25767c478bd9Sstevel@tonic-gate } 25777c478bd9Sstevel@tonic-gate return ((pool_elem_t *)pr); 25787c478bd9Sstevel@tonic-gate } 25797c478bd9Sstevel@tonic-gate 25807c478bd9Sstevel@tonic-gate /* 25817c478bd9Sstevel@tonic-gate * Walk all the pools of the configuration calling the user supplied function 25827c478bd9Sstevel@tonic-gate * as long as the user function continues to return PO_TRUE 25837c478bd9Sstevel@tonic-gate */ 25847c478bd9Sstevel@tonic-gate int 25857c478bd9Sstevel@tonic-gate pool_walk_pools(pool_conf_t *conf, void *arg, 25867c478bd9Sstevel@tonic-gate int (*callback)(pool_conf_t *conf, pool_t *pool, void *arg)) 25877c478bd9Sstevel@tonic-gate { 25887c478bd9Sstevel@tonic-gate pool_t **rs; 25897c478bd9Sstevel@tonic-gate int i; 25907c478bd9Sstevel@tonic-gate uint_t size; 25917c478bd9Sstevel@tonic-gate int error = PO_SUCCESS; 25927c478bd9Sstevel@tonic-gate 25937c478bd9Sstevel@tonic-gate if (pool_conf_status(conf) == POF_INVALID) { 25947c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 25957c478bd9Sstevel@tonic-gate return (PO_FAIL); 25967c478bd9Sstevel@tonic-gate } 25977c478bd9Sstevel@tonic-gate 25987c478bd9Sstevel@tonic-gate if ((rs = pool_query_pools(conf, &size, NULL)) == NULL) /* None */ 25997c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 26007c478bd9Sstevel@tonic-gate for (i = 0; i < size; i++) 26017c478bd9Sstevel@tonic-gate if (callback(conf, rs[i], arg) != PO_SUCCESS) { 26027c478bd9Sstevel@tonic-gate error = PO_FAIL; 26037c478bd9Sstevel@tonic-gate break; 26047c478bd9Sstevel@tonic-gate } 26057c478bd9Sstevel@tonic-gate free(rs); 26067c478bd9Sstevel@tonic-gate return (error); 26077c478bd9Sstevel@tonic-gate } 26087c478bd9Sstevel@tonic-gate 26097c478bd9Sstevel@tonic-gate /* 26107c478bd9Sstevel@tonic-gate * Walk all the comp of the res calling the user supplied function 26117c478bd9Sstevel@tonic-gate * as long as the user function continues to return PO_TRUE 26127c478bd9Sstevel@tonic-gate */ 26137c478bd9Sstevel@tonic-gate int 26147c478bd9Sstevel@tonic-gate pool_walk_components(pool_conf_t *conf, pool_resource_t *prs, void *arg, 26157c478bd9Sstevel@tonic-gate int (*callback)(pool_conf_t *conf, pool_component_t *pr, void *arg)) 26167c478bd9Sstevel@tonic-gate { 26177c478bd9Sstevel@tonic-gate pool_component_t **rs; 26187c478bd9Sstevel@tonic-gate int i; 26197c478bd9Sstevel@tonic-gate uint_t size; 26207c478bd9Sstevel@tonic-gate int error = PO_SUCCESS; 26217c478bd9Sstevel@tonic-gate 26227c478bd9Sstevel@tonic-gate if (pool_conf_status(conf) == POF_INVALID) { 26237c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 26247c478bd9Sstevel@tonic-gate return (PO_FAIL); 26257c478bd9Sstevel@tonic-gate } 26267c478bd9Sstevel@tonic-gate 26277c478bd9Sstevel@tonic-gate if ((rs = pool_query_resource_components(conf, prs, &size, NULL)) == 26287c478bd9Sstevel@tonic-gate NULL) 26297c478bd9Sstevel@tonic-gate return (PO_SUCCESS); /* None */ 26307c478bd9Sstevel@tonic-gate for (i = 0; i < size; i++) 26317c478bd9Sstevel@tonic-gate if (callback(conf, rs[i], arg) != PO_SUCCESS) { 26327c478bd9Sstevel@tonic-gate error = PO_FAIL; 26337c478bd9Sstevel@tonic-gate break; 26347c478bd9Sstevel@tonic-gate } 26357c478bd9Sstevel@tonic-gate free(rs); 26367c478bd9Sstevel@tonic-gate return (error); 26377c478bd9Sstevel@tonic-gate } 26387c478bd9Sstevel@tonic-gate 26397c478bd9Sstevel@tonic-gate /* 26407c478bd9Sstevel@tonic-gate * Return an array of all matching res for the supplied pool. 26417c478bd9Sstevel@tonic-gate */ 26427c478bd9Sstevel@tonic-gate pool_resource_t ** 26437c478bd9Sstevel@tonic-gate pool_query_pool_resources(const pool_conf_t *conf, const pool_t *pp, 26447c478bd9Sstevel@tonic-gate uint_t *size, pool_value_t **props) 26457c478bd9Sstevel@tonic-gate { 26467c478bd9Sstevel@tonic-gate pool_result_set_t *rs; 26477c478bd9Sstevel@tonic-gate pool_elem_t *pe; 26487c478bd9Sstevel@tonic-gate pool_resource_t **result = NULL; 26497c478bd9Sstevel@tonic-gate int i = 0; 26507c478bd9Sstevel@tonic-gate 26517c478bd9Sstevel@tonic-gate if (pool_conf_status(conf) == POF_INVALID) { 26527c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 26537c478bd9Sstevel@tonic-gate return (NULL); 26547c478bd9Sstevel@tonic-gate } 26557c478bd9Sstevel@tonic-gate 26567c478bd9Sstevel@tonic-gate pe = TO_ELEM(pp); 26577c478bd9Sstevel@tonic-gate 26587c478bd9Sstevel@tonic-gate rs = pool_exec_query(conf, pe, "res", PEC_QRY_RES, props); 26597c478bd9Sstevel@tonic-gate if (rs == NULL) { 26607c478bd9Sstevel@tonic-gate return (NULL); 26617c478bd9Sstevel@tonic-gate } 26627c478bd9Sstevel@tonic-gate if ((*size = pool_rs_count(rs)) == 0) { 26637c478bd9Sstevel@tonic-gate (void) pool_rs_close(rs); 26647c478bd9Sstevel@tonic-gate return (NULL); 26657c478bd9Sstevel@tonic-gate } 26667c478bd9Sstevel@tonic-gate if ((result = malloc(sizeof (pool_resource_t *) * (*size + 1))) 26677c478bd9Sstevel@tonic-gate == NULL) { 26687c478bd9Sstevel@tonic-gate pool_seterror(POE_SYSTEM); 26697c478bd9Sstevel@tonic-gate (void) pool_rs_close(rs); 26707c478bd9Sstevel@tonic-gate return (NULL); 26717c478bd9Sstevel@tonic-gate } 26727c478bd9Sstevel@tonic-gate (void) memset(result, 0, sizeof (pool_resource_t *) * (*size + 1)); 26737c478bd9Sstevel@tonic-gate for (pe = rs->prs_next(rs); pe != NULL; pe = rs->prs_next(rs)) { 26747c478bd9Sstevel@tonic-gate if (pool_elem_class(pe) != PEC_RES_COMP && 26757c478bd9Sstevel@tonic-gate pool_elem_class(pe) != PEC_RES_AGG) { 26767c478bd9Sstevel@tonic-gate pool_seterror(POE_INVALID_CONF); 26777c478bd9Sstevel@tonic-gate free(result); 26787c478bd9Sstevel@tonic-gate (void) pool_rs_close(rs); 26797c478bd9Sstevel@tonic-gate return (NULL); 26807c478bd9Sstevel@tonic-gate } 26817c478bd9Sstevel@tonic-gate result[i++] = pool_elem_res(pe); 26827c478bd9Sstevel@tonic-gate } 26837c478bd9Sstevel@tonic-gate (void) pool_rs_close(rs); 26847c478bd9Sstevel@tonic-gate return (result); 26857c478bd9Sstevel@tonic-gate } 26867c478bd9Sstevel@tonic-gate 26877c478bd9Sstevel@tonic-gate /* 26887c478bd9Sstevel@tonic-gate * Walk all the res of the pool calling the user supplied function 26897c478bd9Sstevel@tonic-gate * as long as the user function continues to return PO_TRUE 26907c478bd9Sstevel@tonic-gate */ 26917c478bd9Sstevel@tonic-gate int 26927c478bd9Sstevel@tonic-gate pool_walk_resources(pool_conf_t *conf, pool_t *pp, void *arg, 26937c478bd9Sstevel@tonic-gate int (*callback)(pool_conf_t *, pool_resource_t *, void *)) 26947c478bd9Sstevel@tonic-gate { 26957c478bd9Sstevel@tonic-gate pool_resource_t **rs; 26967c478bd9Sstevel@tonic-gate int i; 26977c478bd9Sstevel@tonic-gate uint_t size; 26987c478bd9Sstevel@tonic-gate int error = PO_SUCCESS; 26997c478bd9Sstevel@tonic-gate 27007c478bd9Sstevel@tonic-gate if (pool_conf_status(conf) == POF_INVALID) { 27017c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 27027c478bd9Sstevel@tonic-gate return (PO_FAIL); 27037c478bd9Sstevel@tonic-gate } 27047c478bd9Sstevel@tonic-gate if ((rs = pool_query_pool_resources(conf, pp, &size, NULL)) == NULL) 27057c478bd9Sstevel@tonic-gate return (PO_SUCCESS); /* None */ 27067c478bd9Sstevel@tonic-gate for (i = 0; i < size; i++) 27077c478bd9Sstevel@tonic-gate if (callback(conf, rs[i], arg) != PO_SUCCESS) { 27087c478bd9Sstevel@tonic-gate error = PO_FAIL; 27097c478bd9Sstevel@tonic-gate break; 27107c478bd9Sstevel@tonic-gate } 27117c478bd9Sstevel@tonic-gate free(rs); 27127c478bd9Sstevel@tonic-gate return (error); 27137c478bd9Sstevel@tonic-gate } 27147c478bd9Sstevel@tonic-gate 27157c478bd9Sstevel@tonic-gate /* 27167c478bd9Sstevel@tonic-gate * Return a result set of all comp for the supplied res. 27177c478bd9Sstevel@tonic-gate */ 27187c478bd9Sstevel@tonic-gate pool_component_t ** 27197c478bd9Sstevel@tonic-gate pool_query_resource_components(const pool_conf_t *conf, 27207c478bd9Sstevel@tonic-gate const pool_resource_t *prs, uint_t *size, pool_value_t **props) 27217c478bd9Sstevel@tonic-gate { 27227c478bd9Sstevel@tonic-gate pool_result_set_t *rs; 27237c478bd9Sstevel@tonic-gate pool_elem_t *pe; 27247c478bd9Sstevel@tonic-gate pool_component_t **result = NULL; 27257c478bd9Sstevel@tonic-gate int i = 0; 27267c478bd9Sstevel@tonic-gate 27277c478bd9Sstevel@tonic-gate if (pool_conf_status(conf) == POF_INVALID) { 27287c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 27297c478bd9Sstevel@tonic-gate return (NULL); 27307c478bd9Sstevel@tonic-gate } 27317c478bd9Sstevel@tonic-gate pe = TO_ELEM(prs); 27327c478bd9Sstevel@tonic-gate 27337c478bd9Sstevel@tonic-gate rs = pool_exec_query(conf, pe, NULL, PEC_QRY_COMP, props); 27347c478bd9Sstevel@tonic-gate if (rs == NULL) { 27357c478bd9Sstevel@tonic-gate return (NULL); 27367c478bd9Sstevel@tonic-gate } 27377c478bd9Sstevel@tonic-gate if ((*size = pool_rs_count(rs)) == 0) { 27387c478bd9Sstevel@tonic-gate (void) pool_rs_close(rs); 27397c478bd9Sstevel@tonic-gate return (NULL); 27407c478bd9Sstevel@tonic-gate } 27417c478bd9Sstevel@tonic-gate if ((result = malloc(sizeof (pool_component_t *) * (*size + 1))) 27427c478bd9Sstevel@tonic-gate == NULL) { 27437c478bd9Sstevel@tonic-gate pool_seterror(POE_SYSTEM); 27447c478bd9Sstevel@tonic-gate (void) pool_rs_close(rs); 27457c478bd9Sstevel@tonic-gate return (NULL); 27467c478bd9Sstevel@tonic-gate } 27477c478bd9Sstevel@tonic-gate (void) memset(result, 0, sizeof (pool_component_t *) * (*size + 1)); 27487c478bd9Sstevel@tonic-gate for (pe = rs->prs_next(rs); pe != NULL; pe = rs->prs_next(rs)) { 27497c478bd9Sstevel@tonic-gate if (pool_elem_class(pe) != PEC_COMP) { 27507c478bd9Sstevel@tonic-gate pool_seterror(POE_INVALID_CONF); 27517c478bd9Sstevel@tonic-gate free(result); 27527c478bd9Sstevel@tonic-gate (void) pool_rs_close(rs); 27537c478bd9Sstevel@tonic-gate return (NULL); 27547c478bd9Sstevel@tonic-gate } 27557c478bd9Sstevel@tonic-gate result[i++] = pool_elem_comp(pe); 27567c478bd9Sstevel@tonic-gate } 27577c478bd9Sstevel@tonic-gate (void) pool_rs_close(rs); 27587c478bd9Sstevel@tonic-gate return (result); 27597c478bd9Sstevel@tonic-gate } 27607c478bd9Sstevel@tonic-gate 27617c478bd9Sstevel@tonic-gate /* 27627c478bd9Sstevel@tonic-gate * pool_version() returns the version of this library, depending on the supplied 27637c478bd9Sstevel@tonic-gate * parameter. 27647c478bd9Sstevel@tonic-gate * 27657c478bd9Sstevel@tonic-gate * Returns: library version depening on the supplied ver parameter. 27667c478bd9Sstevel@tonic-gate */ 27677c478bd9Sstevel@tonic-gate uint_t 27687c478bd9Sstevel@tonic-gate pool_version(uint_t ver) 27697c478bd9Sstevel@tonic-gate { 27707c478bd9Sstevel@tonic-gate switch (ver) { 27717c478bd9Sstevel@tonic-gate case POOL_VER_NONE: 27727c478bd9Sstevel@tonic-gate break; 27737c478bd9Sstevel@tonic-gate case POOL_VER_CURRENT: 27747c478bd9Sstevel@tonic-gate pool_workver = ver; 27757c478bd9Sstevel@tonic-gate break; 27767c478bd9Sstevel@tonic-gate default: 27777c478bd9Sstevel@tonic-gate return (POOL_VER_NONE); 27787c478bd9Sstevel@tonic-gate } 27797c478bd9Sstevel@tonic-gate return (pool_workver); 27807c478bd9Sstevel@tonic-gate } 27817c478bd9Sstevel@tonic-gate 27827c478bd9Sstevel@tonic-gate /* 27837c478bd9Sstevel@tonic-gate * pool_associate() associates the supplied resource to the supplied pool. 27847c478bd9Sstevel@tonic-gate * 27857c478bd9Sstevel@tonic-gate * Returns: PO_SUCCESS/PO_FAIL 27867c478bd9Sstevel@tonic-gate */ 27877c478bd9Sstevel@tonic-gate int 27887c478bd9Sstevel@tonic-gate pool_associate(pool_conf_t *conf, pool_t *pool, const pool_resource_t *res) 27897c478bd9Sstevel@tonic-gate { 27907c478bd9Sstevel@tonic-gate if (pool_conf_check(conf) != PO_SUCCESS) 27917c478bd9Sstevel@tonic-gate return (PO_FAIL); 27927c478bd9Sstevel@tonic-gate 27937c478bd9Sstevel@tonic-gate return (pool->pp_associate(pool, res)); 27947c478bd9Sstevel@tonic-gate } 27957c478bd9Sstevel@tonic-gate 27967c478bd9Sstevel@tonic-gate /* 27977c478bd9Sstevel@tonic-gate * pool_dissociate() dissociates the supplied resource from the supplied pool. 27987c478bd9Sstevel@tonic-gate * 27997c478bd9Sstevel@tonic-gate * Returns: PO_SUCCESS/PO_FAIL 28007c478bd9Sstevel@tonic-gate */ 28017c478bd9Sstevel@tonic-gate int 28027c478bd9Sstevel@tonic-gate pool_dissociate(pool_conf_t *conf, pool_t *pool, const pool_resource_t *res) 28037c478bd9Sstevel@tonic-gate { 28047c478bd9Sstevel@tonic-gate if (pool_conf_check(conf) != PO_SUCCESS) 28057c478bd9Sstevel@tonic-gate return (PO_FAIL); 28067c478bd9Sstevel@tonic-gate 28077c478bd9Sstevel@tonic-gate if (elem_is_default(TO_ELEM(res))) 28087c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 28097c478bd9Sstevel@tonic-gate return (pool->pp_dissociate(pool, res)); 28107c478bd9Sstevel@tonic-gate } 28117c478bd9Sstevel@tonic-gate 28127c478bd9Sstevel@tonic-gate /* 28137c478bd9Sstevel@tonic-gate * Compare two elements for purposes of ordering. 28147c478bd9Sstevel@tonic-gate * Return: 28157c478bd9Sstevel@tonic-gate * < 0 if e1 is "before" e2 28167c478bd9Sstevel@tonic-gate * 0 if e1 "equals" e2 28177c478bd9Sstevel@tonic-gate * > 0 if e1 comes after e2 28187c478bd9Sstevel@tonic-gate */ 28197c478bd9Sstevel@tonic-gate int 28207c478bd9Sstevel@tonic-gate pool_elem_compare_name(const pool_elem_t *e1, const pool_elem_t *e2) 28217c478bd9Sstevel@tonic-gate { 28227c478bd9Sstevel@tonic-gate char *name1, *name2; 28237c478bd9Sstevel@tonic-gate pool_value_t val = POOL_VALUE_INITIALIZER; 28247c478bd9Sstevel@tonic-gate int retval; 28257c478bd9Sstevel@tonic-gate 28267c478bd9Sstevel@tonic-gate /* 28277c478bd9Sstevel@tonic-gate * We may be asked to compare two elements from different classes. 28287c478bd9Sstevel@tonic-gate * They are different so return (1). 28297c478bd9Sstevel@tonic-gate */ 28307c478bd9Sstevel@tonic-gate if (pool_elem_same_class(e1, e2) != PO_TRUE) 28317c478bd9Sstevel@tonic-gate return (1); 28327c478bd9Sstevel@tonic-gate 28337c478bd9Sstevel@tonic-gate /* 28347c478bd9Sstevel@tonic-gate * If the class is PEC_SYSTEM, always match them 28357c478bd9Sstevel@tonic-gate */ 28367c478bd9Sstevel@tonic-gate if (pool_elem_class(e1) == PEC_SYSTEM) 28377c478bd9Sstevel@tonic-gate return (0); 28387c478bd9Sstevel@tonic-gate 28397c478bd9Sstevel@tonic-gate /* 28407c478bd9Sstevel@tonic-gate * If we are going to compare components, then use sys_id 28417c478bd9Sstevel@tonic-gate */ 28427c478bd9Sstevel@tonic-gate if (pool_elem_class(e1) == PEC_COMP) { 28437c478bd9Sstevel@tonic-gate int64_t sys_id1, sys_id2; 28447c478bd9Sstevel@tonic-gate 28457c478bd9Sstevel@tonic-gate if (pool_get_ns_property(e1, c_sys_prop, &val) == POC_INVAL) { 28467c478bd9Sstevel@tonic-gate return (-1); 28477c478bd9Sstevel@tonic-gate } 28487c478bd9Sstevel@tonic-gate (void) pool_value_get_int64(&val, &sys_id1); 28497c478bd9Sstevel@tonic-gate if (pool_get_ns_property(e2, c_sys_prop, &val) == POC_INVAL) { 28507c478bd9Sstevel@tonic-gate return (-1); 28517c478bd9Sstevel@tonic-gate } 28527c478bd9Sstevel@tonic-gate (void) pool_value_get_int64(&val, &sys_id2); 28537c478bd9Sstevel@tonic-gate retval = (sys_id1 - sys_id2); 28547c478bd9Sstevel@tonic-gate } else { 28557c478bd9Sstevel@tonic-gate if (pool_get_ns_property(e1, "name", &val) == POC_INVAL) { 28567c478bd9Sstevel@tonic-gate return (-1); 28577c478bd9Sstevel@tonic-gate } 28587c478bd9Sstevel@tonic-gate (void) pool_value_get_string(&val, (const char **)&name1); 28597c478bd9Sstevel@tonic-gate if ((name1 = strdup(name1)) == NULL) { 28607c478bd9Sstevel@tonic-gate return (-1); 28617c478bd9Sstevel@tonic-gate } 28627c478bd9Sstevel@tonic-gate 28637c478bd9Sstevel@tonic-gate if (pool_get_ns_property(e2, "name", &val) == POC_INVAL) { 28647c478bd9Sstevel@tonic-gate return (-1); 28657c478bd9Sstevel@tonic-gate } 28667c478bd9Sstevel@tonic-gate 28677c478bd9Sstevel@tonic-gate (void) pool_value_get_string(&val, (const char **)&name2); 28687c478bd9Sstevel@tonic-gate retval = strcmp(name1, name2); 28697c478bd9Sstevel@tonic-gate free(name1); 28707c478bd9Sstevel@tonic-gate } 28717c478bd9Sstevel@tonic-gate return (retval); 28727c478bd9Sstevel@tonic-gate } 28737c478bd9Sstevel@tonic-gate 28747c478bd9Sstevel@tonic-gate /* 28757c478bd9Sstevel@tonic-gate * Compare two elements for purposes of ordering. 28767c478bd9Sstevel@tonic-gate * Return: 28777c478bd9Sstevel@tonic-gate * < 0 if e1 is "before" e2 28787c478bd9Sstevel@tonic-gate * 0 if e1 "equals" e2 28797c478bd9Sstevel@tonic-gate * > 0 if e1 comes after e2 28807c478bd9Sstevel@tonic-gate */ 28817c478bd9Sstevel@tonic-gate int 28827c478bd9Sstevel@tonic-gate pool_elem_compare(const pool_elem_t *e1, const pool_elem_t *e2) 28837c478bd9Sstevel@tonic-gate { 28847c478bd9Sstevel@tonic-gate pool_value_t val = POOL_VALUE_INITIALIZER; 28857c478bd9Sstevel@tonic-gate int64_t sys_id1, sys_id2; 28867c478bd9Sstevel@tonic-gate 28877c478bd9Sstevel@tonic-gate /* 28887c478bd9Sstevel@tonic-gate * We may be asked to compare two elements from different classes. 28897c478bd9Sstevel@tonic-gate * They are different so return the difference in their classes 28907c478bd9Sstevel@tonic-gate */ 28917c478bd9Sstevel@tonic-gate if (pool_elem_same_class(e1, e2) != PO_TRUE) 28927c478bd9Sstevel@tonic-gate return (1); 28937c478bd9Sstevel@tonic-gate 28947c478bd9Sstevel@tonic-gate /* 28957c478bd9Sstevel@tonic-gate * If the class is PEC_SYSTEM, always match them 28967c478bd9Sstevel@tonic-gate */ 28977c478bd9Sstevel@tonic-gate if (pool_elem_class(e1) == PEC_SYSTEM) 28987c478bd9Sstevel@tonic-gate return (0); 28997c478bd9Sstevel@tonic-gate 29007c478bd9Sstevel@tonic-gate /* 29017c478bd9Sstevel@tonic-gate * Compare with sys_id 29027c478bd9Sstevel@tonic-gate */ 29037c478bd9Sstevel@tonic-gate if (pool_get_ns_property(e1, c_sys_prop, &val) == POC_INVAL) { 29047c478bd9Sstevel@tonic-gate assert(!"no sys_id on e1\n"); 29057c478bd9Sstevel@tonic-gate } 29067c478bd9Sstevel@tonic-gate (void) pool_value_get_int64(&val, &sys_id1); 29077c478bd9Sstevel@tonic-gate if (pool_get_ns_property(e2, c_sys_prop, &val) == POC_INVAL) { 29087c478bd9Sstevel@tonic-gate assert(!"no sys_id on e2\n"); 29097c478bd9Sstevel@tonic-gate } 29107c478bd9Sstevel@tonic-gate (void) pool_value_get_int64(&val, &sys_id2); 29117c478bd9Sstevel@tonic-gate return (sys_id1 - sys_id2); 29127c478bd9Sstevel@tonic-gate } 29137c478bd9Sstevel@tonic-gate 29147c478bd9Sstevel@tonic-gate /* 29157c478bd9Sstevel@tonic-gate * Return PO_TRUE if the supplied elems are of the same class. 29167c478bd9Sstevel@tonic-gate */ 29177c478bd9Sstevel@tonic-gate int 29187c478bd9Sstevel@tonic-gate pool_elem_same_class(const pool_elem_t *e1, const pool_elem_t *e2) 29197c478bd9Sstevel@tonic-gate { 29207c478bd9Sstevel@tonic-gate if (pool_elem_class(e1) != pool_elem_class(e2)) 29217c478bd9Sstevel@tonic-gate return (PO_FALSE); 29227c478bd9Sstevel@tonic-gate 29237c478bd9Sstevel@tonic-gate /* 29247c478bd9Sstevel@tonic-gate * Check to make sure the fundamental class of the elements match 29257c478bd9Sstevel@tonic-gate */ 29267c478bd9Sstevel@tonic-gate if (pool_elem_class(e1) == PEC_RES_COMP || 29277c478bd9Sstevel@tonic-gate pool_elem_class(e1) == PEC_RES_AGG) 29287c478bd9Sstevel@tonic-gate if (pool_resource_elem_class(e1) != 29297c478bd9Sstevel@tonic-gate pool_resource_elem_class(e2)) 29307c478bd9Sstevel@tonic-gate return (PO_FALSE); 29317c478bd9Sstevel@tonic-gate if (pool_elem_class(e1) == PEC_COMP) 29327c478bd9Sstevel@tonic-gate if (pool_component_elem_class(e1) != 29337c478bd9Sstevel@tonic-gate pool_component_elem_class(e2)) 29347c478bd9Sstevel@tonic-gate return (PO_FALSE); 29357c478bd9Sstevel@tonic-gate return (PO_TRUE); 29367c478bd9Sstevel@tonic-gate } 29377c478bd9Sstevel@tonic-gate 29387c478bd9Sstevel@tonic-gate /* 29397c478bd9Sstevel@tonic-gate * pool_conf_check() checks that the configuration state isn't invalid 29407c478bd9Sstevel@tonic-gate * and that the configuration was opened for modification. 29417c478bd9Sstevel@tonic-gate */ 29427c478bd9Sstevel@tonic-gate int 29437c478bd9Sstevel@tonic-gate pool_conf_check(const pool_conf_t *conf) 29447c478bd9Sstevel@tonic-gate { 29457c478bd9Sstevel@tonic-gate if (pool_conf_status(conf) == POF_INVALID) { 29467c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 29477c478bd9Sstevel@tonic-gate return (PO_FAIL); 29487c478bd9Sstevel@tonic-gate } 29497c478bd9Sstevel@tonic-gate 29507c478bd9Sstevel@tonic-gate if ((conf->pc_prov->pc_oflags & PO_RDWR) == 0) { 29517c478bd9Sstevel@tonic-gate pool_seterror(POE_BADPARAM); 29527c478bd9Sstevel@tonic-gate return (PO_FAIL); 29537c478bd9Sstevel@tonic-gate } 29547c478bd9Sstevel@tonic-gate return (PO_SUCCESS); 29557c478bd9Sstevel@tonic-gate } 2956