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