17c478bd9Sstevel@tonic-gate %{ 27c478bd9Sstevel@tonic-gate /* 37c478bd9Sstevel@tonic-gate * CDDL HEADER START 47c478bd9Sstevel@tonic-gate * 57c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 67c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 77c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 87c478bd9Sstevel@tonic-gate * with the License. 97c478bd9Sstevel@tonic-gate * 107c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 117c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 127c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 137c478bd9Sstevel@tonic-gate * and limitations under the License. 147c478bd9Sstevel@tonic-gate * 157c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 167c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 177c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 187c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 197c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 207c478bd9Sstevel@tonic-gate * 217c478bd9Sstevel@tonic-gate * CDDL HEADER END 227c478bd9Sstevel@tonic-gate * 23*26d8ba22Sgarypen * Copyright 2005 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 /* 307c478bd9Sstevel@tonic-gate * Overview of poolcfg(1) 317c478bd9Sstevel@tonic-gate * 327c478bd9Sstevel@tonic-gate * poolcfg(1) implements a small grammar for manipulating pools configurations. 337c478bd9Sstevel@tonic-gate * yacc(1) is used to generate the parser and poolcfg.l contains a simple lexer 347c478bd9Sstevel@tonic-gate * (generted by lex(1)) to perform lexical processsing of the input. 357c478bd9Sstevel@tonic-gate * 367c478bd9Sstevel@tonic-gate * Refer to the poolcfg(1) manpage for more details of the grammar. 377c478bd9Sstevel@tonic-gate * 387c478bd9Sstevel@tonic-gate * The parser is designed so that all operations implement the same interface. 397c478bd9Sstevel@tonic-gate * This allows the parser to simply build up the command (using the cmd 407c478bd9Sstevel@tonic-gate * variable) by storing arguments and a pointer to the desired function in the 417c478bd9Sstevel@tonic-gate * cmd. The command is executed when the commands production is matched. 427c478bd9Sstevel@tonic-gate * 437c478bd9Sstevel@tonic-gate * Properties and associations are stored in simple linked lists and processed 447c478bd9Sstevel@tonic-gate * in the order submitted by the user. 457c478bd9Sstevel@tonic-gate */ 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate #include <stdlib.h> 487c478bd9Sstevel@tonic-gate #include <stdio.h> 497c478bd9Sstevel@tonic-gate #include <string.h> 507c478bd9Sstevel@tonic-gate #include <errno.h> 517c478bd9Sstevel@tonic-gate #include <sys/types.h> 527c478bd9Sstevel@tonic-gate #include <locale.h> 537c478bd9Sstevel@tonic-gate #include <libintl.h> 547c478bd9Sstevel@tonic-gate #include <sys/utsname.h> 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate #include <pool.h> 577c478bd9Sstevel@tonic-gate #include "utils.h" 587c478bd9Sstevel@tonic-gate #include "poolcfg.h" 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate #define USAGE1 \ 637c478bd9Sstevel@tonic-gate "Usage:\n" \ 647c478bd9Sstevel@tonic-gate "%s -h\n" \ 657c478bd9Sstevel@tonic-gate "%s -c command [ -d | [ file ] ]\n" \ 667c478bd9Sstevel@tonic-gate "%s -f command-file [-d | [ file ] ]\n\n" 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate #define USAGE2 \ 697c478bd9Sstevel@tonic-gate "command:\n" \ 707c478bd9Sstevel@tonic-gate " info [entity name]\n" \ 717c478bd9Sstevel@tonic-gate " display configuration (or specified portion) in readable form\n" \ 727c478bd9Sstevel@tonic-gate " create entity name [property-list]\n" \ 737c478bd9Sstevel@tonic-gate " make an entity of the specified type and name\n" \ 747c478bd9Sstevel@tonic-gate " destroy entity name\n" \ 757c478bd9Sstevel@tonic-gate " remove the specified entity\n" \ 767c478bd9Sstevel@tonic-gate " modify entity name [property-list]\n" \ 777c478bd9Sstevel@tonic-gate " change the listed properties on the named entity\n" \ 787c478bd9Sstevel@tonic-gate " associate pool name [resource-list]\n" \ 797c478bd9Sstevel@tonic-gate " connect one or more resources to a pool, or replace one or more\n" \ 807c478bd9Sstevel@tonic-gate " existing connections\n" \ 817c478bd9Sstevel@tonic-gate " transfer to resource name [component-list]\n" \ 827c478bd9Sstevel@tonic-gate " transfer one or more discreet components to a resource\n" \ 837c478bd9Sstevel@tonic-gate " transfer [quantity] from resource src to tgt\n" \ 847c478bd9Sstevel@tonic-gate " transfer a resource quantity from src to tgt\n" \ 857c478bd9Sstevel@tonic-gate " transfer [quantity] to resource tgt from src\n" \ 867c478bd9Sstevel@tonic-gate " transfer a resource quantity to tgt from src\n" \ 877c478bd9Sstevel@tonic-gate " discover\n" \ 887c478bd9Sstevel@tonic-gate " create a system entity, with one pool entity and resources to\n" \ 897c478bd9Sstevel@tonic-gate " match current system configuration\n" \ 907c478bd9Sstevel@tonic-gate " rename entity old_name to new_name\n" \ 917c478bd9Sstevel@tonic-gate " change the name of the entity on the system to its new name\n\n" \ 927c478bd9Sstevel@tonic-gate "property-list:\n" \ 937c478bd9Sstevel@tonic-gate " ( proptype name = value [ ; proptype name = value ]* )\n" \ 947c478bd9Sstevel@tonic-gate " where multiple definitions in the sentence for a given\n" \ 957c478bd9Sstevel@tonic-gate " proptype, name pair are ignored; the last one provided is used.\n" \ 967c478bd9Sstevel@tonic-gate " For property deletion, use \"~ proptype name\"\n\n" \ 977c478bd9Sstevel@tonic-gate "resource-list:\n" \ 987c478bd9Sstevel@tonic-gate " ( resource name [; resource name ] )\n" \ 997c478bd9Sstevel@tonic-gate " where multiple uses of a resource are ignored; the last provided\n" \ 1007c478bd9Sstevel@tonic-gate " is the one used.\n" \ 1017c478bd9Sstevel@tonic-gate " There is no deletion syntax for resource lists.\n" \ 1027c478bd9Sstevel@tonic-gate "component-list:\n" \ 1037c478bd9Sstevel@tonic-gate " ( cpu id [; cpu id ] )\n" \ 1047c478bd9Sstevel@tonic-gate " where multiple uses of the same component cause the last provided\n" \ 1057c478bd9Sstevel@tonic-gate " to be the one used.\n" \ 1067c478bd9Sstevel@tonic-gate " There is no deletion syntax for component lists.\n" \ 1077c478bd9Sstevel@tonic-gate "entity:\n" \ 1087c478bd9Sstevel@tonic-gate " system | pool | pset | cpu\n" \ 1097c478bd9Sstevel@tonic-gate " where cpu is only valid for transfer, info and modify commands.\n" \ 1107c478bd9Sstevel@tonic-gate "resource:\n" \ 1117c478bd9Sstevel@tonic-gate " pset\n\n" \ 1127c478bd9Sstevel@tonic-gate "proptype:\n" \ 1137c478bd9Sstevel@tonic-gate " boolean | int | uint | string | float\n\n" 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate int dofile = PO_FALSE; /* poolcfg.l uses this for errors */ 1167c478bd9Sstevel@tonic-gate int conf_edit_error = POE_OK; /* cached error for error reporting */ 1177c478bd9Sstevel@tonic-gate int conf_edit_errno = 0; /* cached errno for error reporting */ 1187c478bd9Sstevel@tonic-gate int conf_list_error = POE_OK; /* cached error for error reporting */ 1197c478bd9Sstevel@tonic-gate int conf_list_errno = 0; /* cached errno for error reporting */ 1207c478bd9Sstevel@tonic-gate static const char cmdname[] = "poolcfg"; 1217c478bd9Sstevel@tonic-gate static const char cmd_options[] = "c:df:h"; 1227c478bd9Sstevel@tonic-gate static void usage(int); 1237c478bd9Sstevel@tonic-gate static const char *max_suffix = ".max"; 1247c478bd9Sstevel@tonic-gate static const char *min_suffix = ".min"; 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gate static const char *conf_file = NULL; /* Location of target config */ 1277c478bd9Sstevel@tonic-gate static cmd_t *cmd = NULL; /* Command being processed */ 1287c478bd9Sstevel@tonic-gate static pool_conf_t *conf = NULL; /* Config to be processed */ 1297c478bd9Sstevel@tonic-gate static int edited = PO_FALSE; /* Has the configuration been changed */ 1307c478bd9Sstevel@tonic-gate 1317c478bd9Sstevel@tonic-gate /* yacc externals */ 1327c478bd9Sstevel@tonic-gate extern FILE *yyin; 1337c478bd9Sstevel@tonic-gate extern int yydebug; 1347c478bd9Sstevel@tonic-gate extern void yyerror(char *s); 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate /* Utility functions */ 1377c478bd9Sstevel@tonic-gate static void arg_parse(const char *); 1387c478bd9Sstevel@tonic-gate static void file_parse(const char *); 1397c478bd9Sstevel@tonic-gate static cmd_t *alloc_cmd(void); 1407c478bd9Sstevel@tonic-gate static prop_t *alloc_prop(prop_op_t); 1417c478bd9Sstevel@tonic-gate static assoc_t *alloc_assoc(int, const char *); 1427c478bd9Sstevel@tonic-gate static void free_cmd(cmd_t *); 1437c478bd9Sstevel@tonic-gate static void check_conf_name(cmd_t *); 1447c478bd9Sstevel@tonic-gate static void prop_list_walk(cmd_t *, pool_elem_t *); 1457c478bd9Sstevel@tonic-gate static void assoc_list_walk(cmd_t *, pool_t *); 1467c478bd9Sstevel@tonic-gate static void transfer_list_walk(cmd_t *, pool_resource_t *); 1477c478bd9Sstevel@tonic-gate static void terminate(void); 1487c478bd9Sstevel@tonic-gate static pool_component_t *get_cpu(const char *); 1497c478bd9Sstevel@tonic-gate static void process_min_max(pool_resource_t *); 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate /* Info Commands */ 1527c478bd9Sstevel@tonic-gate static void parser_conf_info(cmd_t *); 1537c478bd9Sstevel@tonic-gate static void parser_pool_info(cmd_t *); 1547c478bd9Sstevel@tonic-gate static void parser_resource_info(cmd_t *, const char *); 1557c478bd9Sstevel@tonic-gate static void parser_pset_info(cmd_t *); 1567c478bd9Sstevel@tonic-gate static void parser_cpu_info(cmd_t *); 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate /* Create Commands */ 1597c478bd9Sstevel@tonic-gate static void parser_conf_create(cmd_t *); 1607c478bd9Sstevel@tonic-gate static void parser_pool_create(cmd_t *); 1617c478bd9Sstevel@tonic-gate static void parser_resource_create(cmd_t *, const char *); 1627c478bd9Sstevel@tonic-gate static void parser_pset_create(cmd_t *); 1637c478bd9Sstevel@tonic-gate 1647c478bd9Sstevel@tonic-gate /* Destroy Commands */ 1657c478bd9Sstevel@tonic-gate static void parser_conf_destroy(cmd_t *); 1667c478bd9Sstevel@tonic-gate static void parser_pool_destroy(cmd_t *); 1677c478bd9Sstevel@tonic-gate static void parser_resource_destroy(cmd_t *, const char *); 1687c478bd9Sstevel@tonic-gate static void parser_pset_destroy(cmd_t *); 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate /* Modify Commands */ 1717c478bd9Sstevel@tonic-gate static void parser_conf_modify(cmd_t *); 1727c478bd9Sstevel@tonic-gate static void parser_pool_modify(cmd_t *); 1737c478bd9Sstevel@tonic-gate static void parser_resource_modify(cmd_t *, const char *); 1747c478bd9Sstevel@tonic-gate static void parser_pset_modify(cmd_t *); 1757c478bd9Sstevel@tonic-gate static void parser_cpu_modify(cmd_t *); 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate /* Associate Commands */ 1787c478bd9Sstevel@tonic-gate static void parser_pool_associate(cmd_t *); 1797c478bd9Sstevel@tonic-gate 1807c478bd9Sstevel@tonic-gate /* Assign Commands */ 1817c478bd9Sstevel@tonic-gate static void parser_resource_xtransfer(cmd_t *); 1827c478bd9Sstevel@tonic-gate static void parser_resource_transfer(cmd_t *); 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate /* Discover Commands */ 1857c478bd9Sstevel@tonic-gate static void parser_conf_discover(cmd_t *); 1867c478bd9Sstevel@tonic-gate 1877c478bd9Sstevel@tonic-gate /* Rename Commands */ 1887c478bd9Sstevel@tonic-gate static void parser_rename(cmd_t *, pool_elem_t *, const char *); 1897c478bd9Sstevel@tonic-gate static void parser_conf_rename(cmd_t *); 1907c478bd9Sstevel@tonic-gate static void parser_pool_rename(cmd_t *); 1917c478bd9Sstevel@tonic-gate static void parser_pset_rename(cmd_t *); 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate 1947c478bd9Sstevel@tonic-gate %} 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate %union { 1977c478bd9Sstevel@tonic-gate double dval; 1987c478bd9Sstevel@tonic-gate uint64_t uval; 1997c478bd9Sstevel@tonic-gate int64_t ival; 2007c478bd9Sstevel@tonic-gate char *sval; 2017c478bd9Sstevel@tonic-gate uchar_t bval; 2027c478bd9Sstevel@tonic-gate cmd_t *cmd; 2037c478bd9Sstevel@tonic-gate prop_t *prop; 2047c478bd9Sstevel@tonic-gate pv_u val; 2057c478bd9Sstevel@tonic-gate assoc_t *assoc; 2067c478bd9Sstevel@tonic-gate } 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate %start commands 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate %token PCC_INFO PCC_CREATE PCC_DESTROY PCC_MODIFY PCC_ASSOC PCC_DISC PCC_RENAME 2117c478bd9Sstevel@tonic-gate %token PCC_TRANSFER 2127c478bd9Sstevel@tonic-gate %token PCK_FROM PCK_TO PCK_OPENLST PCK_CLOSELST PCK_SEPLST PCK_ASSIGN PCK_UNDEF 2137c478bd9Sstevel@tonic-gate PCK_COMMAND 2147c478bd9Sstevel@tonic-gate %token PCV_FILENAME PCV_SYMBOL PCV_VAL_INT PCV_VAL_UINT PCV_VAL_FLOAT 2157c478bd9Sstevel@tonic-gate PCV_VAL_STRING PCV_VAL_BOOLEAN 2167c478bd9Sstevel@tonic-gate %token PCT_INT PCT_UINT PCT_BOOLEAN PCT_FLOAT PCT_STRING 2177c478bd9Sstevel@tonic-gate %token PCE_SYSTEM PCE_POOL PCE_PSET PCE_CPU 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate %type <ival> PCV_VAL_INT 2207c478bd9Sstevel@tonic-gate %type <uval> PCV_VAL_UINT 2217c478bd9Sstevel@tonic-gate %type <bval> PCV_VAL_BOOLEAN 2227c478bd9Sstevel@tonic-gate %type <dval> PCV_VAL_FLOAT 2237c478bd9Sstevel@tonic-gate %type <sval> PCV_VAL_STRING 2247c478bd9Sstevel@tonic-gate %type <sval> PCV_SYMBOL 2257c478bd9Sstevel@tonic-gate %type <sval> PCV_FILENAME 2267c478bd9Sstevel@tonic-gate 2277c478bd9Sstevel@tonic-gate %type <ival> PCC_INFO 2287c478bd9Sstevel@tonic-gate %type <ival> PCE_SYSTEM PCE_POOL PCE_PSET PCE_CPU 2297c478bd9Sstevel@tonic-gate %type <ival> entity proptype info_entity modify_entity 2307c478bd9Sstevel@tonic-gate %type <sval> name src tgt 2317c478bd9Sstevel@tonic-gate %type <cmd> command 2327c478bd9Sstevel@tonic-gate %type <cmd> list_command info_command edit_command create_command 2337c478bd9Sstevel@tonic-gate destroy_command modify_command associate_command discover_command 2347c478bd9Sstevel@tonic-gate rename_command transfer_command transfer_qty transfer_components 2357c478bd9Sstevel@tonic-gate %type <prop> prop_remove prop_assign prop_op prop_ops property_list 2367c478bd9Sstevel@tonic-gate %type <assoc> resource_assign resource_assigns resource_list 2377c478bd9Sstevel@tonic-gate %type <assoc> component_assign component_assigns component_list 2387c478bd9Sstevel@tonic-gate %type <val> value 2397c478bd9Sstevel@tonic-gate %type <ival> resource component 2407c478bd9Sstevel@tonic-gate 2417c478bd9Sstevel@tonic-gate %% 2427c478bd9Sstevel@tonic-gate 2437c478bd9Sstevel@tonic-gate commands: command 2447c478bd9Sstevel@tonic-gate { 2457c478bd9Sstevel@tonic-gate if ($1->cmd != NULL) 2467c478bd9Sstevel@tonic-gate $1->cmd($1); 2477c478bd9Sstevel@tonic-gate free_cmd($1); 2487c478bd9Sstevel@tonic-gate } 2497c478bd9Sstevel@tonic-gate | commands command 2507c478bd9Sstevel@tonic-gate { 2517c478bd9Sstevel@tonic-gate if ($2->cmd != NULL) 2527c478bd9Sstevel@tonic-gate $2->cmd($2); 2537c478bd9Sstevel@tonic-gate free_cmd($2); 2547c478bd9Sstevel@tonic-gate } 2557c478bd9Sstevel@tonic-gate | command error { YYERROR;}; 2567c478bd9Sstevel@tonic-gate 2577c478bd9Sstevel@tonic-gate command: list_command 2587c478bd9Sstevel@tonic-gate | edit_command 2597c478bd9Sstevel@tonic-gate { 2607c478bd9Sstevel@tonic-gate if (conf_edit_error != POE_OK) { 2617c478bd9Sstevel@tonic-gate if ($1->cmd != parser_conf_create && 2627c478bd9Sstevel@tonic-gate $1->cmd != parser_conf_discover) { 2637c478bd9Sstevel@tonic-gate die(gettext(ERR_CONF_LOAD), conf_file, 2647c478bd9Sstevel@tonic-gate get_errstr_err(conf_edit_error, 2657c478bd9Sstevel@tonic-gate conf_edit_errno)); 2667c478bd9Sstevel@tonic-gate } 2677c478bd9Sstevel@tonic-gate } 2687c478bd9Sstevel@tonic-gate edited = PO_TRUE; 2697c478bd9Sstevel@tonic-gate }; 2707c478bd9Sstevel@tonic-gate 2717c478bd9Sstevel@tonic-gate list_command: info_command 2727c478bd9Sstevel@tonic-gate { 2737c478bd9Sstevel@tonic-gate if (conf_list_error != POE_OK) { 2747c478bd9Sstevel@tonic-gate if ($1->cmd != parser_conf_create && 2757c478bd9Sstevel@tonic-gate $1->cmd != parser_conf_discover) { 2767c478bd9Sstevel@tonic-gate die(gettext(ERR_CONF_LOAD), conf_file, 2777c478bd9Sstevel@tonic-gate get_errstr_err(conf_list_error, 2787c478bd9Sstevel@tonic-gate conf_list_errno)); 2797c478bd9Sstevel@tonic-gate } 2807c478bd9Sstevel@tonic-gate } 2817c478bd9Sstevel@tonic-gate } 2827c478bd9Sstevel@tonic-gate | discover_command {conf_list_error = conf_edit_error = POE_OK;}; 2837c478bd9Sstevel@tonic-gate 2847c478bd9Sstevel@tonic-gate edit_command: create_command 2857c478bd9Sstevel@tonic-gate | destroy_command 2867c478bd9Sstevel@tonic-gate | modify_command 2877c478bd9Sstevel@tonic-gate | associate_command 2887c478bd9Sstevel@tonic-gate | transfer_command 2897c478bd9Sstevel@tonic-gate | rename_command; 2907c478bd9Sstevel@tonic-gate 2917c478bd9Sstevel@tonic-gate info_command: PCC_INFO 2927c478bd9Sstevel@tonic-gate { 2937c478bd9Sstevel@tonic-gate if (($$ = alloc_cmd()) == NULL) 2947c478bd9Sstevel@tonic-gate YYERROR; 2957c478bd9Sstevel@tonic-gate cmd = $$; 2967c478bd9Sstevel@tonic-gate $$->cmd = &parser_conf_info; 2977c478bd9Sstevel@tonic-gate } 2987c478bd9Sstevel@tonic-gate | PCC_INFO info_entity name 2997c478bd9Sstevel@tonic-gate { 3007c478bd9Sstevel@tonic-gate if (($$ = alloc_cmd()) == NULL) 3017c478bd9Sstevel@tonic-gate YYERROR; 3027c478bd9Sstevel@tonic-gate cmd = $$; 3037c478bd9Sstevel@tonic-gate switch ($2) { 3047c478bd9Sstevel@tonic-gate case PCE_SYSTEM: 3057c478bd9Sstevel@tonic-gate $$->cmd = &parser_conf_info; 3067c478bd9Sstevel@tonic-gate break; 3077c478bd9Sstevel@tonic-gate case PCE_POOL: 3087c478bd9Sstevel@tonic-gate $$->cmd = &parser_pool_info; 3097c478bd9Sstevel@tonic-gate break; 3107c478bd9Sstevel@tonic-gate case PCE_PSET: 3117c478bd9Sstevel@tonic-gate $$->cmd = &parser_pset_info; 3127c478bd9Sstevel@tonic-gate break; 3137c478bd9Sstevel@tonic-gate case PCE_CPU: 3147c478bd9Sstevel@tonic-gate $$->cmd = &parser_cpu_info; 3157c478bd9Sstevel@tonic-gate break; 3167c478bd9Sstevel@tonic-gate default: 3177c478bd9Sstevel@tonic-gate warn(gettext(ERR_UNKNOWN_ENTITY), $2); 3187c478bd9Sstevel@tonic-gate YYERROR; 3197c478bd9Sstevel@tonic-gate } 3207c478bd9Sstevel@tonic-gate $$->cmd_tgt1 = $3; 3217c478bd9Sstevel@tonic-gate }; 3227c478bd9Sstevel@tonic-gate 3237c478bd9Sstevel@tonic-gate create_command: PCC_CREATE entity name 3247c478bd9Sstevel@tonic-gate { 3257c478bd9Sstevel@tonic-gate if (($$ = alloc_cmd()) == NULL) 3267c478bd9Sstevel@tonic-gate YYERROR; 3277c478bd9Sstevel@tonic-gate cmd = $$; 3287c478bd9Sstevel@tonic-gate switch ($2) { 3297c478bd9Sstevel@tonic-gate case PCE_SYSTEM: 3307c478bd9Sstevel@tonic-gate $$->cmd = &parser_conf_create; 331*26d8ba22Sgarypen /* 332*26d8ba22Sgarypen * When creating a new system element, ensure 333*26d8ba22Sgarypen * pre-existing errors are ignored. 334*26d8ba22Sgarypen */ 335*26d8ba22Sgarypen conf_list_error = conf_edit_error = POE_OK; 3367c478bd9Sstevel@tonic-gate break; 3377c478bd9Sstevel@tonic-gate case PCE_POOL: 3387c478bd9Sstevel@tonic-gate $$->cmd = &parser_pool_create; 3397c478bd9Sstevel@tonic-gate break; 3407c478bd9Sstevel@tonic-gate case PCE_PSET: 3417c478bd9Sstevel@tonic-gate $$->cmd = &parser_pset_create; 3427c478bd9Sstevel@tonic-gate break; 3437c478bd9Sstevel@tonic-gate default: 3447c478bd9Sstevel@tonic-gate warn(gettext(ERR_UNKNOWN_ENTITY), $2); 3457c478bd9Sstevel@tonic-gate YYERROR; 3467c478bd9Sstevel@tonic-gate } 3477c478bd9Sstevel@tonic-gate $$->cmd_tgt1 = $3; 3487c478bd9Sstevel@tonic-gate } 3497c478bd9Sstevel@tonic-gate | create_command property_list; 3507c478bd9Sstevel@tonic-gate 3517c478bd9Sstevel@tonic-gate destroy_command: PCC_DESTROY entity name 3527c478bd9Sstevel@tonic-gate { 3537c478bd9Sstevel@tonic-gate if (($$ = alloc_cmd()) == NULL) 3547c478bd9Sstevel@tonic-gate YYERROR; 3557c478bd9Sstevel@tonic-gate cmd = $$; 3567c478bd9Sstevel@tonic-gate switch ($2) { 3577c478bd9Sstevel@tonic-gate case PCE_SYSTEM: 3587c478bd9Sstevel@tonic-gate $$->cmd = &parser_conf_destroy; 3597c478bd9Sstevel@tonic-gate break; 3607c478bd9Sstevel@tonic-gate case PCE_POOL: 3617c478bd9Sstevel@tonic-gate $$->cmd = &parser_pool_destroy; 3627c478bd9Sstevel@tonic-gate break; 3637c478bd9Sstevel@tonic-gate case PCE_PSET: 3647c478bd9Sstevel@tonic-gate $$->cmd = &parser_pset_destroy; 3657c478bd9Sstevel@tonic-gate break; 3667c478bd9Sstevel@tonic-gate default: 3677c478bd9Sstevel@tonic-gate warn(gettext(ERR_UNKNOWN_ENTITY), $2); 3687c478bd9Sstevel@tonic-gate YYERROR; 3697c478bd9Sstevel@tonic-gate } 3707c478bd9Sstevel@tonic-gate $$->cmd_tgt1 = $3; 3717c478bd9Sstevel@tonic-gate }; 3727c478bd9Sstevel@tonic-gate 3737c478bd9Sstevel@tonic-gate modify_command: PCC_MODIFY modify_entity name 3747c478bd9Sstevel@tonic-gate { 3757c478bd9Sstevel@tonic-gate if (($$ = alloc_cmd()) == NULL) 3767c478bd9Sstevel@tonic-gate YYERROR; 3777c478bd9Sstevel@tonic-gate cmd = $$; 3787c478bd9Sstevel@tonic-gate switch ($2) { 3797c478bd9Sstevel@tonic-gate case PCE_SYSTEM: 3807c478bd9Sstevel@tonic-gate $$->cmd = &parser_conf_modify; 3817c478bd9Sstevel@tonic-gate break; 3827c478bd9Sstevel@tonic-gate case PCE_POOL: 3837c478bd9Sstevel@tonic-gate $$->cmd = &parser_pool_modify; 3847c478bd9Sstevel@tonic-gate break; 3857c478bd9Sstevel@tonic-gate case PCE_PSET: 3867c478bd9Sstevel@tonic-gate $$->cmd = &parser_pset_modify; 3877c478bd9Sstevel@tonic-gate break; 3887c478bd9Sstevel@tonic-gate case PCE_CPU: 3897c478bd9Sstevel@tonic-gate $$->cmd = &parser_cpu_modify; 3907c478bd9Sstevel@tonic-gate break; 3917c478bd9Sstevel@tonic-gate default: 3927c478bd9Sstevel@tonic-gate warn(gettext(ERR_UNKNOWN_ENTITY), $2); 3937c478bd9Sstevel@tonic-gate YYERROR; 3947c478bd9Sstevel@tonic-gate } 3957c478bd9Sstevel@tonic-gate $$->cmd_tgt1 = $3; 3967c478bd9Sstevel@tonic-gate } 3977c478bd9Sstevel@tonic-gate | modify_command property_list; 3987c478bd9Sstevel@tonic-gate 3997c478bd9Sstevel@tonic-gate associate_command: PCC_ASSOC PCE_POOL name 4007c478bd9Sstevel@tonic-gate { 4017c478bd9Sstevel@tonic-gate if (($$ = alloc_cmd()) == NULL) 4027c478bd9Sstevel@tonic-gate YYERROR; 4037c478bd9Sstevel@tonic-gate cmd = $$; 4047c478bd9Sstevel@tonic-gate $$->cmd = &parser_pool_associate; 4057c478bd9Sstevel@tonic-gate cmd->cmd_tgt1 = $3; 4067c478bd9Sstevel@tonic-gate } 4077c478bd9Sstevel@tonic-gate | associate_command resource_list; 4087c478bd9Sstevel@tonic-gate 4097c478bd9Sstevel@tonic-gate transfer_command: transfer_qty 4107c478bd9Sstevel@tonic-gate | transfer_components; 4117c478bd9Sstevel@tonic-gate 4127c478bd9Sstevel@tonic-gate transfer_components: PCC_TRANSFER PCK_TO PCE_PSET name 4137c478bd9Sstevel@tonic-gate { 4147c478bd9Sstevel@tonic-gate if (($$ = alloc_cmd()) == NULL) 4157c478bd9Sstevel@tonic-gate YYERROR; 4167c478bd9Sstevel@tonic-gate cmd = $$; 4177c478bd9Sstevel@tonic-gate $$->cmd = &parser_resource_xtransfer; 4187c478bd9Sstevel@tonic-gate cmd->cmd_tgt1 = $4; 4197c478bd9Sstevel@tonic-gate } 4207c478bd9Sstevel@tonic-gate | transfer_components component_list; 4217c478bd9Sstevel@tonic-gate 4227c478bd9Sstevel@tonic-gate transfer_qty: PCC_TRANSFER PCV_VAL_UINT PCK_FROM PCE_PSET src PCK_TO tgt 4237c478bd9Sstevel@tonic-gate { 4247c478bd9Sstevel@tonic-gate if (($$ = alloc_cmd()) == NULL) 4257c478bd9Sstevel@tonic-gate YYERROR; 4267c478bd9Sstevel@tonic-gate cmd = $$; 4277c478bd9Sstevel@tonic-gate $$->cmd = &parser_resource_transfer; 4287c478bd9Sstevel@tonic-gate cmd->cmd_tgt1 = $5; 4297c478bd9Sstevel@tonic-gate cmd->cmd_tgt2 = $7; 4307c478bd9Sstevel@tonic-gate cmd->cmd_qty = $2; 4317c478bd9Sstevel@tonic-gate } 4327c478bd9Sstevel@tonic-gate | PCC_TRANSFER PCV_VAL_UINT PCK_TO PCE_PSET tgt PCK_FROM src 4337c478bd9Sstevel@tonic-gate { 4347c478bd9Sstevel@tonic-gate if (($$ = alloc_cmd()) == NULL) 4357c478bd9Sstevel@tonic-gate YYERROR; 4367c478bd9Sstevel@tonic-gate cmd = $$; 4377c478bd9Sstevel@tonic-gate $$->cmd = &parser_resource_transfer; 4387c478bd9Sstevel@tonic-gate cmd->cmd_tgt1 = $7; 4397c478bd9Sstevel@tonic-gate cmd->cmd_tgt2 = $5; 4407c478bd9Sstevel@tonic-gate cmd->cmd_qty = $2; 4417c478bd9Sstevel@tonic-gate }; 4427c478bd9Sstevel@tonic-gate 4437c478bd9Sstevel@tonic-gate discover_command: PCC_DISC 4447c478bd9Sstevel@tonic-gate { 4457c478bd9Sstevel@tonic-gate if (($$ = alloc_cmd()) == NULL) 4467c478bd9Sstevel@tonic-gate YYERROR; 4477c478bd9Sstevel@tonic-gate cmd = $$; 4487c478bd9Sstevel@tonic-gate $$->cmd = &parser_conf_discover; 4497c478bd9Sstevel@tonic-gate }; 4507c478bd9Sstevel@tonic-gate 4517c478bd9Sstevel@tonic-gate rename_command: PCC_RENAME entity name PCK_TO name 4527c478bd9Sstevel@tonic-gate { 4537c478bd9Sstevel@tonic-gate if (($$ = alloc_cmd()) == NULL) 4547c478bd9Sstevel@tonic-gate YYERROR; 4557c478bd9Sstevel@tonic-gate cmd = $$; 4567c478bd9Sstevel@tonic-gate switch ($2) { 4577c478bd9Sstevel@tonic-gate case PCE_SYSTEM: 4587c478bd9Sstevel@tonic-gate $$->cmd = &parser_conf_rename; 4597c478bd9Sstevel@tonic-gate break; 4607c478bd9Sstevel@tonic-gate case PCE_POOL: 4617c478bd9Sstevel@tonic-gate $$->cmd = &parser_pool_rename; 4627c478bd9Sstevel@tonic-gate break; 4637c478bd9Sstevel@tonic-gate case PCE_PSET: 4647c478bd9Sstevel@tonic-gate $$->cmd = &parser_pset_rename; 4657c478bd9Sstevel@tonic-gate break; 4667c478bd9Sstevel@tonic-gate default: 4677c478bd9Sstevel@tonic-gate warn(gettext(ERR_UNKNOWN_ENTITY), $2); 4687c478bd9Sstevel@tonic-gate YYERROR; 4697c478bd9Sstevel@tonic-gate } 4707c478bd9Sstevel@tonic-gate $$->cmd_tgt1 = $3; 4717c478bd9Sstevel@tonic-gate $$->cmd_tgt2 = $5; 4727c478bd9Sstevel@tonic-gate }; 4737c478bd9Sstevel@tonic-gate 4747c478bd9Sstevel@tonic-gate modify_entity: entity 4757c478bd9Sstevel@tonic-gate | PCE_CPU {$$ = PCE_CPU;}; 4767c478bd9Sstevel@tonic-gate 4777c478bd9Sstevel@tonic-gate info_entity: entity 4787c478bd9Sstevel@tonic-gate | PCE_CPU {$$ = PCE_CPU;}; 4797c478bd9Sstevel@tonic-gate 4807c478bd9Sstevel@tonic-gate entity: PCE_SYSTEM {$$ = PCE_SYSTEM;} 4817c478bd9Sstevel@tonic-gate | PCE_POOL {$$ = PCE_POOL;} 4827c478bd9Sstevel@tonic-gate | PCE_PSET {$$ = PCE_PSET;}; 4837c478bd9Sstevel@tonic-gate 4847c478bd9Sstevel@tonic-gate name: PCV_SYMBOL; 4857c478bd9Sstevel@tonic-gate 4867c478bd9Sstevel@tonic-gate src: PCV_SYMBOL; 4877c478bd9Sstevel@tonic-gate 4887c478bd9Sstevel@tonic-gate tgt: PCV_SYMBOL; 4897c478bd9Sstevel@tonic-gate 4907c478bd9Sstevel@tonic-gate value: PCV_VAL_INT { $$.i = $1;} 4917c478bd9Sstevel@tonic-gate | PCV_VAL_UINT { $$.u = $1;} 4927c478bd9Sstevel@tonic-gate | PCV_VAL_FLOAT { $$.d = $1;} 4937c478bd9Sstevel@tonic-gate | PCV_VAL_BOOLEAN { $$.b = $1;} 4947c478bd9Sstevel@tonic-gate | PCV_VAL_STRING { $$.s = $1;}; 4957c478bd9Sstevel@tonic-gate 4967c478bd9Sstevel@tonic-gate prop_remove: PCK_UNDEF proptype name 4977c478bd9Sstevel@tonic-gate { 4987c478bd9Sstevel@tonic-gate if (($$ = alloc_prop(po_remove)) == NULL) 4997c478bd9Sstevel@tonic-gate YYERROR; 5007c478bd9Sstevel@tonic-gate $$->prop_name = $3; 5017c478bd9Sstevel@tonic-gate }; 5027c478bd9Sstevel@tonic-gate 5037c478bd9Sstevel@tonic-gate prop_op: prop_assign 5047c478bd9Sstevel@tonic-gate | prop_remove; 5057c478bd9Sstevel@tonic-gate 5067c478bd9Sstevel@tonic-gate prop_ops: prop_op 5077c478bd9Sstevel@tonic-gate { 5087c478bd9Sstevel@tonic-gate prop_t *prop = NULL; 5097c478bd9Sstevel@tonic-gate prop_t *prev = NULL; 5107c478bd9Sstevel@tonic-gate 5117c478bd9Sstevel@tonic-gate for (prop = cmd->cmd_prop_list; prop != NULL; 5127c478bd9Sstevel@tonic-gate prop = prop->prop_next) 5137c478bd9Sstevel@tonic-gate prev = prop; /* Find end of list */ 5147c478bd9Sstevel@tonic-gate if (prev != NULL) 5157c478bd9Sstevel@tonic-gate prev->prop_next = $1; 5167c478bd9Sstevel@tonic-gate else 5177c478bd9Sstevel@tonic-gate cmd->cmd_prop_list = $1; 5187c478bd9Sstevel@tonic-gate $$ = cmd->cmd_prop_list; 5197c478bd9Sstevel@tonic-gate } 5207c478bd9Sstevel@tonic-gate | prop_ops PCK_SEPLST prop_op 5217c478bd9Sstevel@tonic-gate { 5227c478bd9Sstevel@tonic-gate prop_t *prop = NULL; 5237c478bd9Sstevel@tonic-gate prop_t *prev = NULL; 5247c478bd9Sstevel@tonic-gate 5257c478bd9Sstevel@tonic-gate for (prop = cmd->cmd_prop_list; prop != NULL; 5267c478bd9Sstevel@tonic-gate prop = prop->prop_next) 5277c478bd9Sstevel@tonic-gate prev = prop; /* Find end of list */ 5287c478bd9Sstevel@tonic-gate if (prev != NULL) 5297c478bd9Sstevel@tonic-gate prev->prop_next = $3; 5307c478bd9Sstevel@tonic-gate else 5317c478bd9Sstevel@tonic-gate cmd->cmd_prop_list = $3; 5327c478bd9Sstevel@tonic-gate $$ = cmd->cmd_prop_list; 5337c478bd9Sstevel@tonic-gate 5347c478bd9Sstevel@tonic-gate }; 5357c478bd9Sstevel@tonic-gate 5367c478bd9Sstevel@tonic-gate prop_assign: proptype name PCK_ASSIGN value 5377c478bd9Sstevel@tonic-gate { 5387c478bd9Sstevel@tonic-gate if (($$ = alloc_prop(po_create)) == NULL) 5397c478bd9Sstevel@tonic-gate YYERROR; 5407c478bd9Sstevel@tonic-gate $$->prop_name = $2; 5417c478bd9Sstevel@tonic-gate switch ($1) { 5427c478bd9Sstevel@tonic-gate case PCT_INT: 5437c478bd9Sstevel@tonic-gate pool_value_set_int64($$->prop_value, $4.i); 5447c478bd9Sstevel@tonic-gate break; 5457c478bd9Sstevel@tonic-gate case PCT_UINT: 5467c478bd9Sstevel@tonic-gate pool_value_set_uint64($$->prop_value, $4.u); 5477c478bd9Sstevel@tonic-gate break; 5487c478bd9Sstevel@tonic-gate case PCT_BOOLEAN: 5497c478bd9Sstevel@tonic-gate pool_value_set_bool($$->prop_value, $4.b); 5507c478bd9Sstevel@tonic-gate break; 5517c478bd9Sstevel@tonic-gate case PCT_FLOAT: 5527c478bd9Sstevel@tonic-gate pool_value_set_double($$->prop_value, $4.d); 5537c478bd9Sstevel@tonic-gate break; 5547c478bd9Sstevel@tonic-gate case PCT_STRING: 5557c478bd9Sstevel@tonic-gate pool_value_set_string($$->prop_value, $4.s); 5567c478bd9Sstevel@tonic-gate break; 5577c478bd9Sstevel@tonic-gate } 5587c478bd9Sstevel@tonic-gate }; 5597c478bd9Sstevel@tonic-gate 5607c478bd9Sstevel@tonic-gate property_list: PCK_OPENLST prop_ops PCK_CLOSELST 5617c478bd9Sstevel@tonic-gate { 5627c478bd9Sstevel@tonic-gate $$ = $2; 5637c478bd9Sstevel@tonic-gate }; 5647c478bd9Sstevel@tonic-gate 5657c478bd9Sstevel@tonic-gate resource_assigns: resource_assign 5667c478bd9Sstevel@tonic-gate { 5677c478bd9Sstevel@tonic-gate assoc_t *assoc = NULL; 5687c478bd9Sstevel@tonic-gate assoc_t *prev = NULL; 5697c478bd9Sstevel@tonic-gate 5707c478bd9Sstevel@tonic-gate for (assoc = cmd->cmd_assoc_list; assoc != NULL; 5717c478bd9Sstevel@tonic-gate assoc = assoc->assoc_next) 5727c478bd9Sstevel@tonic-gate prev = assoc; /* Find end of list */ 5737c478bd9Sstevel@tonic-gate if (prev != NULL) 5747c478bd9Sstevel@tonic-gate prev->assoc_next = $1; 5757c478bd9Sstevel@tonic-gate else 5767c478bd9Sstevel@tonic-gate cmd->cmd_assoc_list = $1; 5777c478bd9Sstevel@tonic-gate $$ = cmd->cmd_assoc_list; 5787c478bd9Sstevel@tonic-gate } 5797c478bd9Sstevel@tonic-gate 5807c478bd9Sstevel@tonic-gate | resource_assigns PCK_SEPLST resource_assign 5817c478bd9Sstevel@tonic-gate { 5827c478bd9Sstevel@tonic-gate assoc_t *assoc = NULL; 5837c478bd9Sstevel@tonic-gate assoc_t *prev = NULL; 5847c478bd9Sstevel@tonic-gate 5857c478bd9Sstevel@tonic-gate for (assoc = cmd->cmd_assoc_list; assoc != NULL; 5867c478bd9Sstevel@tonic-gate assoc = assoc->assoc_next) 5877c478bd9Sstevel@tonic-gate prev = assoc; /* Find end of list */ 5887c478bd9Sstevel@tonic-gate if (prev != NULL) 5897c478bd9Sstevel@tonic-gate prev->assoc_next = $3; 5907c478bd9Sstevel@tonic-gate $$ = $3; 5917c478bd9Sstevel@tonic-gate }; 5927c478bd9Sstevel@tonic-gate 5937c478bd9Sstevel@tonic-gate resource_assign: resource name 5947c478bd9Sstevel@tonic-gate { 5957c478bd9Sstevel@tonic-gate if (($$ = alloc_assoc($1, $2)) == NULL) 5967c478bd9Sstevel@tonic-gate YYERROR; 5977c478bd9Sstevel@tonic-gate }; 5987c478bd9Sstevel@tonic-gate 5997c478bd9Sstevel@tonic-gate resource: PCE_PSET {$$ = PCE_PSET;}; 6007c478bd9Sstevel@tonic-gate 6017c478bd9Sstevel@tonic-gate resource_list: PCK_OPENLST resource_assigns PCK_CLOSELST 6027c478bd9Sstevel@tonic-gate { 6037c478bd9Sstevel@tonic-gate $$ = $2; 6047c478bd9Sstevel@tonic-gate }; 6057c478bd9Sstevel@tonic-gate 6067c478bd9Sstevel@tonic-gate component_assigns: component_assign 6077c478bd9Sstevel@tonic-gate { 6087c478bd9Sstevel@tonic-gate assoc_t *assoc = NULL; 6097c478bd9Sstevel@tonic-gate assoc_t *prev = NULL; 6107c478bd9Sstevel@tonic-gate 6117c478bd9Sstevel@tonic-gate for (assoc = cmd->cmd_assoc_list; assoc != NULL; 6127c478bd9Sstevel@tonic-gate assoc = assoc->assoc_next) 6137c478bd9Sstevel@tonic-gate prev = assoc; /* Find end of list */ 6147c478bd9Sstevel@tonic-gate if (prev != NULL) 6157c478bd9Sstevel@tonic-gate prev->assoc_next = $1; 6167c478bd9Sstevel@tonic-gate else 6177c478bd9Sstevel@tonic-gate cmd->cmd_assoc_list = $1; 6187c478bd9Sstevel@tonic-gate $$ = cmd->cmd_assoc_list; 6197c478bd9Sstevel@tonic-gate } 6207c478bd9Sstevel@tonic-gate 6217c478bd9Sstevel@tonic-gate | component_assigns PCK_SEPLST component_assign 6227c478bd9Sstevel@tonic-gate { 6237c478bd9Sstevel@tonic-gate assoc_t *assoc = NULL; 6247c478bd9Sstevel@tonic-gate assoc_t *prev = NULL; 6257c478bd9Sstevel@tonic-gate 6267c478bd9Sstevel@tonic-gate for (assoc = cmd->cmd_assoc_list; assoc != NULL; 6277c478bd9Sstevel@tonic-gate assoc = assoc->assoc_next) 6287c478bd9Sstevel@tonic-gate prev = assoc; /* Find end of list */ 6297c478bd9Sstevel@tonic-gate if (prev != NULL) 6307c478bd9Sstevel@tonic-gate prev->assoc_next = $3; 6317c478bd9Sstevel@tonic-gate $$ = $3; 6327c478bd9Sstevel@tonic-gate }; 6337c478bd9Sstevel@tonic-gate 6347c478bd9Sstevel@tonic-gate component_list: PCK_OPENLST component_assigns PCK_CLOSELST 6357c478bd9Sstevel@tonic-gate { 6367c478bd9Sstevel@tonic-gate $$ = $2; 6377c478bd9Sstevel@tonic-gate }; 6387c478bd9Sstevel@tonic-gate 6397c478bd9Sstevel@tonic-gate component_assign: component name 6407c478bd9Sstevel@tonic-gate { 6417c478bd9Sstevel@tonic-gate if (($$ = alloc_assoc($1, $2)) == NULL) 6427c478bd9Sstevel@tonic-gate YYERROR; 6437c478bd9Sstevel@tonic-gate }; 6447c478bd9Sstevel@tonic-gate 6457c478bd9Sstevel@tonic-gate component: PCE_CPU {$$ = PCE_CPU;}; 6467c478bd9Sstevel@tonic-gate 6477c478bd9Sstevel@tonic-gate proptype: PCT_INT {$$ = PCT_INT;} 6487c478bd9Sstevel@tonic-gate | PCT_UINT {$$ = PCT_UINT;} 6497c478bd9Sstevel@tonic-gate | PCT_BOOLEAN {$$ = PCT_BOOLEAN;} 6507c478bd9Sstevel@tonic-gate | PCT_FLOAT {$$ = PCT_FLOAT;} 6517c478bd9Sstevel@tonic-gate | PCT_STRING {$$ = PCT_STRING;}; 6527c478bd9Sstevel@tonic-gate 6537c478bd9Sstevel@tonic-gate %% 6547c478bd9Sstevel@tonic-gate 6557c478bd9Sstevel@tonic-gate #ifndef TEXT_DOMAIN 6567c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" 6577c478bd9Sstevel@tonic-gate #endif 6587c478bd9Sstevel@tonic-gate 6597c478bd9Sstevel@tonic-gate int 6607c478bd9Sstevel@tonic-gate main(int argc, char *argv[]) 6617c478bd9Sstevel@tonic-gate { 6627c478bd9Sstevel@tonic-gate int opt; 6637c478bd9Sstevel@tonic-gate int docmd = PO_FALSE; 6647c478bd9Sstevel@tonic-gate 6657c478bd9Sstevel@tonic-gate (void) getpname(argv[0]); 6667c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 6677c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 6687c478bd9Sstevel@tonic-gate if (atexit(terminate) != 0) { 6697c478bd9Sstevel@tonic-gate die(gettext(ERR_SET_TERM), get_errstr()); 6707c478bd9Sstevel@tonic-gate } 6717c478bd9Sstevel@tonic-gate 6727c478bd9Sstevel@tonic-gate conf_file = pool_static_location(); 6737c478bd9Sstevel@tonic-gate 6747c478bd9Sstevel@tonic-gate yydebug = 0; 6757c478bd9Sstevel@tonic-gate while ((opt = getopt(argc, argv, cmd_options)) != (int)EOF) { 6767c478bd9Sstevel@tonic-gate 6777c478bd9Sstevel@tonic-gate switch (opt) { 6787c478bd9Sstevel@tonic-gate case 'c': /* Process command line */ 6797c478bd9Sstevel@tonic-gate if (dofile == PO_TRUE) 6807c478bd9Sstevel@tonic-gate usage(1); 6817c478bd9Sstevel@tonic-gate arg_parse(optarg); 6827c478bd9Sstevel@tonic-gate docmd = PO_TRUE; 6837c478bd9Sstevel@tonic-gate break; 6847c478bd9Sstevel@tonic-gate case 'd': /* Manipulate dynamic configuration */ 6857c478bd9Sstevel@tonic-gate conf_file = pool_dynamic_location(); 6867c478bd9Sstevel@tonic-gate break; 6877c478bd9Sstevel@tonic-gate case 'f': /* Process command file */ 6887c478bd9Sstevel@tonic-gate if (docmd == PO_TRUE) 6897c478bd9Sstevel@tonic-gate usage(1); 6907c478bd9Sstevel@tonic-gate file_parse(optarg); 6917c478bd9Sstevel@tonic-gate dofile = PO_TRUE; 6927c478bd9Sstevel@tonic-gate break; 6937c478bd9Sstevel@tonic-gate case 'h': 6947c478bd9Sstevel@tonic-gate usage(2); 6957c478bd9Sstevel@tonic-gate break; 6967c478bd9Sstevel@tonic-gate case '?': 6977c478bd9Sstevel@tonic-gate default: 6987c478bd9Sstevel@tonic-gate usage(1); 6997c478bd9Sstevel@tonic-gate break; 7007c478bd9Sstevel@tonic-gate } 7017c478bd9Sstevel@tonic-gate } 7027c478bd9Sstevel@tonic-gate if (docmd == PO_FALSE && dofile == PO_FALSE) 7037c478bd9Sstevel@tonic-gate usage(1); 7047c478bd9Sstevel@tonic-gate 7057c478bd9Sstevel@tonic-gate if (optind == argc - 1) { 7067c478bd9Sstevel@tonic-gate if (strcmp(conf_file, pool_dynamic_location()) == 0) 7077c478bd9Sstevel@tonic-gate usage(1); 7087c478bd9Sstevel@tonic-gate conf_file = argv[optind]; 7097c478bd9Sstevel@tonic-gate } else if (optind < argc - 1) 7107c478bd9Sstevel@tonic-gate usage(1); 7117c478bd9Sstevel@tonic-gate 7127c478bd9Sstevel@tonic-gate if ((conf = pool_conf_alloc()) == NULL) { 7137c478bd9Sstevel@tonic-gate die(gettext(ERR_ALLOC_ELEMENT), gettext(CONFIGURATION), 7147c478bd9Sstevel@tonic-gate get_errstr()); 7157c478bd9Sstevel@tonic-gate } 7167c478bd9Sstevel@tonic-gate /* 7177c478bd9Sstevel@tonic-gate * Opening a conf is complex, since we may be opening one of the 7187c478bd9Sstevel@tonic-gate * following: 7197c478bd9Sstevel@tonic-gate * - An existing configuration that we can modify 7207c478bd9Sstevel@tonic-gate * - An existing configuration that we can't modify 7217c478bd9Sstevel@tonic-gate * - A new configuration that we can modify 7227c478bd9Sstevel@tonic-gate * - A new configuration that we can't modify 7237c478bd9Sstevel@tonic-gate * The parser_conf_discover() function closes the file and reopens 7247c478bd9Sstevel@tonic-gate * in PO_CREAT mode, so we only need be concerned here with the 7257c478bd9Sstevel@tonic-gate * first two cases. 7267c478bd9Sstevel@tonic-gate * Always try to open RDWR, if fail try RDONLY. Don't check 7277c478bd9Sstevel@tonic-gate * if that fails, since we may be trying to discover a configuration 7287c478bd9Sstevel@tonic-gate * in which case it's valid for both open attempts to fail. Later, when 7297c478bd9Sstevel@tonic-gate * processing commands, if we don't have a valid configuration and 7307c478bd9Sstevel@tonic-gate * we are trying to process a command which isn't a create or a discover 7317c478bd9Sstevel@tonic-gate * we will fail the command as there is no valid configuration to 7327c478bd9Sstevel@tonic-gate * work with. 7337c478bd9Sstevel@tonic-gate */ 7347c478bd9Sstevel@tonic-gate if (pool_conf_open(conf, conf_file, PO_RDWR) != 0) { 7357c478bd9Sstevel@tonic-gate conf_edit_error = pool_error(); 7367c478bd9Sstevel@tonic-gate conf_edit_errno = errno; 7377c478bd9Sstevel@tonic-gate if (pool_conf_open(conf, conf_file, PO_RDONLY) != 0) { 7387c478bd9Sstevel@tonic-gate conf_list_error = pool_error(); 7397c478bd9Sstevel@tonic-gate conf_list_errno = errno; 7407c478bd9Sstevel@tonic-gate } 7417c478bd9Sstevel@tonic-gate } 7427c478bd9Sstevel@tonic-gate 7437c478bd9Sstevel@tonic-gate if (yyparse() == 0) { 7447c478bd9Sstevel@tonic-gate if (pool_conf_status(conf) >= POF_VALID) { 7457c478bd9Sstevel@tonic-gate if (pool_conf_validate(conf, POV_STRICT) == PO_FAIL) { 7467c478bd9Sstevel@tonic-gate die(gettext(ERR_VALIDATION_FAILED), 7477c478bd9Sstevel@tonic-gate get_errstr()); 7487c478bd9Sstevel@tonic-gate } 7497c478bd9Sstevel@tonic-gate /* 7507c478bd9Sstevel@tonic-gate * If the user attempted to change the configuration, 7517c478bd9Sstevel@tonic-gate * then we should try to save the changes. 7527c478bd9Sstevel@tonic-gate */ 7537c478bd9Sstevel@tonic-gate if (edited == PO_TRUE) { 7547c478bd9Sstevel@tonic-gate if (pool_conf_commit(conf, 0) == PO_FAIL) { 7557c478bd9Sstevel@tonic-gate die(gettext(ERR_CONFIG_SAVE_FAILED), 7567c478bd9Sstevel@tonic-gate get_errstr()); 7577c478bd9Sstevel@tonic-gate } 7587c478bd9Sstevel@tonic-gate } 7597c478bd9Sstevel@tonic-gate pool_conf_close(conf); 7607c478bd9Sstevel@tonic-gate } 7617c478bd9Sstevel@tonic-gate } else { 7627c478bd9Sstevel@tonic-gate die(gettext(ERR_CMDPARSE_FAILED)); 7637c478bd9Sstevel@tonic-gate } 7647c478bd9Sstevel@tonic-gate 7657c478bd9Sstevel@tonic-gate /* 7667c478bd9Sstevel@tonic-gate * Cleanup is performed in terminate(), using atexit 7677c478bd9Sstevel@tonic-gate */ 7687c478bd9Sstevel@tonic-gate return (0); 7697c478bd9Sstevel@tonic-gate } 7707c478bd9Sstevel@tonic-gate 7717c478bd9Sstevel@tonic-gate /* 7727c478bd9Sstevel@tonic-gate * Info Commands 7737c478bd9Sstevel@tonic-gate * Invoke the appropriate libpool info function and display the returned 7747c478bd9Sstevel@tonic-gate * information. 7757c478bd9Sstevel@tonic-gate */ 7767c478bd9Sstevel@tonic-gate static void 7777c478bd9Sstevel@tonic-gate parser_conf_info(cmd_t *cmd) 7787c478bd9Sstevel@tonic-gate { 7797c478bd9Sstevel@tonic-gate char *info_buf; 7807c478bd9Sstevel@tonic-gate const char *tgt = cmd->cmd_tgt1; 7817c478bd9Sstevel@tonic-gate pool_value_t *pv = NULL; 7827c478bd9Sstevel@tonic-gate pool_elem_t *pe; 7837c478bd9Sstevel@tonic-gate 7847c478bd9Sstevel@tonic-gate if ((pe = pool_conf_to_elem(conf)) == NULL) 7857c478bd9Sstevel@tonic-gate die(gettext(ERR_GET_ELEMENT_DETAILS), 7867c478bd9Sstevel@tonic-gate gettext(CONFIGURATION), "unknown", get_errstr()); 7877c478bd9Sstevel@tonic-gate 7887c478bd9Sstevel@tonic-gate if (tgt != NULL) 7897c478bd9Sstevel@tonic-gate check_conf_name(cmd); 7907c478bd9Sstevel@tonic-gate else { 7917c478bd9Sstevel@tonic-gate if ((pv = pool_value_alloc()) == NULL) 7927c478bd9Sstevel@tonic-gate die(gettext(ERR_GET_ELEMENT_DETAILS), 7937c478bd9Sstevel@tonic-gate gettext(CONFIGURATION), "unknown", get_errstr()); 7947c478bd9Sstevel@tonic-gate if (pool_get_property(conf, pe, "system.name", pv) == 7957c478bd9Sstevel@tonic-gate POC_INVAL || 7967c478bd9Sstevel@tonic-gate pool_value_get_string(pv, &tgt) != PO_SUCCESS) 7977c478bd9Sstevel@tonic-gate die(gettext(ERR_GET_ELEMENT_DETAILS), 7987c478bd9Sstevel@tonic-gate gettext(CONFIGURATION), "unknown", get_errstr()); 7997c478bd9Sstevel@tonic-gate } 8007c478bd9Sstevel@tonic-gate if ((info_buf = pool_conf_info(conf, PO_TRUE)) == NULL) { 8017c478bd9Sstevel@tonic-gate die(gettext(ERR_GET_ELEMENT_DETAILS), gettext(CONFIGURATION), 8027c478bd9Sstevel@tonic-gate tgt, get_errstr()); 8037c478bd9Sstevel@tonic-gate } 8047c478bd9Sstevel@tonic-gate if (pv != NULL) { 8057c478bd9Sstevel@tonic-gate pool_value_free(pv); 8067c478bd9Sstevel@tonic-gate } 8077c478bd9Sstevel@tonic-gate (void) printf("%s\n", info_buf); 8087c478bd9Sstevel@tonic-gate free(info_buf); 8097c478bd9Sstevel@tonic-gate } 8107c478bd9Sstevel@tonic-gate 8117c478bd9Sstevel@tonic-gate static void 8127c478bd9Sstevel@tonic-gate parser_pool_info(cmd_t *cmd) 8137c478bd9Sstevel@tonic-gate { 8147c478bd9Sstevel@tonic-gate pool_t *pool; 8157c478bd9Sstevel@tonic-gate char *info_buf; 8167c478bd9Sstevel@tonic-gate 8177c478bd9Sstevel@tonic-gate if ((pool = pool_get_pool(conf, cmd->cmd_tgt1)) == NULL) 8187c478bd9Sstevel@tonic-gate die(gettext(ERR_LOCATE_ELEMENT), gettext(POOL), cmd->cmd_tgt1, 8197c478bd9Sstevel@tonic-gate get_errstr()); 8207c478bd9Sstevel@tonic-gate 8217c478bd9Sstevel@tonic-gate if ((info_buf = pool_info(conf, pool, PO_TRUE)) == NULL) 8227c478bd9Sstevel@tonic-gate die(gettext(ERR_GET_ELEMENT_DETAILS), gettext(POOL), 8237c478bd9Sstevel@tonic-gate cmd->cmd_tgt1, get_errstr()); 8247c478bd9Sstevel@tonic-gate (void) printf("%s\n", info_buf); 8257c478bd9Sstevel@tonic-gate free(info_buf); 8267c478bd9Sstevel@tonic-gate } 8277c478bd9Sstevel@tonic-gate 8287c478bd9Sstevel@tonic-gate static void 8297c478bd9Sstevel@tonic-gate parser_resource_info(cmd_t *cmd, const char *type) 8307c478bd9Sstevel@tonic-gate { 8317c478bd9Sstevel@tonic-gate pool_resource_t *resource; 8327c478bd9Sstevel@tonic-gate char *info_buf; 8337c478bd9Sstevel@tonic-gate 8347c478bd9Sstevel@tonic-gate if ((resource = pool_get_resource(conf, type, cmd->cmd_tgt1)) == NULL) 8357c478bd9Sstevel@tonic-gate die(gettext(ERR_LOCATE_ELEMENT), gettext(RESOURCE), 8367c478bd9Sstevel@tonic-gate cmd->cmd_tgt1, get_errstr()); 8377c478bd9Sstevel@tonic-gate 8387c478bd9Sstevel@tonic-gate if ((info_buf = pool_resource_info(conf, resource, PO_TRUE)) == NULL) 8397c478bd9Sstevel@tonic-gate die(gettext(ERR_GET_ELEMENT_DETAILS), gettext(RESOURCE), 8407c478bd9Sstevel@tonic-gate cmd->cmd_tgt1, get_errstr()); 8417c478bd9Sstevel@tonic-gate (void) printf("%s\n", info_buf); 8427c478bd9Sstevel@tonic-gate free(info_buf); 8437c478bd9Sstevel@tonic-gate } 8447c478bd9Sstevel@tonic-gate 8457c478bd9Sstevel@tonic-gate static void 8467c478bd9Sstevel@tonic-gate parser_pset_info(cmd_t *cmd) 8477c478bd9Sstevel@tonic-gate { 8487c478bd9Sstevel@tonic-gate parser_resource_info(cmd, PSET); 8497c478bd9Sstevel@tonic-gate } 8507c478bd9Sstevel@tonic-gate 8517c478bd9Sstevel@tonic-gate static void 8527c478bd9Sstevel@tonic-gate parser_cpu_info(cmd_t *cmd) 8537c478bd9Sstevel@tonic-gate { 8547c478bd9Sstevel@tonic-gate pool_component_t *comp; 8557c478bd9Sstevel@tonic-gate char *info_buf; 8567c478bd9Sstevel@tonic-gate 8577c478bd9Sstevel@tonic-gate if ((comp = get_cpu(cmd->cmd_tgt1)) == NULL) 8587c478bd9Sstevel@tonic-gate die(gettext(ERR_LOCATE_ELEMENT), gettext(CPU), 8597c478bd9Sstevel@tonic-gate cmd->cmd_tgt1, get_errstr()); 8607c478bd9Sstevel@tonic-gate if ((info_buf = pool_component_info(conf, comp, PO_TRUE)) == NULL) { 8617c478bd9Sstevel@tonic-gate die(gettext(ERR_GET_ELEMENT_DETAILS), gettext(CPU), 8627c478bd9Sstevel@tonic-gate cmd->cmd_tgt1, get_errstr()); 8637c478bd9Sstevel@tonic-gate } 8647c478bd9Sstevel@tonic-gate (void) printf("%s\n", info_buf); 8657c478bd9Sstevel@tonic-gate free(info_buf); 8667c478bd9Sstevel@tonic-gate } 8677c478bd9Sstevel@tonic-gate 8687c478bd9Sstevel@tonic-gate /* 8697c478bd9Sstevel@tonic-gate * Create Commands 8707c478bd9Sstevel@tonic-gate * Invoke the appropriate libpool create function and perform any requested 8717c478bd9Sstevel@tonic-gate * property operations. 8727c478bd9Sstevel@tonic-gate */ 8737c478bd9Sstevel@tonic-gate static void 8747c478bd9Sstevel@tonic-gate parser_conf_create(cmd_t *cmd) 8757c478bd9Sstevel@tonic-gate { 8767c478bd9Sstevel@tonic-gate const char *tmp_name; 8777c478bd9Sstevel@tonic-gate pool_elem_t *pe; 8787c478bd9Sstevel@tonic-gate 8797c478bd9Sstevel@tonic-gate if (conf != NULL && pool_conf_status(conf) >= POF_VALID) 8807c478bd9Sstevel@tonic-gate pool_conf_close(conf); 8817c478bd9Sstevel@tonic-gate if (pool_conf_open(conf, conf_file, PO_CREAT) != 0) { 8827c478bd9Sstevel@tonic-gate die(gettext(ERR_CREATE_ELEMENT), gettext(CONFIGURATION), 8837c478bd9Sstevel@tonic-gate cmd->cmd_tgt1, get_errstr()); 8847c478bd9Sstevel@tonic-gate } 8857c478bd9Sstevel@tonic-gate tmp_name = cmd->cmd_tgt1; 8867c478bd9Sstevel@tonic-gate cmd->cmd_tgt1 = cmd->cmd_tgt2; 8877c478bd9Sstevel@tonic-gate cmd->cmd_tgt2 = tmp_name; 8887c478bd9Sstevel@tonic-gate parser_conf_rename(cmd); 8897c478bd9Sstevel@tonic-gate if ((pe = pool_conf_to_elem(conf)) == NULL) 8907c478bd9Sstevel@tonic-gate die(gettext(ERR_GET_ELEMENT_DETAILS), 8917c478bd9Sstevel@tonic-gate gettext(CONFIGURATION), "unknown", get_errstr()); 8927c478bd9Sstevel@tonic-gate prop_list_walk(cmd, pe); 8937c478bd9Sstevel@tonic-gate } 8947c478bd9Sstevel@tonic-gate 8957c478bd9Sstevel@tonic-gate static void 8967c478bd9Sstevel@tonic-gate parser_pool_create(cmd_t *cmd) 8977c478bd9Sstevel@tonic-gate { 8987c478bd9Sstevel@tonic-gate pool_t *pool; 8997c478bd9Sstevel@tonic-gate 9007c478bd9Sstevel@tonic-gate if ((pool = pool_create(conf, cmd->cmd_tgt1)) == NULL) 9017c478bd9Sstevel@tonic-gate die(gettext(ERR_CREATE_ELEMENT), gettext(POOL), cmd->cmd_tgt1, 9027c478bd9Sstevel@tonic-gate get_errstr()); 9037c478bd9Sstevel@tonic-gate prop_list_walk(cmd, pool_to_elem(conf, pool)); 9047c478bd9Sstevel@tonic-gate } 9057c478bd9Sstevel@tonic-gate 9067c478bd9Sstevel@tonic-gate static void 9077c478bd9Sstevel@tonic-gate parser_resource_create(cmd_t *cmd, const char *type) 9087c478bd9Sstevel@tonic-gate { 9097c478bd9Sstevel@tonic-gate pool_resource_t *resource; 9107c478bd9Sstevel@tonic-gate 9117c478bd9Sstevel@tonic-gate if ((resource = pool_resource_create(conf, type, cmd->cmd_tgt1)) 9127c478bd9Sstevel@tonic-gate == NULL) 9137c478bd9Sstevel@tonic-gate die(gettext(ERR_CREATE_ELEMENT), type, cmd->cmd_tgt1, 9147c478bd9Sstevel@tonic-gate get_errstr()); 9157c478bd9Sstevel@tonic-gate 9167c478bd9Sstevel@tonic-gate process_min_max(resource); 9177c478bd9Sstevel@tonic-gate 9187c478bd9Sstevel@tonic-gate prop_list_walk(cmd, pool_resource_to_elem(conf, resource)); 9197c478bd9Sstevel@tonic-gate } 9207c478bd9Sstevel@tonic-gate 9217c478bd9Sstevel@tonic-gate static void 9227c478bd9Sstevel@tonic-gate parser_pset_create(cmd_t *cmd) 9237c478bd9Sstevel@tonic-gate { 9247c478bd9Sstevel@tonic-gate parser_resource_create(cmd, PSET); 9257c478bd9Sstevel@tonic-gate } 9267c478bd9Sstevel@tonic-gate 9277c478bd9Sstevel@tonic-gate /* 9287c478bd9Sstevel@tonic-gate * Rename Commands 9297c478bd9Sstevel@tonic-gate * Rename the target by calling pool_put_property for the name property. 9307c478bd9Sstevel@tonic-gate */ 9317c478bd9Sstevel@tonic-gate static void 9327c478bd9Sstevel@tonic-gate parser_rename(cmd_t *cmd, pool_elem_t *pe, const char *name) 9337c478bd9Sstevel@tonic-gate { 9347c478bd9Sstevel@tonic-gate pool_value_t *pv; 9357c478bd9Sstevel@tonic-gate 9367c478bd9Sstevel@tonic-gate if ((pv = pool_value_alloc()) == NULL) { 9377c478bd9Sstevel@tonic-gate die(gettext(ERR_ALLOC_ELEMENT), gettext(RESOURCE), 9387c478bd9Sstevel@tonic-gate get_errstr()); 9397c478bd9Sstevel@tonic-gate } 9407c478bd9Sstevel@tonic-gate pool_value_set_string(pv, cmd->cmd_tgt2); 9417c478bd9Sstevel@tonic-gate if (pool_put_property(conf, pe, name, pv) != 0) 9427c478bd9Sstevel@tonic-gate die(gettext(ERR_PUT_PROPERTY), name, get_errstr()); 9437c478bd9Sstevel@tonic-gate pool_value_free(pv); 9447c478bd9Sstevel@tonic-gate } 9457c478bd9Sstevel@tonic-gate 9467c478bd9Sstevel@tonic-gate static void 9477c478bd9Sstevel@tonic-gate parser_conf_rename(cmd_t *cmd) 9487c478bd9Sstevel@tonic-gate { 9497c478bd9Sstevel@tonic-gate pool_elem_t *pe; 9507c478bd9Sstevel@tonic-gate 9517c478bd9Sstevel@tonic-gate if ((pe = pool_conf_to_elem(conf)) == NULL) 9527c478bd9Sstevel@tonic-gate die(gettext(ERR_GET_ELEMENT_DETAILS), 9537c478bd9Sstevel@tonic-gate gettext(CONFIGURATION), "unknown", get_errstr()); 9547c478bd9Sstevel@tonic-gate 9557c478bd9Sstevel@tonic-gate if (cmd->cmd_tgt1 != NULL) 9567c478bd9Sstevel@tonic-gate check_conf_name(cmd); 9577c478bd9Sstevel@tonic-gate 9587c478bd9Sstevel@tonic-gate parser_rename(cmd, pe, SYSTEM_NAME); 9597c478bd9Sstevel@tonic-gate } 9607c478bd9Sstevel@tonic-gate 9617c478bd9Sstevel@tonic-gate static void 9627c478bd9Sstevel@tonic-gate parser_pool_rename(cmd_t *cmd) 9637c478bd9Sstevel@tonic-gate { 9647c478bd9Sstevel@tonic-gate pool_t *pool; 9657c478bd9Sstevel@tonic-gate 9667c478bd9Sstevel@tonic-gate if ((pool = pool_get_pool(conf, cmd->cmd_tgt1)) == NULL) 9677c478bd9Sstevel@tonic-gate die(gettext(ERR_LOCATE_ELEMENT), gettext(POOL), cmd->cmd_tgt1, 9687c478bd9Sstevel@tonic-gate get_errstr()); 9697c478bd9Sstevel@tonic-gate 9707c478bd9Sstevel@tonic-gate parser_rename(cmd, pool_to_elem(conf, pool), POOL_NAME); 9717c478bd9Sstevel@tonic-gate } 9727c478bd9Sstevel@tonic-gate 9737c478bd9Sstevel@tonic-gate static void 9747c478bd9Sstevel@tonic-gate parser_pset_rename(cmd_t *cmd) 9757c478bd9Sstevel@tonic-gate { 9767c478bd9Sstevel@tonic-gate pool_resource_t *resource; 9777c478bd9Sstevel@tonic-gate 9787c478bd9Sstevel@tonic-gate if ((resource = pool_get_resource(conf, PSET, cmd->cmd_tgt1)) == NULL) 9797c478bd9Sstevel@tonic-gate die(gettext(ERR_LOCATE_ELEMENT), gettext(PSET), cmd->cmd_tgt1, 9807c478bd9Sstevel@tonic-gate get_errstr()); 9817c478bd9Sstevel@tonic-gate 9827c478bd9Sstevel@tonic-gate parser_rename(cmd, pool_resource_to_elem(conf, resource), PSET_NAME); 9837c478bd9Sstevel@tonic-gate } 9847c478bd9Sstevel@tonic-gate 9857c478bd9Sstevel@tonic-gate /* 9867c478bd9Sstevel@tonic-gate * Destroy Commands 9877c478bd9Sstevel@tonic-gate * Invoke the appropriate libpool destroy function to remove the target of the 9887c478bd9Sstevel@tonic-gate * command from the configuration. 9897c478bd9Sstevel@tonic-gate */ 9907c478bd9Sstevel@tonic-gate static void 9917c478bd9Sstevel@tonic-gate parser_conf_destroy(cmd_t *cmd) 9927c478bd9Sstevel@tonic-gate { 9937c478bd9Sstevel@tonic-gate if (cmd->cmd_tgt1 != NULL) 9947c478bd9Sstevel@tonic-gate check_conf_name(cmd); 9957c478bd9Sstevel@tonic-gate 9967c478bd9Sstevel@tonic-gate if (pool_conf_remove(conf) != 0) 9977c478bd9Sstevel@tonic-gate die(gettext(ERR_DESTROY_ELEMENT), gettext(CONFIGURATION), 9987c478bd9Sstevel@tonic-gate cmd->cmd_tgt1, get_errstr()); 9997c478bd9Sstevel@tonic-gate } 10007c478bd9Sstevel@tonic-gate 10017c478bd9Sstevel@tonic-gate static void 10027c478bd9Sstevel@tonic-gate parser_pool_destroy(cmd_t *cmd) 10037c478bd9Sstevel@tonic-gate { 10047c478bd9Sstevel@tonic-gate pool_t *pool; 10057c478bd9Sstevel@tonic-gate 10067c478bd9Sstevel@tonic-gate if ((pool = pool_get_pool(conf, cmd->cmd_tgt1)) == NULL) 10077c478bd9Sstevel@tonic-gate die(gettext(ERR_LOCATE_ELEMENT), gettext(POOL), cmd->cmd_tgt1, 10087c478bd9Sstevel@tonic-gate get_errstr()); 10097c478bd9Sstevel@tonic-gate 10107c478bd9Sstevel@tonic-gate if (pool_destroy(conf, pool) != 0) 10117c478bd9Sstevel@tonic-gate die(gettext(ERR_DESTROY_ELEMENT), gettext(POOL), cmd->cmd_tgt1, 10127c478bd9Sstevel@tonic-gate get_errstr()); 10137c478bd9Sstevel@tonic-gate } 10147c478bd9Sstevel@tonic-gate 10157c478bd9Sstevel@tonic-gate static void 10167c478bd9Sstevel@tonic-gate parser_resource_destroy(cmd_t *cmd, const char *type) 10177c478bd9Sstevel@tonic-gate { 10187c478bd9Sstevel@tonic-gate pool_resource_t *resource; 10197c478bd9Sstevel@tonic-gate 10207c478bd9Sstevel@tonic-gate if ((resource = pool_get_resource(conf, type, cmd->cmd_tgt1)) == NULL) 10217c478bd9Sstevel@tonic-gate die(gettext(ERR_LOCATE_ELEMENT), type, cmd->cmd_tgt1, 10227c478bd9Sstevel@tonic-gate get_errstr()); 10237c478bd9Sstevel@tonic-gate 10247c478bd9Sstevel@tonic-gate if (pool_resource_destroy(conf, resource) != 0) 10257c478bd9Sstevel@tonic-gate die(gettext(ERR_DESTROY_ELEMENT), type, cmd->cmd_tgt1, 10267c478bd9Sstevel@tonic-gate get_errstr()); 10277c478bd9Sstevel@tonic-gate } 10287c478bd9Sstevel@tonic-gate 10297c478bd9Sstevel@tonic-gate static void 10307c478bd9Sstevel@tonic-gate parser_pset_destroy(cmd_t *cmd) 10317c478bd9Sstevel@tonic-gate { 10327c478bd9Sstevel@tonic-gate parser_resource_destroy(cmd, PSET); 10337c478bd9Sstevel@tonic-gate } 10347c478bd9Sstevel@tonic-gate 10357c478bd9Sstevel@tonic-gate /* 10367c478bd9Sstevel@tonic-gate * Modify Commands 10377c478bd9Sstevel@tonic-gate * Perform any requested property operations. 10387c478bd9Sstevel@tonic-gate */ 10397c478bd9Sstevel@tonic-gate static void 10407c478bd9Sstevel@tonic-gate parser_conf_modify(cmd_t *cmd) 10417c478bd9Sstevel@tonic-gate { 10427c478bd9Sstevel@tonic-gate pool_elem_t *pe; 10437c478bd9Sstevel@tonic-gate 10447c478bd9Sstevel@tonic-gate if ((pe = pool_conf_to_elem(conf)) == NULL) 10457c478bd9Sstevel@tonic-gate die(gettext(ERR_GET_ELEMENT_DETAILS), 10467c478bd9Sstevel@tonic-gate gettext(CONFIGURATION), "unknown", get_errstr()); 10477c478bd9Sstevel@tonic-gate 10487c478bd9Sstevel@tonic-gate if (cmd->cmd_tgt1 != NULL) 10497c478bd9Sstevel@tonic-gate check_conf_name(cmd); 10507c478bd9Sstevel@tonic-gate 10517c478bd9Sstevel@tonic-gate prop_list_walk(cmd, pe); 10527c478bd9Sstevel@tonic-gate } 10537c478bd9Sstevel@tonic-gate 10547c478bd9Sstevel@tonic-gate static void 10557c478bd9Sstevel@tonic-gate parser_pool_modify(cmd_t *cmd) 10567c478bd9Sstevel@tonic-gate { 10577c478bd9Sstevel@tonic-gate pool_t *pool; 10587c478bd9Sstevel@tonic-gate 10597c478bd9Sstevel@tonic-gate if ((pool = pool_get_pool(conf, cmd->cmd_tgt1)) == NULL) 10607c478bd9Sstevel@tonic-gate die(gettext(ERR_LOCATE_ELEMENT), gettext(POOL), cmd->cmd_tgt1, 10617c478bd9Sstevel@tonic-gate get_errstr()); 10627c478bd9Sstevel@tonic-gate prop_list_walk(cmd, pool_to_elem(conf, pool)); 10637c478bd9Sstevel@tonic-gate } 10647c478bd9Sstevel@tonic-gate 10657c478bd9Sstevel@tonic-gate static void 10667c478bd9Sstevel@tonic-gate parser_resource_modify(cmd_t *cmd, const char *type) 10677c478bd9Sstevel@tonic-gate { 10687c478bd9Sstevel@tonic-gate pool_resource_t *resource; 10697c478bd9Sstevel@tonic-gate 10707c478bd9Sstevel@tonic-gate if ((resource = pool_get_resource(conf, type, cmd->cmd_tgt1)) == NULL) 10717c478bd9Sstevel@tonic-gate die(gettext(ERR_LOCATE_ELEMENT), gettext(RESOURCE), 10727c478bd9Sstevel@tonic-gate cmd->cmd_tgt1, get_errstr()); 10737c478bd9Sstevel@tonic-gate 10747c478bd9Sstevel@tonic-gate process_min_max(resource); 10757c478bd9Sstevel@tonic-gate 10767c478bd9Sstevel@tonic-gate prop_list_walk(cmd, pool_resource_to_elem(conf, resource)); 10777c478bd9Sstevel@tonic-gate } 10787c478bd9Sstevel@tonic-gate 10797c478bd9Sstevel@tonic-gate static void 10807c478bd9Sstevel@tonic-gate parser_pset_modify(cmd_t *cmd) 10817c478bd9Sstevel@tonic-gate { 10827c478bd9Sstevel@tonic-gate parser_resource_modify(cmd, PSET); 10837c478bd9Sstevel@tonic-gate } 10847c478bd9Sstevel@tonic-gate 10857c478bd9Sstevel@tonic-gate static void 10867c478bd9Sstevel@tonic-gate parser_cpu_modify(cmd_t *cmd) 10877c478bd9Sstevel@tonic-gate { 10887c478bd9Sstevel@tonic-gate pool_component_t *comp; 10897c478bd9Sstevel@tonic-gate 10907c478bd9Sstevel@tonic-gate if ((comp = get_cpu(cmd->cmd_tgt1)) == NULL) 10917c478bd9Sstevel@tonic-gate die(gettext(ERR_LOCATE_ELEMENT), gettext(CPU), 10927c478bd9Sstevel@tonic-gate cmd->cmd_tgt1, get_errstr()); 10937c478bd9Sstevel@tonic-gate prop_list_walk(cmd, pool_component_to_elem(conf, comp)); 10947c478bd9Sstevel@tonic-gate } 10957c478bd9Sstevel@tonic-gate 10967c478bd9Sstevel@tonic-gate /* 10977c478bd9Sstevel@tonic-gate * Discover Commands 10987c478bd9Sstevel@tonic-gate * Invoke the libpool pool_conf_open function so that discovery will be 10997c478bd9Sstevel@tonic-gate * performed. 11007c478bd9Sstevel@tonic-gate */ 11017c478bd9Sstevel@tonic-gate 11027c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 11037c478bd9Sstevel@tonic-gate static void 11047c478bd9Sstevel@tonic-gate parser_conf_discover(cmd_t *cmd) 11057c478bd9Sstevel@tonic-gate { 11067c478bd9Sstevel@tonic-gate struct utsname utsname; 11077c478bd9Sstevel@tonic-gate 11087c478bd9Sstevel@tonic-gate if (strcmp(conf_file, pool_dynamic_location()) == 0) 11097c478bd9Sstevel@tonic-gate return; 11107c478bd9Sstevel@tonic-gate 11117c478bd9Sstevel@tonic-gate if (uname(&utsname) < 0) 11127c478bd9Sstevel@tonic-gate die(gettext(ERR_CREATE_ELEMENT), gettext(CONFIGURATION), 11137c478bd9Sstevel@tonic-gate "unknown", get_errstr()); 11147c478bd9Sstevel@tonic-gate 11157c478bd9Sstevel@tonic-gate if (conf != NULL && pool_conf_status(conf) >= POF_VALID) 11167c478bd9Sstevel@tonic-gate pool_conf_close(conf); 11177c478bd9Sstevel@tonic-gate if (pool_conf_open(conf, pool_dynamic_location(), PO_RDONLY) != 0) { 11187c478bd9Sstevel@tonic-gate die(gettext(ERR_CREATE_ELEMENT), gettext(CONFIGURATION), 11197c478bd9Sstevel@tonic-gate utsname.nodename, get_errstr()); 11207c478bd9Sstevel@tonic-gate } 11217c478bd9Sstevel@tonic-gate if (pool_conf_export(conf, conf_file, POX_NATIVE) != 0) { 11227c478bd9Sstevel@tonic-gate die(gettext(ERR_CREATE_ELEMENT), gettext(CONFIGURATION), 11237c478bd9Sstevel@tonic-gate utsname.nodename, get_errstr()); 11247c478bd9Sstevel@tonic-gate } 11257c478bd9Sstevel@tonic-gate (void) pool_conf_close(conf); 11267c478bd9Sstevel@tonic-gate if (pool_conf_open(conf, conf_file, PO_RDWR) != 0) { 11277c478bd9Sstevel@tonic-gate die(gettext(ERR_CREATE_ELEMENT), gettext(CONFIGURATION), 11287c478bd9Sstevel@tonic-gate utsname.nodename, get_errstr()); 11297c478bd9Sstevel@tonic-gate } 11307c478bd9Sstevel@tonic-gate } 11317c478bd9Sstevel@tonic-gate 11327c478bd9Sstevel@tonic-gate /* 11337c478bd9Sstevel@tonic-gate * Associate Commands 11347c478bd9Sstevel@tonic-gate * Walk the list of specified associations so that the target pool will be 11357c478bd9Sstevel@tonic-gate * associated with the required resources. 11367c478bd9Sstevel@tonic-gate */ 11377c478bd9Sstevel@tonic-gate 11387c478bd9Sstevel@tonic-gate static void 11397c478bd9Sstevel@tonic-gate parser_pool_associate(cmd_t *cmd) 11407c478bd9Sstevel@tonic-gate { 11417c478bd9Sstevel@tonic-gate pool_t *pool; 11427c478bd9Sstevel@tonic-gate 11437c478bd9Sstevel@tonic-gate if ((pool = pool_get_pool(conf, cmd->cmd_tgt1)) == NULL) 11447c478bd9Sstevel@tonic-gate die(gettext(ERR_LOCATE_ELEMENT), gettext(POOL), cmd->cmd_tgt1, 11457c478bd9Sstevel@tonic-gate get_errstr()); 11467c478bd9Sstevel@tonic-gate assoc_list_walk(cmd, pool); 11477c478bd9Sstevel@tonic-gate } 11487c478bd9Sstevel@tonic-gate 11497c478bd9Sstevel@tonic-gate /* 11507c478bd9Sstevel@tonic-gate * Assign Commands 11517c478bd9Sstevel@tonic-gate * Walk the list of specified assignations so that the required 11527c478bd9Sstevel@tonic-gate * components will be assigned to the target resource. 11537c478bd9Sstevel@tonic-gate */ 11547c478bd9Sstevel@tonic-gate 11557c478bd9Sstevel@tonic-gate static void 11567c478bd9Sstevel@tonic-gate parser_resource_xtransfer(cmd_t *cmd) 11577c478bd9Sstevel@tonic-gate { 11587c478bd9Sstevel@tonic-gate pool_resource_t *resource; 11597c478bd9Sstevel@tonic-gate 11607c478bd9Sstevel@tonic-gate if ((resource = pool_get_resource(conf, PSET, cmd->cmd_tgt1)) == NULL) 11617c478bd9Sstevel@tonic-gate die(gettext(ERR_LOCATE_ELEMENT), gettext(RESOURCE), 11627c478bd9Sstevel@tonic-gate cmd->cmd_tgt1, get_errstr()); 11637c478bd9Sstevel@tonic-gate transfer_list_walk(cmd, resource); 11647c478bd9Sstevel@tonic-gate } 11657c478bd9Sstevel@tonic-gate 11667c478bd9Sstevel@tonic-gate /* 11677c478bd9Sstevel@tonic-gate * Transfer Commands 11687c478bd9Sstevel@tonic-gate * Transfer the specified quantity of resource between the src and the tgt. 11697c478bd9Sstevel@tonic-gate */ 11707c478bd9Sstevel@tonic-gate 11717c478bd9Sstevel@tonic-gate static void 11727c478bd9Sstevel@tonic-gate parser_resource_transfer(cmd_t *cmd) 11737c478bd9Sstevel@tonic-gate { 11747c478bd9Sstevel@tonic-gate pool_resource_t *src; 11757c478bd9Sstevel@tonic-gate pool_resource_t *tgt; 11767c478bd9Sstevel@tonic-gate 11777c478bd9Sstevel@tonic-gate if ((src = pool_get_resource(conf, PSET, cmd->cmd_tgt1)) == NULL) 11787c478bd9Sstevel@tonic-gate die(gettext(ERR_LOCATE_ELEMENT), gettext(RESOURCE), 11797c478bd9Sstevel@tonic-gate cmd->cmd_tgt1, get_errstr()); 11807c478bd9Sstevel@tonic-gate if ((tgt = pool_get_resource(conf, PSET, cmd->cmd_tgt2)) == NULL) 11817c478bd9Sstevel@tonic-gate die(gettext(ERR_LOCATE_ELEMENT), gettext(RESOURCE), 11827c478bd9Sstevel@tonic-gate cmd->cmd_tgt2, get_errstr()); 11837c478bd9Sstevel@tonic-gate if (pool_resource_transfer(conf, src, tgt, cmd->cmd_qty) != PO_SUCCESS) 11847c478bd9Sstevel@tonic-gate die(gettext(ERR_XFER_QUANTITY), cmd->cmd_qty, 11857c478bd9Sstevel@tonic-gate cmd->cmd_tgt1, cmd->cmd_tgt2, get_errstr()); 11867c478bd9Sstevel@tonic-gate } 11877c478bd9Sstevel@tonic-gate 11887c478bd9Sstevel@tonic-gate /* 11897c478bd9Sstevel@tonic-gate * arg_parse() puts the parser into command parsing mode. Create a tmpfile 11907c478bd9Sstevel@tonic-gate * and instruct the parser to read instructions from this location by setting 11917c478bd9Sstevel@tonic-gate * yyin to the value returned by tmpfile. Write the command into the file. 11927c478bd9Sstevel@tonic-gate * Then seek back to to the start of the file so that the parser can read 11937c478bd9Sstevel@tonic-gate * the instructions. 11947c478bd9Sstevel@tonic-gate */ 11957c478bd9Sstevel@tonic-gate static void 11967c478bd9Sstevel@tonic-gate arg_parse(const char *command) 11977c478bd9Sstevel@tonic-gate { 11987c478bd9Sstevel@tonic-gate if ((yyin = tmpfile()) == NULL) 11997c478bd9Sstevel@tonic-gate die(gettext(ERR_CMD_FILE_INIT), strerror(errno)); 12007c478bd9Sstevel@tonic-gate if (fwrite(command, strlen(command), 1, yyin) != 1) 12017c478bd9Sstevel@tonic-gate die(gettext(ERR_CMD_FILE_INIT), strerror(errno)); 12027c478bd9Sstevel@tonic-gate if (fseek(yyin, 0, SEEK_SET) != 0) 12037c478bd9Sstevel@tonic-gate die(gettext(ERR_CMD_FILE_INIT), strerror(errno)); 12047c478bd9Sstevel@tonic-gate } 12057c478bd9Sstevel@tonic-gate 12067c478bd9Sstevel@tonic-gate /* 12077c478bd9Sstevel@tonic-gate * file_parse() puts the parser into command file parsing mode. Firstly check 12087c478bd9Sstevel@tonic-gate * to see if the user wishes to parse from standard input, if so do nothing. 12097c478bd9Sstevel@tonic-gate * Attempt to open the specified file and instruct the parser to read 12107c478bd9Sstevel@tonic-gate * instructions from this location by setting yyin to the value returned by 12117c478bd9Sstevel@tonic-gate * fopen. 12127c478bd9Sstevel@tonic-gate */ 12137c478bd9Sstevel@tonic-gate static void 12147c478bd9Sstevel@tonic-gate file_parse(const char *file) 12157c478bd9Sstevel@tonic-gate { 12167c478bd9Sstevel@tonic-gate if (strcmp(file, "-") == 0) 12177c478bd9Sstevel@tonic-gate return; 12187c478bd9Sstevel@tonic-gate 12197c478bd9Sstevel@tonic-gate if ((yyin = fopen(file, "r")) == NULL) { 12207c478bd9Sstevel@tonic-gate die(gettext(ERR_CMD_FILE_INIT), strerror(errno)); 12217c478bd9Sstevel@tonic-gate } 12227c478bd9Sstevel@tonic-gate } 12237c478bd9Sstevel@tonic-gate 12247c478bd9Sstevel@tonic-gate /* 12257c478bd9Sstevel@tonic-gate * free_cmd() releases the resources associated with the supplied cmd parameter. 12267c478bd9Sstevel@tonic-gate */ 12277c478bd9Sstevel@tonic-gate static void 12287c478bd9Sstevel@tonic-gate free_cmd(cmd_t *cmd) 12297c478bd9Sstevel@tonic-gate { 12307c478bd9Sstevel@tonic-gate prop_t *prop = cmd->cmd_prop_list; 12317c478bd9Sstevel@tonic-gate assoc_t *assoc = cmd->cmd_assoc_list; 12327c478bd9Sstevel@tonic-gate 12337c478bd9Sstevel@tonic-gate free((void *)cmd->cmd_tgt1); 12347c478bd9Sstevel@tonic-gate free((void *)cmd->cmd_tgt2); 12357c478bd9Sstevel@tonic-gate while (prop != NULL) { 12367c478bd9Sstevel@tonic-gate prop_t *tmp = prop; 12377c478bd9Sstevel@tonic-gate prop = prop->prop_next; 12387c478bd9Sstevel@tonic-gate pool_value_free(tmp->prop_value); 12397c478bd9Sstevel@tonic-gate free((void *)tmp->prop_name); 12407c478bd9Sstevel@tonic-gate free(tmp); 12417c478bd9Sstevel@tonic-gate } 12427c478bd9Sstevel@tonic-gate while (assoc != NULL) { 12437c478bd9Sstevel@tonic-gate assoc_t *tmp = assoc; 12447c478bd9Sstevel@tonic-gate assoc = assoc->assoc_next; 12457c478bd9Sstevel@tonic-gate free((void *)tmp->assoc_name); 12467c478bd9Sstevel@tonic-gate free(tmp); 12477c478bd9Sstevel@tonic-gate } 12487c478bd9Sstevel@tonic-gate free(cmd); 12497c478bd9Sstevel@tonic-gate } 12507c478bd9Sstevel@tonic-gate 12517c478bd9Sstevel@tonic-gate /* 12527c478bd9Sstevel@tonic-gate * alloc_cmd() allocates the required resources for a cmd_t. On failure, a 12537c478bd9Sstevel@tonic-gate * warning is issued and NULL is returned. 12547c478bd9Sstevel@tonic-gate */ 12557c478bd9Sstevel@tonic-gate static cmd_t * 12567c478bd9Sstevel@tonic-gate alloc_cmd(void) 12577c478bd9Sstevel@tonic-gate { 12587c478bd9Sstevel@tonic-gate cmd_t *cmd; 12597c478bd9Sstevel@tonic-gate 12607c478bd9Sstevel@tonic-gate if ((cmd = malloc(sizeof (cmd_t))) == NULL) { 12617c478bd9Sstevel@tonic-gate warn(gettext(ERR_CMD_LINE_ALLOC)); 12627c478bd9Sstevel@tonic-gate return (NULL); 12637c478bd9Sstevel@tonic-gate } 12647c478bd9Sstevel@tonic-gate 12657c478bd9Sstevel@tonic-gate (void) memset(cmd, 0, sizeof (cmd_t)); 12667c478bd9Sstevel@tonic-gate 12677c478bd9Sstevel@tonic-gate return (cmd); 12687c478bd9Sstevel@tonic-gate } 12697c478bd9Sstevel@tonic-gate 12707c478bd9Sstevel@tonic-gate /* 12717c478bd9Sstevel@tonic-gate * alloc_prop() allocates the required resources for a prop_t. On failure, a 12727c478bd9Sstevel@tonic-gate * warning is issued and NULL is returned. The prop_t is initialised with 12737c478bd9Sstevel@tonic-gate * the prop_op_t parameter. 12747c478bd9Sstevel@tonic-gate */ 12757c478bd9Sstevel@tonic-gate static prop_t * 12767c478bd9Sstevel@tonic-gate alloc_prop(prop_op_t op) 12777c478bd9Sstevel@tonic-gate { 12787c478bd9Sstevel@tonic-gate prop_t *prop; 12797c478bd9Sstevel@tonic-gate 12807c478bd9Sstevel@tonic-gate if ((prop = malloc(sizeof (prop_t))) == NULL) { 12817c478bd9Sstevel@tonic-gate warn(gettext(ERR_PROP_ALLOC)); 12827c478bd9Sstevel@tonic-gate return (NULL); 12837c478bd9Sstevel@tonic-gate } 12847c478bd9Sstevel@tonic-gate 12857c478bd9Sstevel@tonic-gate (void) memset(prop, 0, sizeof (prop_t)); 12867c478bd9Sstevel@tonic-gate if ((prop->prop_value = pool_value_alloc()) == NULL) { 12877c478bd9Sstevel@tonic-gate warn(gettext(ERR_PROP_ALLOC)); 12887c478bd9Sstevel@tonic-gate free(prop); 12897c478bd9Sstevel@tonic-gate return (NULL); 12907c478bd9Sstevel@tonic-gate } 12917c478bd9Sstevel@tonic-gate prop->prop_op = op; 12927c478bd9Sstevel@tonic-gate return (prop); 12937c478bd9Sstevel@tonic-gate } 12947c478bd9Sstevel@tonic-gate 12957c478bd9Sstevel@tonic-gate /* 12967c478bd9Sstevel@tonic-gate * alloc_assoc() allocates the required resources for an assoc_t. On failure, a 12977c478bd9Sstevel@tonic-gate * warning is issued and NULL is returned. The assoc_t is initialised with 12987c478bd9Sstevel@tonic-gate * the type and name of the association. 12997c478bd9Sstevel@tonic-gate */ 13007c478bd9Sstevel@tonic-gate static assoc_t * 13017c478bd9Sstevel@tonic-gate alloc_assoc(int type, const char *name) 13027c478bd9Sstevel@tonic-gate { 13037c478bd9Sstevel@tonic-gate assoc_t *assoc; 13047c478bd9Sstevel@tonic-gate 13057c478bd9Sstevel@tonic-gate if ((assoc = malloc(sizeof (assoc_t))) == NULL) { 13067c478bd9Sstevel@tonic-gate warn(gettext(ERR_ASSOC_ALLOC)); 13077c478bd9Sstevel@tonic-gate return (NULL); 13087c478bd9Sstevel@tonic-gate } 13097c478bd9Sstevel@tonic-gate (void) memset(assoc, 0, sizeof (assoc_t)); 13107c478bd9Sstevel@tonic-gate assoc->assoc_type = type; 13117c478bd9Sstevel@tonic-gate assoc->assoc_name = name; 13127c478bd9Sstevel@tonic-gate return (assoc); 13137c478bd9Sstevel@tonic-gate } 13147c478bd9Sstevel@tonic-gate 13157c478bd9Sstevel@tonic-gate /* 13167c478bd9Sstevel@tonic-gate * check_conf_name() ensures the the name of the system in the configuration 13177c478bd9Sstevel@tonic-gate * which is being manipulated matches the name of the system in the command. 13187c478bd9Sstevel@tonic-gate * If not, the command is terminated with an appropriate error message. 13197c478bd9Sstevel@tonic-gate */ 13207c478bd9Sstevel@tonic-gate static void 13217c478bd9Sstevel@tonic-gate check_conf_name(cmd_t *cmd) 13227c478bd9Sstevel@tonic-gate { 13237c478bd9Sstevel@tonic-gate pool_value_t *pv; 13247c478bd9Sstevel@tonic-gate const char *name; 13257c478bd9Sstevel@tonic-gate pool_elem_t *pe; 13267c478bd9Sstevel@tonic-gate 13277c478bd9Sstevel@tonic-gate if ((pe = pool_conf_to_elem(conf)) == NULL) 13287c478bd9Sstevel@tonic-gate die(gettext(ERR_GET_ELEMENT_DETAILS), 13297c478bd9Sstevel@tonic-gate gettext(CONFIGURATION), "unknown", get_errstr()); 13307c478bd9Sstevel@tonic-gate 13317c478bd9Sstevel@tonic-gate 13327c478bd9Sstevel@tonic-gate if ((pv = pool_value_alloc()) == NULL) { 13337c478bd9Sstevel@tonic-gate die(gettext(ERR_ALLOC_ELEMENT), gettext(RESOURCE), 13347c478bd9Sstevel@tonic-gate get_errstr()); 13357c478bd9Sstevel@tonic-gate } 13367c478bd9Sstevel@tonic-gate 13377c478bd9Sstevel@tonic-gate if (pool_get_property(conf, pe, SYSTEM_NAME, pv) 13387c478bd9Sstevel@tonic-gate == POC_INVAL) 13397c478bd9Sstevel@tonic-gate die(gettext(ERR_GET_PROPERTY), gettext(SYSTEM_NAME), 13407c478bd9Sstevel@tonic-gate get_errstr()); 13417c478bd9Sstevel@tonic-gate 13427c478bd9Sstevel@tonic-gate if (pool_value_get_string(pv, &name) == PO_FAIL) 13437c478bd9Sstevel@tonic-gate die(gettext(ERR_GET_PROPERTY), gettext(SYSTEM_NAME), 13447c478bd9Sstevel@tonic-gate get_errstr()); 13457c478bd9Sstevel@tonic-gate 13467c478bd9Sstevel@tonic-gate if (strcmp(cmd->cmd_tgt1, name) != 0) { 13477c478bd9Sstevel@tonic-gate die(gettext(ERR_WRONG_SYSTEM_NAME), cmd->cmd_tgt1); 13487c478bd9Sstevel@tonic-gate } 13497c478bd9Sstevel@tonic-gate pool_value_free(pv); 13507c478bd9Sstevel@tonic-gate } 13517c478bd9Sstevel@tonic-gate 13527c478bd9Sstevel@tonic-gate /* 13537c478bd9Sstevel@tonic-gate * usage() display brief or verbose help for the poolcfg(1) command. 13547c478bd9Sstevel@tonic-gate */ 13557c478bd9Sstevel@tonic-gate static void 13567c478bd9Sstevel@tonic-gate usage(int help) 13577c478bd9Sstevel@tonic-gate { 13587c478bd9Sstevel@tonic-gate if (help >= 1) 13597c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(USAGE1), cmdname, cmdname, 13607c478bd9Sstevel@tonic-gate cmdname); 13617c478bd9Sstevel@tonic-gate if (help >= 2) 13627c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(USAGE2)); 13637c478bd9Sstevel@tonic-gate exit(E_USAGE); 13647c478bd9Sstevel@tonic-gate } 13657c478bd9Sstevel@tonic-gate 13667c478bd9Sstevel@tonic-gate /* 13677c478bd9Sstevel@tonic-gate * prop_list_walk() walks the property manipulation requests and either puts 13687c478bd9Sstevel@tonic-gate * or removes the property as appropriate. 13697c478bd9Sstevel@tonic-gate */ 13707c478bd9Sstevel@tonic-gate static void 13717c478bd9Sstevel@tonic-gate prop_list_walk(cmd_t *cmd, pool_elem_t *pe) 13727c478bd9Sstevel@tonic-gate { 13737c478bd9Sstevel@tonic-gate prop_t *prop; 13747c478bd9Sstevel@tonic-gate 13757c478bd9Sstevel@tonic-gate for (prop = cmd->cmd_prop_list; prop != NULL; prop = prop->prop_next) { 13767c478bd9Sstevel@tonic-gate switch (prop->prop_op) { 13777c478bd9Sstevel@tonic-gate case po_create: 13787c478bd9Sstevel@tonic-gate if (pool_put_property(conf, pe, prop->prop_name, 13797c478bd9Sstevel@tonic-gate prop->prop_value) != 0) 13807c478bd9Sstevel@tonic-gate die(gettext(ERR_PUT_PROPERTY), 13817c478bd9Sstevel@tonic-gate prop->prop_name, get_errstr()); 13827c478bd9Sstevel@tonic-gate break; 13837c478bd9Sstevel@tonic-gate case po_remove: 13847c478bd9Sstevel@tonic-gate if (pool_rm_property(conf, pe, prop->prop_name) != 0) 13857c478bd9Sstevel@tonic-gate die(gettext(ERR_REMOVE_PROPERTY), 13867c478bd9Sstevel@tonic-gate prop->prop_name, get_errstr()); 13877c478bd9Sstevel@tonic-gate break; 13887c478bd9Sstevel@tonic-gate } 13897c478bd9Sstevel@tonic-gate } 13907c478bd9Sstevel@tonic-gate } 13917c478bd9Sstevel@tonic-gate 13927c478bd9Sstevel@tonic-gate /* 13937c478bd9Sstevel@tonic-gate * assoc_list_walk() walks the resource association requests and attempts 13947c478bd9Sstevel@tonic-gate * to associate the pool with the specified resource. 13957c478bd9Sstevel@tonic-gate */ 13967c478bd9Sstevel@tonic-gate static void 13977c478bd9Sstevel@tonic-gate assoc_list_walk(cmd_t *cmd, pool_t *pool) 13987c478bd9Sstevel@tonic-gate { 13997c478bd9Sstevel@tonic-gate assoc_t *assoc; 14007c478bd9Sstevel@tonic-gate 14017c478bd9Sstevel@tonic-gate for (assoc = cmd->cmd_assoc_list; assoc != NULL; 14027c478bd9Sstevel@tonic-gate assoc = assoc->assoc_next) { 14037c478bd9Sstevel@tonic-gate pool_resource_t *resource; 14047c478bd9Sstevel@tonic-gate 14057c478bd9Sstevel@tonic-gate switch (assoc->assoc_type) { 14067c478bd9Sstevel@tonic-gate case PCE_PSET: 14077c478bd9Sstevel@tonic-gate if ((resource = pool_get_resource(conf, 14087c478bd9Sstevel@tonic-gate PSET, assoc->assoc_name)) == NULL) 14097c478bd9Sstevel@tonic-gate die(gettext(ERR_LOCATE_ELEMENT), gettext(PSET), 14107c478bd9Sstevel@tonic-gate assoc->assoc_name, get_errstr()); 14117c478bd9Sstevel@tonic-gate break; 14127c478bd9Sstevel@tonic-gate default: 14137c478bd9Sstevel@tonic-gate die(gettext(ERR_UNKNOWN_RESOURCE), 14147c478bd9Sstevel@tonic-gate assoc->assoc_type); 14157c478bd9Sstevel@tonic-gate break; 14167c478bd9Sstevel@tonic-gate } 14177c478bd9Sstevel@tonic-gate if (pool_associate(conf, pool, resource) != 0) 14187c478bd9Sstevel@tonic-gate die(gettext(ERR_ASSOC_RESOURCE), assoc->assoc_name, 14197c478bd9Sstevel@tonic-gate get_errstr()); 14207c478bd9Sstevel@tonic-gate } 14217c478bd9Sstevel@tonic-gate } 14227c478bd9Sstevel@tonic-gate 14237c478bd9Sstevel@tonic-gate /* 14247c478bd9Sstevel@tonic-gate * transfer_list_walk() walks the component assign requests and attempts 14257c478bd9Sstevel@tonic-gate * to assign the component with the specified resource. 14267c478bd9Sstevel@tonic-gate */ 14277c478bd9Sstevel@tonic-gate static void 14287c478bd9Sstevel@tonic-gate transfer_list_walk(cmd_t *cmd, pool_resource_t *tgt) 14297c478bd9Sstevel@tonic-gate { 14307c478bd9Sstevel@tonic-gate assoc_t *assoc; 14317c478bd9Sstevel@tonic-gate 14327c478bd9Sstevel@tonic-gate for (assoc = cmd->cmd_assoc_list; assoc != NULL; 14337c478bd9Sstevel@tonic-gate assoc = assoc->assoc_next) { 14347c478bd9Sstevel@tonic-gate pool_component_t *comp; 14357c478bd9Sstevel@tonic-gate pool_resource_t *src; 14367c478bd9Sstevel@tonic-gate pool_component_t *xfer[2] = {NULL}; 14377c478bd9Sstevel@tonic-gate 14387c478bd9Sstevel@tonic-gate if ((comp = get_cpu(assoc->assoc_name)) == NULL) 14397c478bd9Sstevel@tonic-gate die(gettext(ERR_LOCATE_ELEMENT), gettext(CPU), 14407c478bd9Sstevel@tonic-gate assoc->assoc_name, get_errstr()); 14417c478bd9Sstevel@tonic-gate if ((src = pool_get_owning_resource(conf, comp)) == NULL) 14427c478bd9Sstevel@tonic-gate die(gettext(ERR_XFER_COMPONENT), gettext(COMPONENT), 14437c478bd9Sstevel@tonic-gate assoc->assoc_name, cmd->cmd_tgt1, get_errstr()); 14447c478bd9Sstevel@tonic-gate xfer[0] = comp; 14457c478bd9Sstevel@tonic-gate if (pool_resource_xtransfer(conf, src, tgt, xfer) != 14467c478bd9Sstevel@tonic-gate PO_SUCCESS) 14477c478bd9Sstevel@tonic-gate die(gettext(ERR_XFER_COMPONENT), gettext(COMPONENT), 14487c478bd9Sstevel@tonic-gate assoc->assoc_name, cmd->cmd_tgt1, get_errstr()); 14497c478bd9Sstevel@tonic-gate } 14507c478bd9Sstevel@tonic-gate } 14517c478bd9Sstevel@tonic-gate 14527c478bd9Sstevel@tonic-gate /* 14537c478bd9Sstevel@tonic-gate * terminate() is invoked when poolcfg exits. It cleans up 14547c478bd9Sstevel@tonic-gate * configurations and closes the parser input stream. 14557c478bd9Sstevel@tonic-gate */ 14567c478bd9Sstevel@tonic-gate static void 14577c478bd9Sstevel@tonic-gate terminate(void) 14587c478bd9Sstevel@tonic-gate { 14597c478bd9Sstevel@tonic-gate if (conf != NULL) { 14607c478bd9Sstevel@tonic-gate (void) pool_conf_close(conf); 14617c478bd9Sstevel@tonic-gate pool_conf_free(conf); 14627c478bd9Sstevel@tonic-gate } 14637c478bd9Sstevel@tonic-gate if (yyin != stdin) 14647c478bd9Sstevel@tonic-gate (void) fclose(yyin); 14657c478bd9Sstevel@tonic-gate } 14667c478bd9Sstevel@tonic-gate 14677c478bd9Sstevel@tonic-gate /* 14687c478bd9Sstevel@tonic-gate * get_cpu() takes the name of a CPU components and attempts to locate 14697c478bd9Sstevel@tonic-gate * the element with that name. If the name is not formatted correctly 14707c478bd9Sstevel@tonic-gate * (i.e. contains non-numeric characters) then the function terminates 14717c478bd9Sstevel@tonic-gate * execution. If the components cannot be uniquely identified by the 14727c478bd9Sstevel@tonic-gate * name, then NULL is returned. 14737c478bd9Sstevel@tonic-gate */ 14747c478bd9Sstevel@tonic-gate static pool_component_t * 14757c478bd9Sstevel@tonic-gate get_cpu(const char *name) 14767c478bd9Sstevel@tonic-gate { 14777c478bd9Sstevel@tonic-gate pool_component_t **components; 14787c478bd9Sstevel@tonic-gate uint_t nelem; 14797c478bd9Sstevel@tonic-gate int64_t sysid; 14807c478bd9Sstevel@tonic-gate pool_value_t *vals[3] = {NULL}; 14817c478bd9Sstevel@tonic-gate pool_component_t *ret; 14827c478bd9Sstevel@tonic-gate const char *c; 14837c478bd9Sstevel@tonic-gate 14847c478bd9Sstevel@tonic-gate if ((vals[0] = pool_value_alloc()) == NULL) 14857c478bd9Sstevel@tonic-gate return (NULL); 14867c478bd9Sstevel@tonic-gate if ((vals[1] = pool_value_alloc()) == NULL) { 14877c478bd9Sstevel@tonic-gate pool_value_free(vals[0]); 14887c478bd9Sstevel@tonic-gate return (NULL); 14897c478bd9Sstevel@tonic-gate } 14907c478bd9Sstevel@tonic-gate if (pool_value_set_string(vals[0], "cpu") != PO_SUCCESS || 14917c478bd9Sstevel@tonic-gate pool_value_set_name(vals[0], "type") != PO_SUCCESS) { 14927c478bd9Sstevel@tonic-gate pool_value_free(vals[0]); 14937c478bd9Sstevel@tonic-gate pool_value_free(vals[1]); 14947c478bd9Sstevel@tonic-gate return (NULL); 14957c478bd9Sstevel@tonic-gate } 14967c478bd9Sstevel@tonic-gate 14977c478bd9Sstevel@tonic-gate for (c = name; *c != NULL; c++) { 14987c478bd9Sstevel@tonic-gate if (!isdigit(*c)){ 14997c478bd9Sstevel@tonic-gate pool_value_free(vals[0]); 15007c478bd9Sstevel@tonic-gate pool_value_free(vals[1]); 15017c478bd9Sstevel@tonic-gate die(gettext(ERR_LOCATE_ELEMENT), gettext(CPU), 15027c478bd9Sstevel@tonic-gate cmd->cmd_tgt1, gettext("CPU id should only contain " 15037c478bd9Sstevel@tonic-gate "digits")); 15047c478bd9Sstevel@tonic-gate } 15057c478bd9Sstevel@tonic-gate } 15067c478bd9Sstevel@tonic-gate sysid = strtoll(name, NULL, 0); 15077c478bd9Sstevel@tonic-gate if (errno == ERANGE || errno == EINVAL) { 15087c478bd9Sstevel@tonic-gate pool_value_free(vals[0]); 15097c478bd9Sstevel@tonic-gate pool_value_free(vals[1]); 15107c478bd9Sstevel@tonic-gate return (NULL); 15117c478bd9Sstevel@tonic-gate } 15127c478bd9Sstevel@tonic-gate pool_value_set_int64(vals[1], sysid); 15137c478bd9Sstevel@tonic-gate if (pool_value_set_name(vals[1], CPU_SYSID) != PO_SUCCESS) { 15147c478bd9Sstevel@tonic-gate pool_value_free(vals[0]); 15157c478bd9Sstevel@tonic-gate pool_value_free(vals[1]); 15167c478bd9Sstevel@tonic-gate return (NULL); 15177c478bd9Sstevel@tonic-gate } 15187c478bd9Sstevel@tonic-gate if ((components = pool_query_components(conf, &nelem, vals)) == 15197c478bd9Sstevel@tonic-gate NULL) { 15207c478bd9Sstevel@tonic-gate pool_value_free(vals[0]); 15217c478bd9Sstevel@tonic-gate pool_value_free(vals[1]); 15227c478bd9Sstevel@tonic-gate return (NULL); 15237c478bd9Sstevel@tonic-gate } 15247c478bd9Sstevel@tonic-gate if (nelem != 1) { 15257c478bd9Sstevel@tonic-gate free(components); 15267c478bd9Sstevel@tonic-gate pool_value_free(vals[0]); 15277c478bd9Sstevel@tonic-gate pool_value_free(vals[1]); 15287c478bd9Sstevel@tonic-gate return (NULL); 15297c478bd9Sstevel@tonic-gate } 15307c478bd9Sstevel@tonic-gate pool_value_free(vals[0]); 15317c478bd9Sstevel@tonic-gate pool_value_free(vals[1]); 15327c478bd9Sstevel@tonic-gate ret = components[0]; 15337c478bd9Sstevel@tonic-gate free(components); 15347c478bd9Sstevel@tonic-gate return (ret); 15357c478bd9Sstevel@tonic-gate } 15367c478bd9Sstevel@tonic-gate 15377c478bd9Sstevel@tonic-gate /* 15387c478bd9Sstevel@tonic-gate * process_min_max() ensures that "min" and "max" properties are 15397c478bd9Sstevel@tonic-gate * processed correctly by poolcfg. libpool enforces validity 15407c478bd9Sstevel@tonic-gate * constraints on these properties and so it's important that changes 15417c478bd9Sstevel@tonic-gate * to them are supplied to the library in the correct order. 15427c478bd9Sstevel@tonic-gate */ 15437c478bd9Sstevel@tonic-gate void 15447c478bd9Sstevel@tonic-gate process_min_max(pool_resource_t *resource) 15457c478bd9Sstevel@tonic-gate { 15467c478bd9Sstevel@tonic-gate prop_t *minprop = NULL; 15477c478bd9Sstevel@tonic-gate prop_t *maxprop = NULL; 15487c478bd9Sstevel@tonic-gate prop_t *prop; 15497c478bd9Sstevel@tonic-gate 15507c478bd9Sstevel@tonic-gate /* 15517c478bd9Sstevel@tonic-gate * Before walking the list of properties, it has to be checked 15527c478bd9Sstevel@tonic-gate * to ensure there are no clashes between min and max. If 15537c478bd9Sstevel@tonic-gate * there are, then process these properties immediately. 15547c478bd9Sstevel@tonic-gate */ 15557c478bd9Sstevel@tonic-gate for (prop = cmd->cmd_prop_list; prop != NULL; prop = prop->prop_next) { 15567c478bd9Sstevel@tonic-gate const char *pos; 15577c478bd9Sstevel@tonic-gate 15587c478bd9Sstevel@tonic-gate if ((pos = strstr(prop->prop_name, min_suffix)) != NULL) 15597c478bd9Sstevel@tonic-gate if (pos == prop->prop_name + strlen(prop->prop_name) 15607c478bd9Sstevel@tonic-gate - 4) 15617c478bd9Sstevel@tonic-gate minprop = prop; 15627c478bd9Sstevel@tonic-gate if ((pos = strstr(prop->prop_name, max_suffix)) != NULL) 15637c478bd9Sstevel@tonic-gate if (pos == prop->prop_name + strlen(prop->prop_name) 15647c478bd9Sstevel@tonic-gate - 4) 15657c478bd9Sstevel@tonic-gate maxprop = prop; 15667c478bd9Sstevel@tonic-gate } 15677c478bd9Sstevel@tonic-gate if (minprop && maxprop) { 15687c478bd9Sstevel@tonic-gate pool_value_t *pv; 15697c478bd9Sstevel@tonic-gate uint64_t smin, smax, dmax; 15707c478bd9Sstevel@tonic-gate const char *type; 15717c478bd9Sstevel@tonic-gate char *prop_name; 15727c478bd9Sstevel@tonic-gate pool_elem_t *pe = pool_resource_to_elem(conf, resource); 15737c478bd9Sstevel@tonic-gate 15747c478bd9Sstevel@tonic-gate if ((pv = pool_value_alloc()) == NULL) 15757c478bd9Sstevel@tonic-gate die(gettext(ERR_NOMEM)); 15767c478bd9Sstevel@tonic-gate 15777c478bd9Sstevel@tonic-gate (void) pool_get_property(conf, pe, "type", pv); 15787c478bd9Sstevel@tonic-gate (void) pool_value_get_string(pv, &type); 15797c478bd9Sstevel@tonic-gate 15807c478bd9Sstevel@tonic-gate if ((prop_name = malloc(strlen(type) + strlen(max_suffix) 15817c478bd9Sstevel@tonic-gate + 1)) == NULL) 15827c478bd9Sstevel@tonic-gate die(gettext(ERR_NOMEM)); 15837c478bd9Sstevel@tonic-gate 15847c478bd9Sstevel@tonic-gate (void) sprintf(prop_name, "%s%s", type, max_suffix); 15857c478bd9Sstevel@tonic-gate (void) pool_get_property(conf, pe, prop_name, pv); 15867c478bd9Sstevel@tonic-gate (void) pool_value_get_uint64(pv, &dmax); 15877c478bd9Sstevel@tonic-gate 15887c478bd9Sstevel@tonic-gate (void) pool_value_get_uint64(minprop->prop_value, &smin); 15897c478bd9Sstevel@tonic-gate 15907c478bd9Sstevel@tonic-gate (void) pool_value_get_uint64(maxprop->prop_value, &smax); 15917c478bd9Sstevel@tonic-gate if (smin < dmax) { 15927c478bd9Sstevel@tonic-gate (void) pool_put_property(conf, pe, 15937c478bd9Sstevel@tonic-gate minprop->prop_name, minprop->prop_value); 15947c478bd9Sstevel@tonic-gate } else { 15957c478bd9Sstevel@tonic-gate (void) pool_put_property(conf, pe, 15967c478bd9Sstevel@tonic-gate maxprop->prop_name, maxprop->prop_value); 15977c478bd9Sstevel@tonic-gate } 15987c478bd9Sstevel@tonic-gate free((void *)prop_name); 15997c478bd9Sstevel@tonic-gate pool_value_free(pv); 16007c478bd9Sstevel@tonic-gate } 16017c478bd9Sstevel@tonic-gate } 1602