17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5fb03efaaSdp * Common Development and Distribution License (the "License"). 6fb03efaaSdp * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217e362f58Scomay 227c478bd9Sstevel@tonic-gate /* 235679c89fSjv227347 * Copyright 2009 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 * zonecfg is a lex/yacc based command interpreter used to manage zone 297c478bd9Sstevel@tonic-gate * configurations. The lexer (see zonecfg_lex.l) builds up tokens, which 307c478bd9Sstevel@tonic-gate * the grammar (see zonecfg_grammar.y) builds up into commands, some of 317c478bd9Sstevel@tonic-gate * which takes resources and/or properties as arguments. See the block 327c478bd9Sstevel@tonic-gate * comments near the end of zonecfg_grammar.y for how the data structures 337c478bd9Sstevel@tonic-gate * which keep track of these resources and properties are built up. 347c478bd9Sstevel@tonic-gate * 357c478bd9Sstevel@tonic-gate * The resource/property data structures are inserted into a command 367c478bd9Sstevel@tonic-gate * structure (see zonecfg.h), which also keeps track of command names, 377c478bd9Sstevel@tonic-gate * miscellaneous arguments, and function handlers. The grammar selects 387c478bd9Sstevel@tonic-gate * the appropriate function handler, each of which takes a pointer to a 397c478bd9Sstevel@tonic-gate * command structure as its sole argument, and invokes it. The grammar 407c478bd9Sstevel@tonic-gate * itself is "entered" (a la the Matrix) by yyparse(), which is called 417c478bd9Sstevel@tonic-gate * from read_input(), our main driving function. That in turn is called 427c478bd9Sstevel@tonic-gate * by one of do_interactive(), cmd_file() or one_command_at_a_time(), each 437c478bd9Sstevel@tonic-gate * of which is called from main() depending on how the program was invoked. 447c478bd9Sstevel@tonic-gate * 457c478bd9Sstevel@tonic-gate * The rest of this module consists of the various function handlers and 467c478bd9Sstevel@tonic-gate * their helper functions. Some of these functions, particularly the 477c478bd9Sstevel@tonic-gate * X_to_str() functions, which maps command, resource and property numbers 487c478bd9Sstevel@tonic-gate * to strings, are used quite liberally, as doing so results in a better 497c478bd9Sstevel@tonic-gate * program w/rt I18N, reducing the need for translation notes. 507c478bd9Sstevel@tonic-gate */ 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate #include <sys/mntent.h> 537c478bd9Sstevel@tonic-gate #include <sys/varargs.h> 547c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate #include <errno.h> 579acbbeafSnn35248 #include <fcntl.h> 587c478bd9Sstevel@tonic-gate #include <strings.h> 597c478bd9Sstevel@tonic-gate #include <unistd.h> 607c478bd9Sstevel@tonic-gate #include <ctype.h> 617c478bd9Sstevel@tonic-gate #include <stdlib.h> 627c478bd9Sstevel@tonic-gate #include <assert.h> 637c478bd9Sstevel@tonic-gate #include <sys/stat.h> 647c478bd9Sstevel@tonic-gate #include <zone.h> 657c478bd9Sstevel@tonic-gate #include <arpa/inet.h> 667c478bd9Sstevel@tonic-gate #include <netdb.h> 677c478bd9Sstevel@tonic-gate #include <locale.h> 687c478bd9Sstevel@tonic-gate #include <libintl.h> 697c478bd9Sstevel@tonic-gate #include <alloca.h> 707c478bd9Sstevel@tonic-gate #include <signal.h> 719acbbeafSnn35248 #include <wait.h> 727c478bd9Sstevel@tonic-gate #include <libtecla.h> 73fa9e4066Sahrens #include <libzfs.h> 749acbbeafSnn35248 #include <sys/brand.h> 759acbbeafSnn35248 #include <libbrand.h> 765679c89fSjv227347 #include <sys/systeminfo.h> 77c9f134eaSjv227347 #include <libdladm.h> 78c9f134eaSjv227347 #include <libinetutil.h> 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate #include <libzonecfg.h> 817c478bd9Sstevel@tonic-gate #include "zonecfg.h" 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) /* should be defined by cc -D */ 847c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it wasn't */ 857c478bd9Sstevel@tonic-gate #endif 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate #define PAGER "/usr/bin/more" 889acbbeafSnn35248 #define EXEC_PREFIX "exec " 899acbbeafSnn35248 #define EXEC_LEN (strlen(EXEC_PREFIX)) 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate struct help { 927c478bd9Sstevel@tonic-gate uint_t cmd_num; 937c478bd9Sstevel@tonic-gate char *cmd_name; 947c478bd9Sstevel@tonic-gate uint_t flags; 957c478bd9Sstevel@tonic-gate char *short_usage; 967c478bd9Sstevel@tonic-gate }; 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate extern int yyparse(void); 997c478bd9Sstevel@tonic-gate extern int lex_lineno; 1007c478bd9Sstevel@tonic-gate 1017c478bd9Sstevel@tonic-gate #define MAX_LINE_LEN 1024 1027c478bd9Sstevel@tonic-gate #define MAX_CMD_HIST 1024 1039acbbeafSnn35248 #define MAX_CMD_LEN 1024 1047c478bd9Sstevel@tonic-gate 1050209230bSgjelinek #define ONE_MB 1048576 1060209230bSgjelinek 1077c478bd9Sstevel@tonic-gate /* 1087c478bd9Sstevel@tonic-gate * Each SHELP_ should be a simple string. 1097c478bd9Sstevel@tonic-gate */ 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate #define SHELP_ADD "add <resource-type>\n\t(global scope)\n" \ 1127c478bd9Sstevel@tonic-gate "add <property-name> <property-value>\n\t(resource scope)" 1137c478bd9Sstevel@tonic-gate #define SHELP_CANCEL "cancel" 1140209230bSgjelinek #define SHELP_CLEAR "clear <property-name>" 1157c478bd9Sstevel@tonic-gate #define SHELP_COMMIT "commit" 116ee519a1fSgjelinek #define SHELP_CREATE "create [-F] [ -a <path> | -b | -t <template> ]" 1177c478bd9Sstevel@tonic-gate #define SHELP_DELETE "delete [-F]" 1187c478bd9Sstevel@tonic-gate #define SHELP_END "end" 1197c478bd9Sstevel@tonic-gate #define SHELP_EXIT "exit [-F]" 1207c478bd9Sstevel@tonic-gate #define SHELP_EXPORT "export [-f output-file]" 1217c478bd9Sstevel@tonic-gate #define SHELP_HELP "help [commands] [syntax] [usage] [<command-name>]" 1227c478bd9Sstevel@tonic-gate #define SHELP_INFO "info [<resource-type> [property-name=property-value]*]" 1230209230bSgjelinek #define SHELP_REMOVE "remove [-F] <resource-type> " \ 1240209230bSgjelinek "[ <property-name>=<property-value> ]*\n" \ 1250209230bSgjelinek "\t(global scope)\n" \ 1260209230bSgjelinek "remove <property-name> <property-value>\n" \ 1270209230bSgjelinek "\t(resource scope)" 1287c478bd9Sstevel@tonic-gate #define SHELP_REVERT "revert [-F]" 1297c478bd9Sstevel@tonic-gate #define SHELP_SELECT "select <resource-type> { <property-name>=" \ 1307c478bd9Sstevel@tonic-gate "<property-value> }" 1317c478bd9Sstevel@tonic-gate #define SHELP_SET "set <property-name>=<property-value>" 1327c478bd9Sstevel@tonic-gate #define SHELP_VERIFY "verify" 1337c478bd9Sstevel@tonic-gate 1347c478bd9Sstevel@tonic-gate static struct help helptab[] = { 1357c478bd9Sstevel@tonic-gate { CMD_ADD, "add", HELP_RES_PROPS, SHELP_ADD, }, 1367c478bd9Sstevel@tonic-gate { CMD_CANCEL, "cancel", 0, SHELP_CANCEL, }, 1370209230bSgjelinek { CMD_CLEAR, "clear", HELP_PROPS, SHELP_CLEAR, }, 1387c478bd9Sstevel@tonic-gate { CMD_COMMIT, "commit", 0, SHELP_COMMIT, }, 1397c478bd9Sstevel@tonic-gate { CMD_CREATE, "create", 0, SHELP_CREATE, }, 1407c478bd9Sstevel@tonic-gate { CMD_DELETE, "delete", 0, SHELP_DELETE, }, 1417c478bd9Sstevel@tonic-gate { CMD_END, "end", 0, SHELP_END, }, 1427c478bd9Sstevel@tonic-gate { CMD_EXIT, "exit", 0, SHELP_EXIT, }, 1437c478bd9Sstevel@tonic-gate { CMD_EXPORT, "export", 0, SHELP_EXPORT, }, 1447c478bd9Sstevel@tonic-gate { CMD_HELP, "help", 0, SHELP_HELP }, 1457c478bd9Sstevel@tonic-gate { CMD_INFO, "info", HELP_RES_PROPS, SHELP_INFO, }, 1467c478bd9Sstevel@tonic-gate { CMD_REMOVE, "remove", HELP_RES_PROPS, SHELP_REMOVE, }, 1477c478bd9Sstevel@tonic-gate { CMD_REVERT, "revert", 0, SHELP_REVERT, }, 1487c478bd9Sstevel@tonic-gate { CMD_SELECT, "select", HELP_RES_PROPS, SHELP_SELECT, }, 1497c478bd9Sstevel@tonic-gate { CMD_SET, "set", HELP_PROPS, SHELP_SET, }, 1507c478bd9Sstevel@tonic-gate { CMD_VERIFY, "verify", 0, SHELP_VERIFY, }, 1517c478bd9Sstevel@tonic-gate { 0 }, 1527c478bd9Sstevel@tonic-gate }; 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate #define MAX_RT_STRLEN 16 1557c478bd9Sstevel@tonic-gate 1567c478bd9Sstevel@tonic-gate /* These *must* match the order of the RT_ define's from zonecfg.h */ 157*c94c1ef0Sjv227347 char *res_types[] = { 1587c478bd9Sstevel@tonic-gate "unknown", 159087719fdSdp "zonename", 1607c478bd9Sstevel@tonic-gate "zonepath", 1617c478bd9Sstevel@tonic-gate "autoboot", 1627c478bd9Sstevel@tonic-gate "pool", 1637c478bd9Sstevel@tonic-gate "fs", 1647c478bd9Sstevel@tonic-gate "inherit-pkg-dir", 1657c478bd9Sstevel@tonic-gate "net", 1667c478bd9Sstevel@tonic-gate "device", 1677c478bd9Sstevel@tonic-gate "rctl", 1687c478bd9Sstevel@tonic-gate "attr", 169fa9e4066Sahrens "dataset", 170ffbafc53Scomay "limitpriv", 1713f2f09c1Sdp "bootargs", 1729acbbeafSnn35248 "brand", 1730209230bSgjelinek "dedicated-cpu", 1740209230bSgjelinek "capped-memory", 1750209230bSgjelinek ALIAS_MAXLWPS, 1760209230bSgjelinek ALIAS_MAXSHMMEM, 1770209230bSgjelinek ALIAS_MAXSHMIDS, 1780209230bSgjelinek ALIAS_MAXMSGIDS, 1790209230bSgjelinek ALIAS_MAXSEMIDS, 1800209230bSgjelinek ALIAS_SHARES, 1810209230bSgjelinek "scheduling-class", 182f4b3ec61Sdh155122 "ip-type", 183c97ad5cdSakolb "capped-cpu", 1845679c89fSjv227347 "hostid", 1857c478bd9Sstevel@tonic-gate NULL 1867c478bd9Sstevel@tonic-gate }; 1877c478bd9Sstevel@tonic-gate 1887c478bd9Sstevel@tonic-gate /* These *must* match the order of the PT_ define's from zonecfg.h */ 189*c94c1ef0Sjv227347 char *prop_types[] = { 1907c478bd9Sstevel@tonic-gate "unknown", 191087719fdSdp "zonename", 1927c478bd9Sstevel@tonic-gate "zonepath", 1937c478bd9Sstevel@tonic-gate "autoboot", 1947c478bd9Sstevel@tonic-gate "pool", 1957c478bd9Sstevel@tonic-gate "dir", 1967c478bd9Sstevel@tonic-gate "special", 1977c478bd9Sstevel@tonic-gate "type", 1987c478bd9Sstevel@tonic-gate "options", 1997c478bd9Sstevel@tonic-gate "address", 2007c478bd9Sstevel@tonic-gate "physical", 2017c478bd9Sstevel@tonic-gate "name", 2027c478bd9Sstevel@tonic-gate "value", 2037c478bd9Sstevel@tonic-gate "match", 2047c478bd9Sstevel@tonic-gate "priv", 2057c478bd9Sstevel@tonic-gate "limit", 2067c478bd9Sstevel@tonic-gate "action", 2077c478bd9Sstevel@tonic-gate "raw", 208ffbafc53Scomay "limitpriv", 2093f2f09c1Sdp "bootargs", 2109acbbeafSnn35248 "brand", 2110209230bSgjelinek "ncpus", 2120209230bSgjelinek "importance", 2130209230bSgjelinek "swap", 2140209230bSgjelinek "locked", 2150209230bSgjelinek ALIAS_SHARES, 2160209230bSgjelinek ALIAS_MAXLWPS, 2170209230bSgjelinek ALIAS_MAXSHMMEM, 2180209230bSgjelinek ALIAS_MAXSHMIDS, 2190209230bSgjelinek ALIAS_MAXMSGIDS, 2200209230bSgjelinek ALIAS_MAXSEMIDS, 2210209230bSgjelinek ALIAS_MAXLOCKEDMEM, 2220209230bSgjelinek ALIAS_MAXSWAP, 2230209230bSgjelinek "scheduling-class", 224f4b3ec61Sdh155122 "ip-type", 225de860bd9Sgfaden "defrouter", 2265679c89fSjv227347 "hostid", 2277c478bd9Sstevel@tonic-gate NULL 2287c478bd9Sstevel@tonic-gate }; 2297c478bd9Sstevel@tonic-gate 230ffbafc53Scomay /* These *must* match the order of the PROP_VAL_ define's from zonecfg.h */ 2317c478bd9Sstevel@tonic-gate static char *prop_val_types[] = { 2327c478bd9Sstevel@tonic-gate "simple", 2337c478bd9Sstevel@tonic-gate "complex", 2347c478bd9Sstevel@tonic-gate "list", 2357c478bd9Sstevel@tonic-gate }; 2367c478bd9Sstevel@tonic-gate 2377c478bd9Sstevel@tonic-gate /* 2387c478bd9Sstevel@tonic-gate * The various _cmds[] lists below are for command tab-completion. 2397c478bd9Sstevel@tonic-gate */ 2407c478bd9Sstevel@tonic-gate 2417c478bd9Sstevel@tonic-gate /* 2427c478bd9Sstevel@tonic-gate * remove has a space afterwards because it has qualifiers; the other commands 2430209230bSgjelinek * that have qualifiers (add, select, etc.) don't need a space here because 2447c478bd9Sstevel@tonic-gate * they have their own _cmds[] lists below. 2457c478bd9Sstevel@tonic-gate */ 2467c478bd9Sstevel@tonic-gate static const char *global_scope_cmds[] = { 2477c478bd9Sstevel@tonic-gate "add", 2480209230bSgjelinek "clear", 2497c478bd9Sstevel@tonic-gate "commit", 2507c478bd9Sstevel@tonic-gate "create", 2517c478bd9Sstevel@tonic-gate "delete", 2527c478bd9Sstevel@tonic-gate "exit", 2537c478bd9Sstevel@tonic-gate "export", 2547c478bd9Sstevel@tonic-gate "help", 2557c478bd9Sstevel@tonic-gate "info", 2567c478bd9Sstevel@tonic-gate "remove ", 2577c478bd9Sstevel@tonic-gate "revert", 2587c478bd9Sstevel@tonic-gate "select", 2597c478bd9Sstevel@tonic-gate "set", 2607c478bd9Sstevel@tonic-gate "verify", 2617c478bd9Sstevel@tonic-gate NULL 2627c478bd9Sstevel@tonic-gate }; 2637c478bd9Sstevel@tonic-gate 2647c478bd9Sstevel@tonic-gate static const char *add_cmds[] = { 2657c478bd9Sstevel@tonic-gate "add fs", 2667c478bd9Sstevel@tonic-gate "add inherit-pkg-dir", 2677c478bd9Sstevel@tonic-gate "add net", 2687c478bd9Sstevel@tonic-gate "add device", 2697c478bd9Sstevel@tonic-gate "add rctl", 2707c478bd9Sstevel@tonic-gate "add attr", 271fa9e4066Sahrens "add dataset", 2720209230bSgjelinek "add dedicated-cpu", 273c97ad5cdSakolb "add capped-cpu", 2740209230bSgjelinek "add capped-memory", 2750209230bSgjelinek NULL 2760209230bSgjelinek }; 2770209230bSgjelinek 2780209230bSgjelinek static const char *clear_cmds[] = { 2790209230bSgjelinek "clear autoboot", 2800209230bSgjelinek "clear pool", 2810209230bSgjelinek "clear limitpriv", 2820209230bSgjelinek "clear bootargs", 2830209230bSgjelinek "clear scheduling-class", 284f4b3ec61Sdh155122 "clear ip-type", 2850209230bSgjelinek "clear " ALIAS_MAXLWPS, 2860209230bSgjelinek "clear " ALIAS_MAXSHMMEM, 2870209230bSgjelinek "clear " ALIAS_MAXSHMIDS, 2880209230bSgjelinek "clear " ALIAS_MAXMSGIDS, 2890209230bSgjelinek "clear " ALIAS_MAXSEMIDS, 2900209230bSgjelinek "clear " ALIAS_SHARES, 2917c478bd9Sstevel@tonic-gate NULL 2927c478bd9Sstevel@tonic-gate }; 2937c478bd9Sstevel@tonic-gate 2949e7542f4Sdp static const char *remove_cmds[] = { 2959e7542f4Sdp "remove fs ", 2969e7542f4Sdp "remove inherit-pkg-dir ", 2979e7542f4Sdp "remove net ", 2989e7542f4Sdp "remove device ", 2999e7542f4Sdp "remove rctl ", 3009e7542f4Sdp "remove attr ", 3019e7542f4Sdp "remove dataset ", 3020209230bSgjelinek "remove dedicated-cpu ", 303c97ad5cdSakolb "remove capped-cpu ", 3040209230bSgjelinek "remove capped-memory ", 3059e7542f4Sdp NULL 3069e7542f4Sdp }; 3079e7542f4Sdp 3087c478bd9Sstevel@tonic-gate static const char *select_cmds[] = { 3097c478bd9Sstevel@tonic-gate "select fs ", 3107c478bd9Sstevel@tonic-gate "select inherit-pkg-dir ", 3117c478bd9Sstevel@tonic-gate "select net ", 3127c478bd9Sstevel@tonic-gate "select device ", 3137c478bd9Sstevel@tonic-gate "select rctl ", 3147c478bd9Sstevel@tonic-gate "select attr ", 315fa9e4066Sahrens "select dataset ", 3160209230bSgjelinek "select dedicated-cpu", 317c97ad5cdSakolb "select capped-cpu", 3180209230bSgjelinek "select capped-memory", 3197c478bd9Sstevel@tonic-gate NULL 3207c478bd9Sstevel@tonic-gate }; 3217c478bd9Sstevel@tonic-gate 3227c478bd9Sstevel@tonic-gate static const char *set_cmds[] = { 323087719fdSdp "set zonename=", 324087719fdSdp "set zonepath=", 3259acbbeafSnn35248 "set brand=", 326087719fdSdp "set autoboot=", 327087719fdSdp "set pool=", 328ffbafc53Scomay "set limitpriv=", 3293f2f09c1Sdp "set bootargs=", 3300209230bSgjelinek "set scheduling-class=", 331f4b3ec61Sdh155122 "set ip-type=", 3320209230bSgjelinek "set " ALIAS_MAXLWPS "=", 3330209230bSgjelinek "set " ALIAS_MAXSHMMEM "=", 3340209230bSgjelinek "set " ALIAS_MAXSHMIDS "=", 3350209230bSgjelinek "set " ALIAS_MAXMSGIDS "=", 3360209230bSgjelinek "set " ALIAS_MAXSEMIDS "=", 3370209230bSgjelinek "set " ALIAS_SHARES "=", 3385679c89fSjv227347 "set hostid=", 3397c478bd9Sstevel@tonic-gate NULL 3407c478bd9Sstevel@tonic-gate }; 3417c478bd9Sstevel@tonic-gate 3429e7542f4Sdp static const char *info_cmds[] = { 3439e7542f4Sdp "info fs ", 3449e7542f4Sdp "info inherit-pkg-dir ", 3459e7542f4Sdp "info net ", 3469e7542f4Sdp "info device ", 3479e7542f4Sdp "info rctl ", 3489e7542f4Sdp "info attr ", 3499e7542f4Sdp "info dataset ", 3500209230bSgjelinek "info capped-memory", 3510209230bSgjelinek "info dedicated-cpu", 352c97ad5cdSakolb "info capped-cpu", 3539e7542f4Sdp "info zonename", 3549e7542f4Sdp "info zonepath", 3559e7542f4Sdp "info autoboot", 3569e7542f4Sdp "info pool", 3579e7542f4Sdp "info limitpriv", 3589e7542f4Sdp "info bootargs", 3590209230bSgjelinek "info brand", 3600209230bSgjelinek "info scheduling-class", 361f4b3ec61Sdh155122 "info ip-type", 3620209230bSgjelinek "info max-lwps", 3630209230bSgjelinek "info max-shm-memory", 3640209230bSgjelinek "info max-shm-ids", 3650209230bSgjelinek "info max-msg-ids", 3660209230bSgjelinek "info max-sem-ids", 3670209230bSgjelinek "info cpu-shares", 3685679c89fSjv227347 "info hostid", 3699e7542f4Sdp NULL 3709e7542f4Sdp }; 3719e7542f4Sdp 3727c478bd9Sstevel@tonic-gate static const char *fs_res_scope_cmds[] = { 3737c478bd9Sstevel@tonic-gate "add options ", 3747c478bd9Sstevel@tonic-gate "cancel", 3757c478bd9Sstevel@tonic-gate "end", 3767c478bd9Sstevel@tonic-gate "exit", 3777c478bd9Sstevel@tonic-gate "help", 3787c478bd9Sstevel@tonic-gate "info", 379ffbafc53Scomay "remove options ", 3807c478bd9Sstevel@tonic-gate "set dir=", 3817c478bd9Sstevel@tonic-gate "set raw=", 3827c478bd9Sstevel@tonic-gate "set special=", 3837c478bd9Sstevel@tonic-gate "set type=", 3840209230bSgjelinek "clear raw", 3857c478bd9Sstevel@tonic-gate NULL 3867c478bd9Sstevel@tonic-gate }; 3877c478bd9Sstevel@tonic-gate 3887c478bd9Sstevel@tonic-gate static const char *net_res_scope_cmds[] = { 3897c478bd9Sstevel@tonic-gate "cancel", 3907c478bd9Sstevel@tonic-gate "end", 3917c478bd9Sstevel@tonic-gate "exit", 3927c478bd9Sstevel@tonic-gate "help", 3937c478bd9Sstevel@tonic-gate "info", 3947c478bd9Sstevel@tonic-gate "set address=", 3957c478bd9Sstevel@tonic-gate "set physical=", 3967c478bd9Sstevel@tonic-gate NULL 3977c478bd9Sstevel@tonic-gate }; 3987c478bd9Sstevel@tonic-gate 3997c478bd9Sstevel@tonic-gate static const char *ipd_res_scope_cmds[] = { 4007c478bd9Sstevel@tonic-gate "cancel", 4017c478bd9Sstevel@tonic-gate "end", 4027c478bd9Sstevel@tonic-gate "exit", 4037c478bd9Sstevel@tonic-gate "help", 4047c478bd9Sstevel@tonic-gate "info", 4057c478bd9Sstevel@tonic-gate "set dir=", 4067c478bd9Sstevel@tonic-gate NULL 4077c478bd9Sstevel@tonic-gate }; 4087c478bd9Sstevel@tonic-gate 4097c478bd9Sstevel@tonic-gate static const char *device_res_scope_cmds[] = { 4107c478bd9Sstevel@tonic-gate "cancel", 4117c478bd9Sstevel@tonic-gate "end", 4127c478bd9Sstevel@tonic-gate "exit", 4137c478bd9Sstevel@tonic-gate "help", 4147c478bd9Sstevel@tonic-gate "info", 4157c478bd9Sstevel@tonic-gate "set match=", 4167c478bd9Sstevel@tonic-gate NULL 4177c478bd9Sstevel@tonic-gate }; 4187c478bd9Sstevel@tonic-gate 4197c478bd9Sstevel@tonic-gate static const char *attr_res_scope_cmds[] = { 4207c478bd9Sstevel@tonic-gate "cancel", 4217c478bd9Sstevel@tonic-gate "end", 4227c478bd9Sstevel@tonic-gate "exit", 4237c478bd9Sstevel@tonic-gate "help", 4247c478bd9Sstevel@tonic-gate "info", 4257c478bd9Sstevel@tonic-gate "set name=", 4267c478bd9Sstevel@tonic-gate "set type=", 4277c478bd9Sstevel@tonic-gate "set value=", 4287c478bd9Sstevel@tonic-gate NULL 4297c478bd9Sstevel@tonic-gate }; 4307c478bd9Sstevel@tonic-gate 4317c478bd9Sstevel@tonic-gate static const char *rctl_res_scope_cmds[] = { 4327c478bd9Sstevel@tonic-gate "add value ", 4337c478bd9Sstevel@tonic-gate "cancel", 4347c478bd9Sstevel@tonic-gate "end", 4357c478bd9Sstevel@tonic-gate "exit", 4367c478bd9Sstevel@tonic-gate "help", 4377c478bd9Sstevel@tonic-gate "info", 438ffbafc53Scomay "remove value ", 4397c478bd9Sstevel@tonic-gate "set name=", 4407c478bd9Sstevel@tonic-gate NULL 4417c478bd9Sstevel@tonic-gate }; 4427c478bd9Sstevel@tonic-gate 443fa9e4066Sahrens static const char *dataset_res_scope_cmds[] = { 444fa9e4066Sahrens "cancel", 445fa9e4066Sahrens "end", 446fa9e4066Sahrens "exit", 447fa9e4066Sahrens "help", 448fa9e4066Sahrens "info", 449fa9e4066Sahrens "set name=", 450fa9e4066Sahrens NULL 451fa9e4066Sahrens }; 452fa9e4066Sahrens 4530209230bSgjelinek static const char *pset_res_scope_cmds[] = { 4540209230bSgjelinek "cancel", 4550209230bSgjelinek "end", 4560209230bSgjelinek "exit", 4570209230bSgjelinek "help", 4580209230bSgjelinek "info", 4590209230bSgjelinek "set ncpus=", 4600209230bSgjelinek "set importance=", 4610209230bSgjelinek "clear importance", 4620209230bSgjelinek NULL 4630209230bSgjelinek }; 4640209230bSgjelinek 465c97ad5cdSakolb static const char *pcap_res_scope_cmds[] = { 466c97ad5cdSakolb "cancel", 467c97ad5cdSakolb "end", 468c97ad5cdSakolb "exit", 469c97ad5cdSakolb "help", 470c97ad5cdSakolb "info", 471c97ad5cdSakolb "set ncpus=", 472c97ad5cdSakolb NULL 473c97ad5cdSakolb }; 474c97ad5cdSakolb 4750209230bSgjelinek static const char *mcap_res_scope_cmds[] = { 4760209230bSgjelinek "cancel", 4770209230bSgjelinek "end", 4780209230bSgjelinek "exit", 4790209230bSgjelinek "help", 4800209230bSgjelinek "info", 4810209230bSgjelinek "set physical=", 4820209230bSgjelinek "set swap=", 4830209230bSgjelinek "set locked=", 4840209230bSgjelinek "clear physical", 4850209230bSgjelinek "clear swap", 4860209230bSgjelinek "clear locked", 4870209230bSgjelinek NULL 4880209230bSgjelinek }; 4890209230bSgjelinek 4907c478bd9Sstevel@tonic-gate /* Global variables */ 4917c478bd9Sstevel@tonic-gate 4927c478bd9Sstevel@tonic-gate /* set early in main(), never modified thereafter, used all over the place */ 4937c478bd9Sstevel@tonic-gate static char *execname; 4947c478bd9Sstevel@tonic-gate 4957c478bd9Sstevel@tonic-gate /* set in main(), used all over the place */ 4967c478bd9Sstevel@tonic-gate static zone_dochandle_t handle; 4977c478bd9Sstevel@tonic-gate 4987c478bd9Sstevel@tonic-gate /* used all over the place */ 499087719fdSdp static char zone[ZONENAME_MAX]; 500087719fdSdp static char revert_zone[ZONENAME_MAX]; 5017c478bd9Sstevel@tonic-gate 5029acbbeafSnn35248 /* global brand operations */ 503123807fbSedp static brand_handle_t brand; 5049acbbeafSnn35248 5057c478bd9Sstevel@tonic-gate /* set in modifying functions, checked in read_input() */ 506bbec428eSgjelinek static boolean_t need_to_commit = B_FALSE; 507bbec428eSgjelinek boolean_t saw_error; 5087c478bd9Sstevel@tonic-gate 5097c478bd9Sstevel@tonic-gate /* set in yacc parser, checked in read_input() */ 510bbec428eSgjelinek boolean_t newline_terminated; 5117c478bd9Sstevel@tonic-gate 5127c478bd9Sstevel@tonic-gate /* set in main(), checked in lex error handler */ 513bbec428eSgjelinek boolean_t cmd_file_mode; 5147c478bd9Sstevel@tonic-gate 5157c478bd9Sstevel@tonic-gate /* set in exit_func(), checked in read_input() */ 516bbec428eSgjelinek static boolean_t time_to_exit = B_FALSE, force_exit = B_FALSE; 5177c478bd9Sstevel@tonic-gate 5187c478bd9Sstevel@tonic-gate /* used in short_usage() and zerr() */ 5197c478bd9Sstevel@tonic-gate static char *cmd_file_name = NULL; 5207c478bd9Sstevel@tonic-gate 5217c478bd9Sstevel@tonic-gate /* checked in read_input() and other places */ 522bbec428eSgjelinek static boolean_t ok_to_prompt = B_FALSE; 5237c478bd9Sstevel@tonic-gate 5247c478bd9Sstevel@tonic-gate /* set and checked in initialize() */ 525bbec428eSgjelinek static boolean_t got_handle = B_FALSE; 5267c478bd9Sstevel@tonic-gate 5277c478bd9Sstevel@tonic-gate /* initialized in do_interactive(), checked in initialize() */ 528bbec428eSgjelinek static boolean_t interactive_mode; 5297c478bd9Sstevel@tonic-gate 5300209230bSgjelinek /* set if configuring the global zone */ 531bbec428eSgjelinek static boolean_t global_zone = B_FALSE; 5320209230bSgjelinek 5337c478bd9Sstevel@tonic-gate /* set in main(), checked in multiple places */ 534bbec428eSgjelinek static boolean_t read_only_mode; 5357c478bd9Sstevel@tonic-gate 536bbec428eSgjelinek /* scope is outer/global or inner/resource */ 537bbec428eSgjelinek static boolean_t global_scope = B_TRUE; 5387c478bd9Sstevel@tonic-gate static int resource_scope; /* should be in the RT_ list from zonecfg.h */ 5397c478bd9Sstevel@tonic-gate static int end_op = -1; /* operation on end is either add or modify */ 5407c478bd9Sstevel@tonic-gate 5417c478bd9Sstevel@tonic-gate int num_prop_vals; /* for grammar */ 5427c478bd9Sstevel@tonic-gate 5437c478bd9Sstevel@tonic-gate /* 5447c478bd9Sstevel@tonic-gate * These are for keeping track of resources as they are specified as part of 5457c478bd9Sstevel@tonic-gate * the multi-step process. They should be initialized by add_resource() or 5467c478bd9Sstevel@tonic-gate * select_func() and filled in by add_property() or set_func(). 5477c478bd9Sstevel@tonic-gate */ 5487c478bd9Sstevel@tonic-gate static struct zone_fstab old_fstab, in_progress_fstab; 5497c478bd9Sstevel@tonic-gate static struct zone_fstab old_ipdtab, in_progress_ipdtab; 5507c478bd9Sstevel@tonic-gate static struct zone_nwiftab old_nwiftab, in_progress_nwiftab; 5517c478bd9Sstevel@tonic-gate static struct zone_devtab old_devtab, in_progress_devtab; 5527c478bd9Sstevel@tonic-gate static struct zone_rctltab old_rctltab, in_progress_rctltab; 5537c478bd9Sstevel@tonic-gate static struct zone_attrtab old_attrtab, in_progress_attrtab; 554fa9e4066Sahrens static struct zone_dstab old_dstab, in_progress_dstab; 5550209230bSgjelinek static struct zone_psettab old_psettab, in_progress_psettab; 5560209230bSgjelinek static struct zone_mcaptab old_mcaptab, in_progress_mcaptab; 5577c478bd9Sstevel@tonic-gate 5587c478bd9Sstevel@tonic-gate static GetLine *gl; /* The gl_get_line() resource object */ 5597c478bd9Sstevel@tonic-gate 5600209230bSgjelinek static void bytes_to_units(char *str, char *buf, int bufsize); 5610209230bSgjelinek 5627c478bd9Sstevel@tonic-gate /* Functions begin here */ 5637c478bd9Sstevel@tonic-gate 564bbec428eSgjelinek static boolean_t 5657c478bd9Sstevel@tonic-gate initial_match(const char *line1, const char *line2, int word_end) 5667c478bd9Sstevel@tonic-gate { 5677c478bd9Sstevel@tonic-gate if (word_end <= 0) 568bbec428eSgjelinek return (B_TRUE); 5697c478bd9Sstevel@tonic-gate return (strncmp(line1, line2, word_end) == 0); 5707c478bd9Sstevel@tonic-gate } 5717c478bd9Sstevel@tonic-gate 5727c478bd9Sstevel@tonic-gate static int 5737c478bd9Sstevel@tonic-gate add_stuff(WordCompletion *cpl, const char *line1, const char **list, 5747c478bd9Sstevel@tonic-gate int word_end) 5757c478bd9Sstevel@tonic-gate { 5767c478bd9Sstevel@tonic-gate int i, err; 5777c478bd9Sstevel@tonic-gate 5787c478bd9Sstevel@tonic-gate for (i = 0; list[i] != NULL; i++) { 5797c478bd9Sstevel@tonic-gate if (initial_match(line1, list[i], word_end)) { 5807c478bd9Sstevel@tonic-gate err = cpl_add_completion(cpl, line1, 0, word_end, 5817c478bd9Sstevel@tonic-gate list[i] + word_end, "", ""); 5827c478bd9Sstevel@tonic-gate if (err != 0) 5837c478bd9Sstevel@tonic-gate return (err); 5847c478bd9Sstevel@tonic-gate } 5857c478bd9Sstevel@tonic-gate } 5867c478bd9Sstevel@tonic-gate return (0); 5877c478bd9Sstevel@tonic-gate } 5887c478bd9Sstevel@tonic-gate 5897c478bd9Sstevel@tonic-gate static 5907c478bd9Sstevel@tonic-gate /* ARGSUSED */ 5917c478bd9Sstevel@tonic-gate CPL_MATCH_FN(cmd_cpl_fn) 5927c478bd9Sstevel@tonic-gate { 5937c478bd9Sstevel@tonic-gate if (global_scope) { 5947c478bd9Sstevel@tonic-gate /* 5957c478bd9Sstevel@tonic-gate * The MAX/MIN tests below are to make sure we have at least 5967c478bd9Sstevel@tonic-gate * enough characters to distinguish from other prefixes (MAX) 5977c478bd9Sstevel@tonic-gate * but only check MIN(what we have, what we're checking). 5987c478bd9Sstevel@tonic-gate */ 5997c478bd9Sstevel@tonic-gate if (strncmp(line, "add ", MAX(MIN(word_end, 4), 1)) == 0) 6007c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, add_cmds, word_end)); 6010209230bSgjelinek if (strncmp(line, "clear ", MAX(MIN(word_end, 6), 2)) == 0) 6020209230bSgjelinek return (add_stuff(cpl, line, clear_cmds, word_end)); 6037c478bd9Sstevel@tonic-gate if (strncmp(line, "select ", MAX(MIN(word_end, 7), 3)) == 0) 6047c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, select_cmds, word_end)); 6057c478bd9Sstevel@tonic-gate if (strncmp(line, "set ", MAX(MIN(word_end, 4), 3)) == 0) 6067c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, set_cmds, word_end)); 6079e7542f4Sdp if (strncmp(line, "remove ", MAX(MIN(word_end, 7), 1)) == 0) 6089e7542f4Sdp return (add_stuff(cpl, line, remove_cmds, word_end)); 6099e7542f4Sdp if (strncmp(line, "info ", MAX(MIN(word_end, 5), 1)) == 0) 6109e7542f4Sdp return (add_stuff(cpl, line, info_cmds, word_end)); 6117c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, global_scope_cmds, word_end)); 6127c478bd9Sstevel@tonic-gate } 6137c478bd9Sstevel@tonic-gate switch (resource_scope) { 6147c478bd9Sstevel@tonic-gate case RT_FS: 6157c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, fs_res_scope_cmds, word_end)); 6167c478bd9Sstevel@tonic-gate case RT_IPD: 6177c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, ipd_res_scope_cmds, word_end)); 6187c478bd9Sstevel@tonic-gate case RT_NET: 6197c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, net_res_scope_cmds, word_end)); 6207c478bd9Sstevel@tonic-gate case RT_DEVICE: 6217c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, device_res_scope_cmds, word_end)); 6227c478bd9Sstevel@tonic-gate case RT_RCTL: 6237c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, rctl_res_scope_cmds, word_end)); 6247c478bd9Sstevel@tonic-gate case RT_ATTR: 6257c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, attr_res_scope_cmds, word_end)); 626fa9e4066Sahrens case RT_DATASET: 627fa9e4066Sahrens return (add_stuff(cpl, line, dataset_res_scope_cmds, word_end)); 6280209230bSgjelinek case RT_DCPU: 6290209230bSgjelinek return (add_stuff(cpl, line, pset_res_scope_cmds, word_end)); 630c97ad5cdSakolb case RT_PCAP: 631c97ad5cdSakolb return (add_stuff(cpl, line, pcap_res_scope_cmds, word_end)); 6320209230bSgjelinek case RT_MCAP: 6330209230bSgjelinek return (add_stuff(cpl, line, mcap_res_scope_cmds, word_end)); 6347c478bd9Sstevel@tonic-gate } 6357c478bd9Sstevel@tonic-gate return (0); 6367c478bd9Sstevel@tonic-gate } 6377c478bd9Sstevel@tonic-gate 6387c478bd9Sstevel@tonic-gate /* 6397c478bd9Sstevel@tonic-gate * For the main CMD_func() functions below, several of them call getopt() 6407c478bd9Sstevel@tonic-gate * then check optind against argc to make sure an extra parameter was not 6417c478bd9Sstevel@tonic-gate * passed in. The reason this is not caught in the grammar is that the 6427c478bd9Sstevel@tonic-gate * grammar just checks for a miscellaneous TOKEN, which is *expected* to 6437c478bd9Sstevel@tonic-gate * be "-F" (for example), but could be anything. So (for example) this 6447c478bd9Sstevel@tonic-gate * check will prevent "create bogus". 6457c478bd9Sstevel@tonic-gate */ 6467c478bd9Sstevel@tonic-gate 6477c478bd9Sstevel@tonic-gate cmd_t * 6487c478bd9Sstevel@tonic-gate alloc_cmd(void) 6497c478bd9Sstevel@tonic-gate { 6507c478bd9Sstevel@tonic-gate return (calloc(1, sizeof (cmd_t))); 6517c478bd9Sstevel@tonic-gate } 6527c478bd9Sstevel@tonic-gate 6537c478bd9Sstevel@tonic-gate void 6547c478bd9Sstevel@tonic-gate free_cmd(cmd_t *cmd) 6557c478bd9Sstevel@tonic-gate { 6567c478bd9Sstevel@tonic-gate int i; 6577c478bd9Sstevel@tonic-gate 6587c478bd9Sstevel@tonic-gate for (i = 0; i < MAX_EQ_PROP_PAIRS; i++) 6597c478bd9Sstevel@tonic-gate if (cmd->cmd_property_ptr[i] != NULL) { 6607c478bd9Sstevel@tonic-gate property_value_ptr_t pp = cmd->cmd_property_ptr[i]; 6617c478bd9Sstevel@tonic-gate 6627c478bd9Sstevel@tonic-gate switch (pp->pv_type) { 6637c478bd9Sstevel@tonic-gate case PROP_VAL_SIMPLE: 6647c478bd9Sstevel@tonic-gate free(pp->pv_simple); 6657c478bd9Sstevel@tonic-gate break; 6667c478bd9Sstevel@tonic-gate case PROP_VAL_COMPLEX: 6677c478bd9Sstevel@tonic-gate free_complex(pp->pv_complex); 6687c478bd9Sstevel@tonic-gate break; 6697c478bd9Sstevel@tonic-gate case PROP_VAL_LIST: 6707c478bd9Sstevel@tonic-gate free_list(pp->pv_list); 6717c478bd9Sstevel@tonic-gate break; 6727c478bd9Sstevel@tonic-gate } 6737c478bd9Sstevel@tonic-gate } 6747c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_argc; i++) 6757c478bd9Sstevel@tonic-gate free(cmd->cmd_argv[i]); 6767c478bd9Sstevel@tonic-gate free(cmd); 6777c478bd9Sstevel@tonic-gate } 6787c478bd9Sstevel@tonic-gate 6797c478bd9Sstevel@tonic-gate complex_property_ptr_t 6807c478bd9Sstevel@tonic-gate alloc_complex(void) 6817c478bd9Sstevel@tonic-gate { 6827c478bd9Sstevel@tonic-gate return (calloc(1, sizeof (complex_property_t))); 6837c478bd9Sstevel@tonic-gate } 6847c478bd9Sstevel@tonic-gate 6857c478bd9Sstevel@tonic-gate void 6867c478bd9Sstevel@tonic-gate free_complex(complex_property_ptr_t complex) 6877c478bd9Sstevel@tonic-gate { 6887c478bd9Sstevel@tonic-gate if (complex == NULL) 6897c478bd9Sstevel@tonic-gate return; 6907c478bd9Sstevel@tonic-gate free_complex(complex->cp_next); 6917c478bd9Sstevel@tonic-gate if (complex->cp_value != NULL) 6927c478bd9Sstevel@tonic-gate free(complex->cp_value); 6937c478bd9Sstevel@tonic-gate free(complex); 6947c478bd9Sstevel@tonic-gate } 6957c478bd9Sstevel@tonic-gate 6967c478bd9Sstevel@tonic-gate list_property_ptr_t 6977c478bd9Sstevel@tonic-gate alloc_list(void) 6987c478bd9Sstevel@tonic-gate { 6997c478bd9Sstevel@tonic-gate return (calloc(1, sizeof (list_property_t))); 7007c478bd9Sstevel@tonic-gate } 7017c478bd9Sstevel@tonic-gate 7027c478bd9Sstevel@tonic-gate void 7037c478bd9Sstevel@tonic-gate free_list(list_property_ptr_t list) 7047c478bd9Sstevel@tonic-gate { 7057c478bd9Sstevel@tonic-gate if (list == NULL) 7067c478bd9Sstevel@tonic-gate return; 7077c478bd9Sstevel@tonic-gate if (list->lp_simple != NULL) 7087c478bd9Sstevel@tonic-gate free(list->lp_simple); 7097c478bd9Sstevel@tonic-gate free_complex(list->lp_complex); 7107c478bd9Sstevel@tonic-gate free_list(list->lp_next); 7117c478bd9Sstevel@tonic-gate free(list); 7127c478bd9Sstevel@tonic-gate } 7137c478bd9Sstevel@tonic-gate 7147c478bd9Sstevel@tonic-gate void 7157c478bd9Sstevel@tonic-gate free_outer_list(list_property_ptr_t list) 7167c478bd9Sstevel@tonic-gate { 7177c478bd9Sstevel@tonic-gate if (list == NULL) 7187c478bd9Sstevel@tonic-gate return; 7197c478bd9Sstevel@tonic-gate free_outer_list(list->lp_next); 7207c478bd9Sstevel@tonic-gate free(list); 7217c478bd9Sstevel@tonic-gate } 7227c478bd9Sstevel@tonic-gate 7237c478bd9Sstevel@tonic-gate static struct zone_rctlvaltab * 7247c478bd9Sstevel@tonic-gate alloc_rctlvaltab(void) 7257c478bd9Sstevel@tonic-gate { 7267c478bd9Sstevel@tonic-gate return (calloc(1, sizeof (struct zone_rctlvaltab))); 7277c478bd9Sstevel@tonic-gate } 7287c478bd9Sstevel@tonic-gate 7297c478bd9Sstevel@tonic-gate static char * 7307c478bd9Sstevel@tonic-gate rt_to_str(int res_type) 7317c478bd9Sstevel@tonic-gate { 7327c478bd9Sstevel@tonic-gate assert(res_type >= RT_MIN && res_type <= RT_MAX); 7337c478bd9Sstevel@tonic-gate return (res_types[res_type]); 7347c478bd9Sstevel@tonic-gate } 7357c478bd9Sstevel@tonic-gate 7367c478bd9Sstevel@tonic-gate static char * 7377c478bd9Sstevel@tonic-gate pt_to_str(int prop_type) 7387c478bd9Sstevel@tonic-gate { 7397c478bd9Sstevel@tonic-gate assert(prop_type >= PT_MIN && prop_type <= PT_MAX); 7407c478bd9Sstevel@tonic-gate return (prop_types[prop_type]); 7417c478bd9Sstevel@tonic-gate } 7427c478bd9Sstevel@tonic-gate 7437c478bd9Sstevel@tonic-gate static char * 7447c478bd9Sstevel@tonic-gate pvt_to_str(int pv_type) 7457c478bd9Sstevel@tonic-gate { 7467c478bd9Sstevel@tonic-gate assert(pv_type >= PROP_VAL_MIN && pv_type <= PROP_VAL_MAX); 7477c478bd9Sstevel@tonic-gate return (prop_val_types[pv_type]); 7487c478bd9Sstevel@tonic-gate } 7497c478bd9Sstevel@tonic-gate 7507c478bd9Sstevel@tonic-gate static char * 7517c478bd9Sstevel@tonic-gate cmd_to_str(int cmd_num) 7527c478bd9Sstevel@tonic-gate { 7537c478bd9Sstevel@tonic-gate assert(cmd_num >= CMD_MIN && cmd_num <= CMD_MAX); 7547c478bd9Sstevel@tonic-gate return (helptab[cmd_num].cmd_name); 7557c478bd9Sstevel@tonic-gate } 7567c478bd9Sstevel@tonic-gate 7577c478bd9Sstevel@tonic-gate /* 7587c478bd9Sstevel@tonic-gate * This is a separate function rather than a set of define's because of the 7597c478bd9Sstevel@tonic-gate * gettext() wrapping. 7607c478bd9Sstevel@tonic-gate */ 7617c478bd9Sstevel@tonic-gate 7627c478bd9Sstevel@tonic-gate /* 7637c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE 7647c478bd9Sstevel@tonic-gate * Each string below should have \t follow \n whenever needed; the 7657c478bd9Sstevel@tonic-gate * initial \t and the terminal \n will be provided by the calling function. 7667c478bd9Sstevel@tonic-gate */ 7677c478bd9Sstevel@tonic-gate 7687c478bd9Sstevel@tonic-gate static char * 7697c478bd9Sstevel@tonic-gate long_help(int cmd_num) 7707c478bd9Sstevel@tonic-gate { 7717c478bd9Sstevel@tonic-gate static char line[1024]; /* arbitrary large amount */ 7727c478bd9Sstevel@tonic-gate 7737c478bd9Sstevel@tonic-gate assert(cmd_num >= CMD_MIN && cmd_num <= CMD_MAX); 7747c478bd9Sstevel@tonic-gate switch (cmd_num) { 7757c478bd9Sstevel@tonic-gate case CMD_HELP: 7767c478bd9Sstevel@tonic-gate return (gettext("Prints help message.")); 7777c478bd9Sstevel@tonic-gate case CMD_CREATE: 7787c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), 7797c478bd9Sstevel@tonic-gate gettext("Creates a configuration for the " 7807c478bd9Sstevel@tonic-gate "specified zone. %s should be\n\tused to " 7817c478bd9Sstevel@tonic-gate "begin configuring a new zone. If overwriting an " 7827c478bd9Sstevel@tonic-gate "existing\n\tconfiguration, the -F flag can be " 7837c478bd9Sstevel@tonic-gate "used to force the action. If\n\t-t template is " 7847c478bd9Sstevel@tonic-gate "given, creates a configuration identical to the\n" 7857c478bd9Sstevel@tonic-gate "\tspecified template, except that the zone name " 7869e518655Sgjelinek "is changed from\n\ttemplate to zonename. '%s -a' " 7879e518655Sgjelinek "creates a configuration from a\n\tdetached " 7889e518655Sgjelinek "zonepath. '%s -b' results in a blank " 7899e518655Sgjelinek "configuration.\n\t'%s' with no arguments applies " 7909e518655Sgjelinek "the Sun default settings."), 7917c478bd9Sstevel@tonic-gate cmd_to_str(CMD_CREATE), cmd_to_str(CMD_CREATE), 7929e518655Sgjelinek cmd_to_str(CMD_CREATE), cmd_to_str(CMD_CREATE)); 7937c478bd9Sstevel@tonic-gate return (line); 7947c478bd9Sstevel@tonic-gate case CMD_EXIT: 7957c478bd9Sstevel@tonic-gate return (gettext("Exits the program. The -F flag can " 7967c478bd9Sstevel@tonic-gate "be used to force the action.")); 7977c478bd9Sstevel@tonic-gate case CMD_EXPORT: 7987c478bd9Sstevel@tonic-gate return (gettext("Prints configuration to standard " 7997c478bd9Sstevel@tonic-gate "output, or to output-file if\n\tspecified, in " 8007c478bd9Sstevel@tonic-gate "a form suitable for use in a command-file.")); 8017c478bd9Sstevel@tonic-gate case CMD_ADD: 8027c478bd9Sstevel@tonic-gate return (gettext("Add specified resource to " 8037c478bd9Sstevel@tonic-gate "configuration.")); 8047c478bd9Sstevel@tonic-gate case CMD_DELETE: 8057c478bd9Sstevel@tonic-gate return (gettext("Deletes the specified zone. The -F " 8067c478bd9Sstevel@tonic-gate "flag can be used to force the\n\taction.")); 8077c478bd9Sstevel@tonic-gate case CMD_REMOVE: 8087c478bd9Sstevel@tonic-gate return (gettext("Remove specified resource from " 8090209230bSgjelinek "configuration. The -F flag can be used\n\tto " 8100209230bSgjelinek "force the action.")); 8117c478bd9Sstevel@tonic-gate case CMD_SELECT: 8127c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), 8137c478bd9Sstevel@tonic-gate gettext("Selects a resource to modify. " 8147c478bd9Sstevel@tonic-gate "Resource modification is completed\n\twith the " 8157c478bd9Sstevel@tonic-gate "command \"%s\". The property name/value pairs " 8167c478bd9Sstevel@tonic-gate "must uniquely\n\tidentify a resource. Note that " 8177c478bd9Sstevel@tonic-gate "the curly braces ('{', '}') mean one\n\tor more " 8187c478bd9Sstevel@tonic-gate "of whatever is between them."), 8197c478bd9Sstevel@tonic-gate cmd_to_str(CMD_END)); 8207c478bd9Sstevel@tonic-gate return (line); 8217c478bd9Sstevel@tonic-gate case CMD_SET: 8227c478bd9Sstevel@tonic-gate return (gettext("Sets property values.")); 8230209230bSgjelinek case CMD_CLEAR: 8240209230bSgjelinek return (gettext("Clears property values.")); 8257c478bd9Sstevel@tonic-gate case CMD_INFO: 8267c478bd9Sstevel@tonic-gate return (gettext("Displays information about the " 8277c478bd9Sstevel@tonic-gate "current configuration. If resource\n\ttype is " 8287c478bd9Sstevel@tonic-gate "specified, displays only information about " 8297c478bd9Sstevel@tonic-gate "resources of\n\tthe relevant type. If resource " 8307c478bd9Sstevel@tonic-gate "id is specified, displays only\n\tinformation " 8317c478bd9Sstevel@tonic-gate "about that resource.")); 8327c478bd9Sstevel@tonic-gate case CMD_VERIFY: 8337c478bd9Sstevel@tonic-gate return (gettext("Verifies current configuration " 8347c478bd9Sstevel@tonic-gate "for correctness (some resource types\n\thave " 8357c478bd9Sstevel@tonic-gate "required properties).")); 8367c478bd9Sstevel@tonic-gate case CMD_COMMIT: 8377c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), 8387c478bd9Sstevel@tonic-gate gettext("Commits current configuration. " 8397c478bd9Sstevel@tonic-gate "Configuration must be committed to\n\tbe used by " 8407c478bd9Sstevel@tonic-gate "%s. Until the configuration is committed, " 8417c478bd9Sstevel@tonic-gate "changes \n\tcan be removed with the %s " 8427c478bd9Sstevel@tonic-gate "command. This operation is\n\tattempted " 8437c478bd9Sstevel@tonic-gate "automatically upon completion of a %s " 8447c478bd9Sstevel@tonic-gate "session."), "zoneadm", cmd_to_str(CMD_REVERT), 8457c478bd9Sstevel@tonic-gate "zonecfg"); 8467c478bd9Sstevel@tonic-gate return (line); 8477c478bd9Sstevel@tonic-gate case CMD_REVERT: 8487c478bd9Sstevel@tonic-gate return (gettext("Reverts configuration back to the " 8497c478bd9Sstevel@tonic-gate "last committed state. The -F flag\n\tcan be " 8507c478bd9Sstevel@tonic-gate "used to force the action.")); 8517c478bd9Sstevel@tonic-gate case CMD_CANCEL: 8527c478bd9Sstevel@tonic-gate return (gettext("Cancels resource/property " 8537c478bd9Sstevel@tonic-gate "specification.")); 8547c478bd9Sstevel@tonic-gate case CMD_END: 8557c478bd9Sstevel@tonic-gate return (gettext("Ends resource/property " 8567c478bd9Sstevel@tonic-gate "specification.")); 8577c478bd9Sstevel@tonic-gate } 8587c478bd9Sstevel@tonic-gate /* NOTREACHED */ 8597e362f58Scomay return (NULL); 8607c478bd9Sstevel@tonic-gate } 8617c478bd9Sstevel@tonic-gate 8627c478bd9Sstevel@tonic-gate /* 8637c478bd9Sstevel@tonic-gate * Called with verbose TRUE when help is explicitly requested, FALSE for 8647c478bd9Sstevel@tonic-gate * unexpected errors. 8657c478bd9Sstevel@tonic-gate */ 8667c478bd9Sstevel@tonic-gate 8677c478bd9Sstevel@tonic-gate void 868bbec428eSgjelinek usage(boolean_t verbose, uint_t flags) 8697c478bd9Sstevel@tonic-gate { 8707c478bd9Sstevel@tonic-gate FILE *fp = verbose ? stdout : stderr, *newfp; 871bbec428eSgjelinek boolean_t need_to_close = B_FALSE; 8727c478bd9Sstevel@tonic-gate char *pager; 8737c478bd9Sstevel@tonic-gate int i; 8747c478bd9Sstevel@tonic-gate 8757c478bd9Sstevel@tonic-gate /* don't page error output */ 8767c478bd9Sstevel@tonic-gate if (verbose && interactive_mode) { 8777c478bd9Sstevel@tonic-gate if ((pager = getenv("PAGER")) == NULL) 8787c478bd9Sstevel@tonic-gate pager = PAGER; 8797c478bd9Sstevel@tonic-gate if ((newfp = popen(pager, "w")) != NULL) { 880bbec428eSgjelinek need_to_close = B_TRUE; 8817c478bd9Sstevel@tonic-gate fp = newfp; 8827c478bd9Sstevel@tonic-gate } 8837c478bd9Sstevel@tonic-gate } 8847c478bd9Sstevel@tonic-gate if (flags & HELP_META) { 8857c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("More help is available for the " 8867c478bd9Sstevel@tonic-gate "following:\n")); 8877c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\n\tcommands ('%s commands')\n", 8887c478bd9Sstevel@tonic-gate cmd_to_str(CMD_HELP)); 8897c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\tsyntax ('%s syntax')\n", 8907c478bd9Sstevel@tonic-gate cmd_to_str(CMD_HELP)); 8917c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\tusage ('%s usage')\n\n", 8927c478bd9Sstevel@tonic-gate cmd_to_str(CMD_HELP)); 8937c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("You may also obtain help on any " 8947c478bd9Sstevel@tonic-gate "command by typing '%s <command-name>.'\n"), 8957c478bd9Sstevel@tonic-gate cmd_to_str(CMD_HELP)); 8967c478bd9Sstevel@tonic-gate } 8977c478bd9Sstevel@tonic-gate if (flags & HELP_RES_SCOPE) { 8987c478bd9Sstevel@tonic-gate switch (resource_scope) { 8997c478bd9Sstevel@tonic-gate case RT_FS: 9007c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is " 9017c478bd9Sstevel@tonic-gate "used to configure a file-system.\n"), 9027c478bd9Sstevel@tonic-gate rt_to_str(resource_scope)); 9037c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n")); 9047c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 9057c478bd9Sstevel@tonic-gate pt_to_str(PT_DIR), gettext("<path>")); 9067c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 9077c478bd9Sstevel@tonic-gate pt_to_str(PT_SPECIAL), gettext("<path>")); 9087c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 9097c478bd9Sstevel@tonic-gate pt_to_str(PT_RAW), gettext("<raw-device>")); 9107c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 9117c478bd9Sstevel@tonic-gate pt_to_str(PT_TYPE), gettext("<file-system type>")); 9127c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s %s\n", cmd_to_str(CMD_ADD), 9137c478bd9Sstevel@tonic-gate pt_to_str(PT_OPTIONS), 9147c478bd9Sstevel@tonic-gate gettext("<file-system options>")); 915ffbafc53Scomay (void) fprintf(fp, "\t%s %s %s\n", 916ffbafc53Scomay cmd_to_str(CMD_REMOVE), pt_to_str(PT_OPTIONS), 917ffbafc53Scomay gettext("<file-system options>")); 9187c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Consult the file-system " 9197c478bd9Sstevel@tonic-gate "specific manual page, such as mount_ufs(1M), " 9207c478bd9Sstevel@tonic-gate "for\ndetails about file-system options. Note " 9217c478bd9Sstevel@tonic-gate "that any file-system options with an\nembedded " 9227c478bd9Sstevel@tonic-gate "'=' character must be enclosed in double quotes, " 9237c478bd9Sstevel@tonic-gate /*CSTYLED*/ 9247c478bd9Sstevel@tonic-gate "such as \"%s=5\".\n"), MNTOPT_RETRY); 9257c478bd9Sstevel@tonic-gate break; 9267c478bd9Sstevel@tonic-gate case RT_IPD: 9277c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is " 9287c478bd9Sstevel@tonic-gate "used to configure a directory\ninherited from the " 9297c478bd9Sstevel@tonic-gate "global zone into a non-global zone in read-only " 9307c478bd9Sstevel@tonic-gate "mode.\n"), rt_to_str(resource_scope)); 9317c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n")); 9327c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 9337c478bd9Sstevel@tonic-gate pt_to_str(PT_DIR), gettext("<path>")); 9347c478bd9Sstevel@tonic-gate break; 9357c478bd9Sstevel@tonic-gate case RT_NET: 9367c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is " 9377c478bd9Sstevel@tonic-gate "used to configure a network interface.\n"), 9387c478bd9Sstevel@tonic-gate rt_to_str(resource_scope)); 9397c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n")); 9407c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 9417c478bd9Sstevel@tonic-gate pt_to_str(PT_ADDRESS), gettext("<IP-address>")); 9427c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 9437c478bd9Sstevel@tonic-gate pt_to_str(PT_PHYSICAL), gettext("<interface>")); 9447c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("See ifconfig(1M) for " 9457c478bd9Sstevel@tonic-gate "details of the <interface> string.\n")); 946de860bd9Sgfaden (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 947de860bd9Sgfaden pt_to_str(PT_DEFROUTER), gettext("<IP-address>")); 948de860bd9Sgfaden (void) fprintf(fp, gettext("%s %s and %s %s are valid " 949de860bd9Sgfaden "if the %s property is set to %s, otherwise they " 950de860bd9Sgfaden "must not be set.\n"), 951f4b3ec61Sdh155122 cmd_to_str(CMD_SET), pt_to_str(PT_ADDRESS), 952de860bd9Sgfaden cmd_to_str(CMD_SET), pt_to_str(PT_DEFROUTER), 953f4b3ec61Sdh155122 pt_to_str(PT_IPTYPE), "shared"); 9547c478bd9Sstevel@tonic-gate break; 9557c478bd9Sstevel@tonic-gate case RT_DEVICE: 9567c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is " 9577c478bd9Sstevel@tonic-gate "used to configure a device node.\n"), 9587c478bd9Sstevel@tonic-gate rt_to_str(resource_scope)); 9597c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n")); 9607c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 9617c478bd9Sstevel@tonic-gate pt_to_str(PT_MATCH), gettext("<device-path>")); 9627c478bd9Sstevel@tonic-gate break; 9637c478bd9Sstevel@tonic-gate case RT_RCTL: 9647c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is " 9657c478bd9Sstevel@tonic-gate "used to configure a resource control.\n"), 9667c478bd9Sstevel@tonic-gate rt_to_str(resource_scope)); 9677c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n")); 9687c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 9697c478bd9Sstevel@tonic-gate pt_to_str(PT_NAME), gettext("<string>")); 9707c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s (%s=%s,%s=%s,%s=%s)\n", 9717c478bd9Sstevel@tonic-gate cmd_to_str(CMD_ADD), pt_to_str(PT_VALUE), 9727c478bd9Sstevel@tonic-gate pt_to_str(PT_PRIV), gettext("<priv-value>"), 9737c478bd9Sstevel@tonic-gate pt_to_str(PT_LIMIT), gettext("<number>"), 9747c478bd9Sstevel@tonic-gate pt_to_str(PT_ACTION), gettext("<action-value>")); 975ffbafc53Scomay (void) fprintf(fp, "\t%s %s (%s=%s,%s=%s,%s=%s)\n", 976ffbafc53Scomay cmd_to_str(CMD_REMOVE), pt_to_str(PT_VALUE), 977ffbafc53Scomay pt_to_str(PT_PRIV), gettext("<priv-value>"), 978ffbafc53Scomay pt_to_str(PT_LIMIT), gettext("<number>"), 979ffbafc53Scomay pt_to_str(PT_ACTION), gettext("<action-value>")); 9807c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s\n\t%s := privileged\n" 9817c478bd9Sstevel@tonic-gate "\t%s := none | deny\n", gettext("Where"), 9827c478bd9Sstevel@tonic-gate gettext("<priv-value>"), gettext("<action-value>")); 9837c478bd9Sstevel@tonic-gate break; 9847c478bd9Sstevel@tonic-gate case RT_ATTR: 9857c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is " 9867c478bd9Sstevel@tonic-gate "used to configure a generic attribute.\n"), 9877c478bd9Sstevel@tonic-gate rt_to_str(resource_scope)); 9887c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n")); 9897c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 9907c478bd9Sstevel@tonic-gate pt_to_str(PT_NAME), gettext("<name>")); 9917c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=boolean\n", 9927c478bd9Sstevel@tonic-gate cmd_to_str(CMD_SET), pt_to_str(PT_TYPE)); 9937c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=true | false\n", 9947c478bd9Sstevel@tonic-gate cmd_to_str(CMD_SET), pt_to_str(PT_VALUE)); 9957c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("or\n")); 9967c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=int\n", cmd_to_str(CMD_SET), 9977c478bd9Sstevel@tonic-gate pt_to_str(PT_TYPE)); 9987c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 9997c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE), gettext("<integer>")); 10007c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("or\n")); 10017c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=string\n", 10027c478bd9Sstevel@tonic-gate cmd_to_str(CMD_SET), pt_to_str(PT_TYPE)); 10037c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 10047c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE), gettext("<string>")); 10057c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("or\n")); 10067c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=uint\n", 10077c478bd9Sstevel@tonic-gate cmd_to_str(CMD_SET), pt_to_str(PT_TYPE)); 10087c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 10097c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE), gettext("<unsigned integer>")); 10107c478bd9Sstevel@tonic-gate break; 1011fa9e4066Sahrens case RT_DATASET: 1012fa9e4066Sahrens (void) fprintf(fp, gettext("The '%s' resource scope is " 1013fa9e4066Sahrens "used to export ZFS datasets.\n"), 1014fa9e4066Sahrens rt_to_str(resource_scope)); 1015fa9e4066Sahrens (void) fprintf(fp, gettext("Valid commands:\n")); 1016fa9e4066Sahrens (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 1017fa9e4066Sahrens pt_to_str(PT_NAME), gettext("<name>")); 1018fa9e4066Sahrens break; 10190209230bSgjelinek case RT_DCPU: 10200209230bSgjelinek (void) fprintf(fp, gettext("The '%s' resource scope " 10210209230bSgjelinek "configures the 'pools' facility to dedicate\na " 10220209230bSgjelinek "subset of the system's processors to this zone " 10230209230bSgjelinek "while it is running.\n"), 10240209230bSgjelinek rt_to_str(resource_scope)); 10250209230bSgjelinek (void) fprintf(fp, gettext("Valid commands:\n")); 10260209230bSgjelinek (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 10270209230bSgjelinek pt_to_str(PT_NCPUS), 10280209230bSgjelinek gettext("<unsigned integer | range>")); 10290209230bSgjelinek (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 10300209230bSgjelinek pt_to_str(PT_IMPORTANCE), 10310209230bSgjelinek gettext("<unsigned integer>")); 10320209230bSgjelinek break; 1033c97ad5cdSakolb case RT_PCAP: 1034c97ad5cdSakolb (void) fprintf(fp, gettext("The '%s' resource scope is " 1035c97ad5cdSakolb "used to set an upper limit (a cap) on the\n" 1036c97ad5cdSakolb "percentage of CPU that can be used by this zone. " 1037c97ad5cdSakolb "A '%s' value of 1\ncorresponds to one cpu. The " 1038c97ad5cdSakolb "value can be set higher than 1, up to the total\n" 1039c97ad5cdSakolb "number of CPUs on the system. The value can " 1040c97ad5cdSakolb "also be less than 1,\nrepresenting a fraction of " 1041c97ad5cdSakolb "a cpu.\n"), 1042c97ad5cdSakolb rt_to_str(resource_scope), pt_to_str(PT_NCPUS)); 1043c97ad5cdSakolb (void) fprintf(fp, gettext("Valid commands:\n")); 1044c97ad5cdSakolb (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 1045c97ad5cdSakolb pt_to_str(PT_NCPUS), gettext("<unsigned decimal>")); 1046c97ad5cdSakolb break; 10470209230bSgjelinek case RT_MCAP: 10480209230bSgjelinek (void) fprintf(fp, gettext("The '%s' resource scope is " 10490209230bSgjelinek "used to set an upper limit (a cap) on the\n" 10500209230bSgjelinek "amount of physical memory, swap space and locked " 10510209230bSgjelinek "memory that can be used by\nthis zone.\n"), 10520209230bSgjelinek rt_to_str(resource_scope)); 10530209230bSgjelinek (void) fprintf(fp, gettext("Valid commands:\n")); 10540209230bSgjelinek (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 10550209230bSgjelinek pt_to_str(PT_PHYSICAL), 10560209230bSgjelinek gettext("<qualified unsigned decimal>")); 10570209230bSgjelinek (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 10580209230bSgjelinek pt_to_str(PT_SWAP), 10590209230bSgjelinek gettext("<qualified unsigned decimal>")); 10600209230bSgjelinek (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 10610209230bSgjelinek pt_to_str(PT_LOCKED), 10620209230bSgjelinek gettext("<qualified unsigned decimal>")); 10630209230bSgjelinek break; 10647c478bd9Sstevel@tonic-gate } 10657c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("And from any resource scope, you " 10667c478bd9Sstevel@tonic-gate "can:\n")); 10677c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", cmd_to_str(CMD_END), 10687c478bd9Sstevel@tonic-gate gettext("(to conclude this operation)")); 10697c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", cmd_to_str(CMD_CANCEL), 10707c478bd9Sstevel@tonic-gate gettext("(to cancel this operation)")); 10717c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", cmd_to_str(CMD_EXIT), 10727c478bd9Sstevel@tonic-gate gettext("(to exit the zonecfg utility)")); 10737c478bd9Sstevel@tonic-gate } 10747c478bd9Sstevel@tonic-gate if (flags & HELP_USAGE) { 10757c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\t%s %s\n", gettext("usage"), 10767c478bd9Sstevel@tonic-gate execname, cmd_to_str(CMD_HELP)); 10777c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s -z <zone>\t\t\t(%s)\n", 10787c478bd9Sstevel@tonic-gate execname, gettext("interactive")); 10797c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s -z <zone> <command>\n", execname); 10807c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s -z <zone> -f <command-file>\n", 10817c478bd9Sstevel@tonic-gate execname); 10827c478bd9Sstevel@tonic-gate } 10837c478bd9Sstevel@tonic-gate if (flags & HELP_SUBCMDS) { 10847c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n\n", gettext("Commands")); 10857c478bd9Sstevel@tonic-gate for (i = 0; i <= CMD_MAX; i++) { 10867c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s\n", helptab[i].short_usage); 10877c478bd9Sstevel@tonic-gate if (verbose) 10887c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\n\n", long_help(i)); 10897c478bd9Sstevel@tonic-gate } 10907c478bd9Sstevel@tonic-gate } 10917c478bd9Sstevel@tonic-gate if (flags & HELP_SYNTAX) { 10927c478bd9Sstevel@tonic-gate if (!verbose) 10937c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\n"); 10947c478bd9Sstevel@tonic-gate (void) fprintf(fp, "<zone> := [A-Za-z0-9][A-Za-z0-9_.-]*\n"); 10957c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("\t(except the reserved words " 10967c478bd9Sstevel@tonic-gate "'%s' and anything starting with '%s')\n"), "global", 10977c478bd9Sstevel@tonic-gate "SUNW"); 10987c478bd9Sstevel@tonic-gate (void) fprintf(fp, 10997c478bd9Sstevel@tonic-gate gettext("\tName must be less than %d characters.\n"), 11007c478bd9Sstevel@tonic-gate ZONENAME_MAX); 11017c478bd9Sstevel@tonic-gate if (verbose) 11027c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\n"); 11037c478bd9Sstevel@tonic-gate } 11047c478bd9Sstevel@tonic-gate if (flags & HELP_NETADDR) { 11057c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("\n<net-addr> :=")); 11067c478bd9Sstevel@tonic-gate (void) fprintf(fp, 11077c478bd9Sstevel@tonic-gate gettext("\t<IPv4-address>[/<IPv4-prefix-length>] |\n")); 11087c478bd9Sstevel@tonic-gate (void) fprintf(fp, 11097c478bd9Sstevel@tonic-gate gettext("\t\t<IPv6-address>/<IPv6-prefix-length> |\n")); 11107c478bd9Sstevel@tonic-gate (void) fprintf(fp, 11117c478bd9Sstevel@tonic-gate gettext("\t\t<hostname>[/<IPv4-prefix-length>]\n")); 11127c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("See inet(3SOCKET) for IPv4 and " 11137c478bd9Sstevel@tonic-gate "IPv6 address syntax.\n")); 11147c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("<IPv4-prefix-length> := [0-32]\n")); 11157c478bd9Sstevel@tonic-gate (void) fprintf(fp, 11167c478bd9Sstevel@tonic-gate gettext("<IPv6-prefix-length> := [0-128]\n")); 11177c478bd9Sstevel@tonic-gate (void) fprintf(fp, 11187c478bd9Sstevel@tonic-gate gettext("<hostname> := [A-Za-z0-9][A-Za-z0-9-.]*\n")); 11197c478bd9Sstevel@tonic-gate } 11207c478bd9Sstevel@tonic-gate if (flags & HELP_RESOURCES) { 11219e7542f4Sdp (void) fprintf(fp, "<%s> := %s | %s | %s | %s | %s | %s |\n\t" 1122c97ad5cdSakolb "%s | %s | %s | %s\n\n", 11237c478bd9Sstevel@tonic-gate gettext("resource type"), rt_to_str(RT_FS), 11247c478bd9Sstevel@tonic-gate rt_to_str(RT_IPD), rt_to_str(RT_NET), rt_to_str(RT_DEVICE), 11259e7542f4Sdp rt_to_str(RT_RCTL), rt_to_str(RT_ATTR), 11260209230bSgjelinek rt_to_str(RT_DATASET), rt_to_str(RT_DCPU), 1127c97ad5cdSakolb rt_to_str(RT_PCAP), rt_to_str(RT_MCAP)); 11287c478bd9Sstevel@tonic-gate } 11297c478bd9Sstevel@tonic-gate if (flags & HELP_PROPS) { 11307c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("For resource type ... there are " 11317c478bd9Sstevel@tonic-gate "property types ...:\n")); 11327c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 1133087719fdSdp pt_to_str(PT_ZONENAME)); 1134087719fdSdp (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11357c478bd9Sstevel@tonic-gate pt_to_str(PT_ZONEPATH)); 11367c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11379acbbeafSnn35248 pt_to_str(PT_BRAND)); 11389acbbeafSnn35248 (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11397c478bd9Sstevel@tonic-gate pt_to_str(PT_AUTOBOOT)); 11407c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11413f2f09c1Sdp pt_to_str(PT_BOOTARGS)); 11423f2f09c1Sdp (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11437c478bd9Sstevel@tonic-gate pt_to_str(PT_POOL)); 1144ffbafc53Scomay (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 1145ffbafc53Scomay pt_to_str(PT_LIMITPRIV)); 11460209230bSgjelinek (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11470209230bSgjelinek pt_to_str(PT_SCHED)); 11480209230bSgjelinek (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 1149f4b3ec61Sdh155122 pt_to_str(PT_IPTYPE)); 1150f4b3ec61Sdh155122 (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11515679c89fSjv227347 pt_to_str(PT_HOSTID)); 11525679c89fSjv227347 (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11530209230bSgjelinek pt_to_str(PT_MAXLWPS)); 11540209230bSgjelinek (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11550209230bSgjelinek pt_to_str(PT_MAXSHMMEM)); 11560209230bSgjelinek (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11570209230bSgjelinek pt_to_str(PT_MAXSHMIDS)); 11580209230bSgjelinek (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11590209230bSgjelinek pt_to_str(PT_MAXMSGIDS)); 11600209230bSgjelinek (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11610209230bSgjelinek pt_to_str(PT_MAXSEMIDS)); 11620209230bSgjelinek (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11630209230bSgjelinek pt_to_str(PT_SHARES)); 11647c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t\t%s, %s, %s, %s\n", rt_to_str(RT_FS), 11657c478bd9Sstevel@tonic-gate pt_to_str(PT_DIR), pt_to_str(PT_SPECIAL), 11667c478bd9Sstevel@tonic-gate pt_to_str(PT_RAW), pt_to_str(PT_TYPE), 11677c478bd9Sstevel@tonic-gate pt_to_str(PT_OPTIONS)); 11687c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", rt_to_str(RT_IPD), 11697c478bd9Sstevel@tonic-gate pt_to_str(PT_DIR)); 1170de860bd9Sgfaden (void) fprintf(fp, "\t%s\t\t%s, %s, %s\n", rt_to_str(RT_NET), 1171de860bd9Sgfaden pt_to_str(PT_ADDRESS), pt_to_str(PT_PHYSICAL), 1172de860bd9Sgfaden pt_to_str(PT_DEFROUTER)); 11737c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t\t%s\n", rt_to_str(RT_DEVICE), 11747c478bd9Sstevel@tonic-gate pt_to_str(PT_MATCH)); 11757c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t\t%s, %s\n", rt_to_str(RT_RCTL), 11767c478bd9Sstevel@tonic-gate pt_to_str(PT_NAME), pt_to_str(PT_VALUE)); 11777c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t\t%s, %s, %s\n", rt_to_str(RT_ATTR), 11787c478bd9Sstevel@tonic-gate pt_to_str(PT_NAME), pt_to_str(PT_TYPE), 11797c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE)); 1180fa9e4066Sahrens (void) fprintf(fp, "\t%s\t\t%s\n", rt_to_str(RT_DATASET), 1181fa9e4066Sahrens pt_to_str(PT_NAME)); 11820209230bSgjelinek (void) fprintf(fp, "\t%s\t%s, %s\n", rt_to_str(RT_DCPU), 11830209230bSgjelinek pt_to_str(PT_NCPUS), pt_to_str(PT_IMPORTANCE)); 1184c97ad5cdSakolb (void) fprintf(fp, "\t%s\t%s\n", rt_to_str(RT_PCAP), 1185c97ad5cdSakolb pt_to_str(PT_NCPUS)); 11860209230bSgjelinek (void) fprintf(fp, "\t%s\t%s, %s, %s\n", rt_to_str(RT_MCAP), 11870209230bSgjelinek pt_to_str(PT_PHYSICAL), pt_to_str(PT_SWAP), 11880209230bSgjelinek pt_to_str(PT_LOCKED)); 11897c478bd9Sstevel@tonic-gate } 11907c478bd9Sstevel@tonic-gate if (need_to_close) 11917c478bd9Sstevel@tonic-gate (void) pclose(fp); 11927c478bd9Sstevel@tonic-gate } 11937c478bd9Sstevel@tonic-gate 11947c478bd9Sstevel@tonic-gate /* PRINTFLIKE1 */ 11957c478bd9Sstevel@tonic-gate static void 11967c478bd9Sstevel@tonic-gate zerr(const char *fmt, ...) 11977c478bd9Sstevel@tonic-gate { 11987c478bd9Sstevel@tonic-gate va_list alist; 11997c478bd9Sstevel@tonic-gate static int last_lineno; 12007c478bd9Sstevel@tonic-gate 12017c478bd9Sstevel@tonic-gate /* lex_lineno has already been incremented in the lexer; compensate */ 12027c478bd9Sstevel@tonic-gate if (cmd_file_mode && lex_lineno > last_lineno) { 12037c478bd9Sstevel@tonic-gate if (strcmp(cmd_file_name, "-") == 0) 12047c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("On line %d:\n"), 12057c478bd9Sstevel@tonic-gate lex_lineno - 1); 12067c478bd9Sstevel@tonic-gate else 12077c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("On line %d of %s:\n"), 12087c478bd9Sstevel@tonic-gate lex_lineno - 1, cmd_file_name); 12097c478bd9Sstevel@tonic-gate last_lineno = lex_lineno; 12107c478bd9Sstevel@tonic-gate } 12117c478bd9Sstevel@tonic-gate va_start(alist, fmt); 12127c478bd9Sstevel@tonic-gate (void) vfprintf(stderr, fmt, alist); 12137c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "\n"); 12147c478bd9Sstevel@tonic-gate va_end(alist); 12157c478bd9Sstevel@tonic-gate } 12167c478bd9Sstevel@tonic-gate 12177c478bd9Sstevel@tonic-gate static void 1218bbec428eSgjelinek zone_perror(char *prefix, int err, boolean_t set_saw) 12197c478bd9Sstevel@tonic-gate { 12207c478bd9Sstevel@tonic-gate zerr("%s: %s", prefix, zonecfg_strerror(err)); 12217c478bd9Sstevel@tonic-gate if (set_saw) 1222bbec428eSgjelinek saw_error = B_TRUE; 12237c478bd9Sstevel@tonic-gate } 12247c478bd9Sstevel@tonic-gate 12257c478bd9Sstevel@tonic-gate /* 12267c478bd9Sstevel@tonic-gate * zone_perror() expects a single string, but for remove and select 12277c478bd9Sstevel@tonic-gate * we have both the command and the resource type, so this wrapper 12287c478bd9Sstevel@tonic-gate * function serves the same purpose in a slightly different way. 12297c478bd9Sstevel@tonic-gate */ 12307c478bd9Sstevel@tonic-gate 12317c478bd9Sstevel@tonic-gate static void 1232bbec428eSgjelinek z_cmd_rt_perror(int cmd_num, int res_num, int err, boolean_t set_saw) 12337c478bd9Sstevel@tonic-gate { 12347c478bd9Sstevel@tonic-gate zerr("%s %s: %s", cmd_to_str(cmd_num), rt_to_str(res_num), 12357c478bd9Sstevel@tonic-gate zonecfg_strerror(err)); 12367c478bd9Sstevel@tonic-gate if (set_saw) 1237bbec428eSgjelinek saw_error = B_TRUE; 12387c478bd9Sstevel@tonic-gate } 12397c478bd9Sstevel@tonic-gate 12407c478bd9Sstevel@tonic-gate /* returns Z_OK if successful, Z_foo from <libzonecfg.h> otherwise */ 12417c478bd9Sstevel@tonic-gate static int 1242bbec428eSgjelinek initialize(boolean_t handle_expected) 12437c478bd9Sstevel@tonic-gate { 12447c478bd9Sstevel@tonic-gate int err; 12459acbbeafSnn35248 char brandname[MAXNAMELEN]; 12467c478bd9Sstevel@tonic-gate 12477c478bd9Sstevel@tonic-gate if (zonecfg_check_handle(handle) != Z_OK) { 12487c478bd9Sstevel@tonic-gate if ((err = zonecfg_get_handle(zone, handle)) == Z_OK) { 1249bbec428eSgjelinek got_handle = B_TRUE; 12509acbbeafSnn35248 if (zonecfg_get_brand(handle, brandname, 12519acbbeafSnn35248 sizeof (brandname)) != Z_OK) { 12529acbbeafSnn35248 zerr("Zone %s is inconsistent: missing " 12539acbbeafSnn35248 "brand attribute", zone); 12549acbbeafSnn35248 exit(Z_ERR); 12559acbbeafSnn35248 } 12569acbbeafSnn35248 if ((brand = brand_open(brandname)) == NULL) { 12579acbbeafSnn35248 zerr("Zone %s uses non-existent brand \"%s\"." 12589acbbeafSnn35248 " Unable to continue", zone, brandname); 12599acbbeafSnn35248 exit(Z_ERR); 12609acbbeafSnn35248 } 12610209230bSgjelinek } else if (global_zone && err == Z_NO_ZONE && !got_handle && 12620209230bSgjelinek !read_only_mode) { 12630209230bSgjelinek /* 12640209230bSgjelinek * We implicitly create the global zone config if it 12650209230bSgjelinek * doesn't exist. 12660209230bSgjelinek */ 12670209230bSgjelinek zone_dochandle_t tmphandle; 12680209230bSgjelinek 12690209230bSgjelinek if ((tmphandle = zonecfg_init_handle()) == NULL) { 1270bbec428eSgjelinek zone_perror(execname, Z_NOMEM, B_TRUE); 12710209230bSgjelinek exit(Z_ERR); 12720209230bSgjelinek } 12730209230bSgjelinek 12740209230bSgjelinek err = zonecfg_get_template_handle("SUNWblank", zone, 12750209230bSgjelinek tmphandle); 12760209230bSgjelinek 12770209230bSgjelinek if (err != Z_OK) { 12780209230bSgjelinek zonecfg_fini_handle(tmphandle); 1279bbec428eSgjelinek zone_perror("SUNWblank", err, B_TRUE); 12800209230bSgjelinek return (err); 12810209230bSgjelinek } 12820209230bSgjelinek 1283bbec428eSgjelinek need_to_commit = B_TRUE; 12840209230bSgjelinek zonecfg_fini_handle(handle); 12850209230bSgjelinek handle = tmphandle; 1286bbec428eSgjelinek got_handle = B_TRUE; 12870209230bSgjelinek 12887c478bd9Sstevel@tonic-gate } else { 12897c478bd9Sstevel@tonic-gate zone_perror(zone, err, handle_expected || got_handle); 12907c478bd9Sstevel@tonic-gate if (err == Z_NO_ZONE && !got_handle && 12917c478bd9Sstevel@tonic-gate interactive_mode && !read_only_mode) 12927c478bd9Sstevel@tonic-gate (void) printf(gettext("Use '%s' to begin " 12937c478bd9Sstevel@tonic-gate "configuring a new zone.\n"), 12947c478bd9Sstevel@tonic-gate cmd_to_str(CMD_CREATE)); 12957c478bd9Sstevel@tonic-gate return (err); 12967c478bd9Sstevel@tonic-gate } 12977c478bd9Sstevel@tonic-gate } 12987c478bd9Sstevel@tonic-gate return (Z_OK); 12997c478bd9Sstevel@tonic-gate } 13007c478bd9Sstevel@tonic-gate 1301bbec428eSgjelinek static boolean_t 1302087719fdSdp state_atleast(zone_state_t state) 1303087719fdSdp { 1304087719fdSdp zone_state_t state_num; 1305087719fdSdp int err; 1306087719fdSdp 1307087719fdSdp if ((err = zone_get_state(zone, &state_num)) != Z_OK) { 1308087719fdSdp /* all states are greater than "non-existent" */ 1309087719fdSdp if (err == Z_NO_ZONE) 1310087719fdSdp return (B_FALSE); 1311087719fdSdp zerr(gettext("Unexpectedly failed to determine state " 1312087719fdSdp "of zone %s: %s"), zone, zonecfg_strerror(err)); 1313087719fdSdp exit(Z_ERR); 1314087719fdSdp } 1315087719fdSdp return (state_num >= state); 1316087719fdSdp } 1317087719fdSdp 13187c478bd9Sstevel@tonic-gate /* 13197c478bd9Sstevel@tonic-gate * short_usage() is for bad syntax: getopt() issues, too many arguments, etc. 13207c478bd9Sstevel@tonic-gate */ 13217c478bd9Sstevel@tonic-gate 13227c478bd9Sstevel@tonic-gate void 13237c478bd9Sstevel@tonic-gate short_usage(int command) 13247c478bd9Sstevel@tonic-gate { 13257c478bd9Sstevel@tonic-gate /* lex_lineno has already been incremented in the lexer; compensate */ 13267c478bd9Sstevel@tonic-gate if (cmd_file_mode) { 13277c478bd9Sstevel@tonic-gate if (strcmp(cmd_file_name, "-") == 0) 13287c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 13297c478bd9Sstevel@tonic-gate gettext("syntax error on line %d\n"), 13307c478bd9Sstevel@tonic-gate lex_lineno - 1); 13317c478bd9Sstevel@tonic-gate else 13327c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 13337c478bd9Sstevel@tonic-gate gettext("syntax error on line %d of %s\n"), 13347c478bd9Sstevel@tonic-gate lex_lineno - 1, cmd_file_name); 13357c478bd9Sstevel@tonic-gate } 13367c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s:\n%s\n", gettext("usage"), 13377c478bd9Sstevel@tonic-gate helptab[command].short_usage); 1338bbec428eSgjelinek saw_error = B_TRUE; 13397c478bd9Sstevel@tonic-gate } 13407c478bd9Sstevel@tonic-gate 13417c478bd9Sstevel@tonic-gate /* 13427c478bd9Sstevel@tonic-gate * long_usage() is for bad semantics: e.g., wrong property type for a given 13437c478bd9Sstevel@tonic-gate * resource type. It is also used by longer_usage() below. 13447c478bd9Sstevel@tonic-gate */ 13457c478bd9Sstevel@tonic-gate 13467c478bd9Sstevel@tonic-gate void 1347bbec428eSgjelinek long_usage(uint_t cmd_num, boolean_t set_saw) 13487c478bd9Sstevel@tonic-gate { 13497c478bd9Sstevel@tonic-gate (void) fprintf(set_saw ? stderr : stdout, "%s:\n%s\n", gettext("usage"), 13507c478bd9Sstevel@tonic-gate helptab[cmd_num].short_usage); 13517c478bd9Sstevel@tonic-gate (void) fprintf(set_saw ? stderr : stdout, "\t%s\n", long_help(cmd_num)); 13527c478bd9Sstevel@tonic-gate if (set_saw) 1353bbec428eSgjelinek saw_error = B_TRUE; 13547c478bd9Sstevel@tonic-gate } 13557c478bd9Sstevel@tonic-gate 13567c478bd9Sstevel@tonic-gate /* 13577c478bd9Sstevel@tonic-gate * longer_usage() is for 'help foo' and 'foo -?': call long_usage() and also 13587c478bd9Sstevel@tonic-gate * any extra usage() flags as appropriate for whatever command. 13597c478bd9Sstevel@tonic-gate */ 13607c478bd9Sstevel@tonic-gate 13617c478bd9Sstevel@tonic-gate void 13627c478bd9Sstevel@tonic-gate longer_usage(uint_t cmd_num) 13637c478bd9Sstevel@tonic-gate { 1364bbec428eSgjelinek long_usage(cmd_num, B_FALSE); 13657c478bd9Sstevel@tonic-gate if (helptab[cmd_num].flags != 0) { 13667c478bd9Sstevel@tonic-gate (void) printf("\n"); 1367bbec428eSgjelinek usage(B_TRUE, helptab[cmd_num].flags); 13687c478bd9Sstevel@tonic-gate } 13697c478bd9Sstevel@tonic-gate } 13707c478bd9Sstevel@tonic-gate 13717c478bd9Sstevel@tonic-gate /* 13727c478bd9Sstevel@tonic-gate * scope_usage() is simply used when a command is called from the wrong scope. 13737c478bd9Sstevel@tonic-gate */ 13747c478bd9Sstevel@tonic-gate 13757c478bd9Sstevel@tonic-gate static void 13767c478bd9Sstevel@tonic-gate scope_usage(uint_t cmd_num) 13777c478bd9Sstevel@tonic-gate { 13787c478bd9Sstevel@tonic-gate zerr(gettext("The %s command only makes sense in the %s scope."), 13797c478bd9Sstevel@tonic-gate cmd_to_str(cmd_num), 13807c478bd9Sstevel@tonic-gate global_scope ? gettext("resource") : gettext("global")); 1381bbec428eSgjelinek saw_error = B_TRUE; 13827c478bd9Sstevel@tonic-gate } 13837c478bd9Sstevel@tonic-gate 13847c478bd9Sstevel@tonic-gate /* 1385bbec428eSgjelinek * On input, B_TRUE => yes, B_FALSE => no. 1386bbec428eSgjelinek * On return, B_TRUE => 1, B_FALSE => no, could not ask => -1. 13877c478bd9Sstevel@tonic-gate */ 13887c478bd9Sstevel@tonic-gate 13897c478bd9Sstevel@tonic-gate static int 1390bbec428eSgjelinek ask_yesno(boolean_t default_answer, const char *question) 13917c478bd9Sstevel@tonic-gate { 13927c478bd9Sstevel@tonic-gate char line[64]; /* should be enough to answer yes or no */ 13937c478bd9Sstevel@tonic-gate 13947c478bd9Sstevel@tonic-gate if (!ok_to_prompt) { 1395bbec428eSgjelinek saw_error = B_TRUE; 13967c478bd9Sstevel@tonic-gate return (-1); 13977c478bd9Sstevel@tonic-gate } 13987c478bd9Sstevel@tonic-gate for (;;) { 1399087719fdSdp if (printf("%s (%s)? ", question, 1400087719fdSdp default_answer ? "[y]/n" : "y/[n]") < 0) 1401087719fdSdp return (-1); 1402087719fdSdp if (fgets(line, sizeof (line), stdin) == NULL) 1403087719fdSdp return (-1); 1404087719fdSdp 1405087719fdSdp if (line[0] == '\n') 14067c478bd9Sstevel@tonic-gate return (default_answer ? 1 : 0); 14077c478bd9Sstevel@tonic-gate if (tolower(line[0]) == 'y') 14087c478bd9Sstevel@tonic-gate return (1); 14097c478bd9Sstevel@tonic-gate if (tolower(line[0]) == 'n') 14107c478bd9Sstevel@tonic-gate return (0); 14117c478bd9Sstevel@tonic-gate } 14127c478bd9Sstevel@tonic-gate } 14137c478bd9Sstevel@tonic-gate 14147c478bd9Sstevel@tonic-gate /* 14157c478bd9Sstevel@tonic-gate * Prints warning if zone already exists. 14167c478bd9Sstevel@tonic-gate * In interactive mode, prompts if we should continue anyway and returns Z_OK 14177c478bd9Sstevel@tonic-gate * if so, Z_ERR if not. In non-interactive mode, exits with Z_ERR. 14187c478bd9Sstevel@tonic-gate * 14197c478bd9Sstevel@tonic-gate * Note that if a zone exists and its state is >= INSTALLED, an error message 14207c478bd9Sstevel@tonic-gate * will be printed and this function will return Z_ERR regardless of mode. 14217c478bd9Sstevel@tonic-gate */ 14227c478bd9Sstevel@tonic-gate 14237c478bd9Sstevel@tonic-gate static int 1424bbec428eSgjelinek check_if_zone_already_exists(boolean_t force) 14257c478bd9Sstevel@tonic-gate { 14267c478bd9Sstevel@tonic-gate char line[ZONENAME_MAX + 128]; /* enough to ask a question */ 14277c478bd9Sstevel@tonic-gate zone_dochandle_t tmphandle; 14287c478bd9Sstevel@tonic-gate int res, answer; 14297c478bd9Sstevel@tonic-gate 14307c478bd9Sstevel@tonic-gate if ((tmphandle = zonecfg_init_handle()) == NULL) { 1431bbec428eSgjelinek zone_perror(execname, Z_NOMEM, B_TRUE); 14327c478bd9Sstevel@tonic-gate exit(Z_ERR); 14337c478bd9Sstevel@tonic-gate } 14347c478bd9Sstevel@tonic-gate res = zonecfg_get_handle(zone, tmphandle); 14357c478bd9Sstevel@tonic-gate zonecfg_fini_handle(tmphandle); 1436087719fdSdp if (res != Z_OK) 14377c478bd9Sstevel@tonic-gate return (Z_OK); 1438087719fdSdp 1439087719fdSdp if (state_atleast(ZONE_STATE_INSTALLED)) { 14407c478bd9Sstevel@tonic-gate zerr(gettext("Zone %s already installed; %s not allowed."), 14417c478bd9Sstevel@tonic-gate zone, cmd_to_str(CMD_CREATE)); 14427c478bd9Sstevel@tonic-gate return (Z_ERR); 14437c478bd9Sstevel@tonic-gate } 14447c478bd9Sstevel@tonic-gate 14457c478bd9Sstevel@tonic-gate if (force) { 14467c478bd9Sstevel@tonic-gate (void) printf(gettext("Zone %s already exists; overwriting.\n"), 14477c478bd9Sstevel@tonic-gate zone); 14487c478bd9Sstevel@tonic-gate return (Z_OK); 14497c478bd9Sstevel@tonic-gate } 14507c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), 14517c478bd9Sstevel@tonic-gate gettext("Zone %s already exists; %s anyway"), zone, 14527c478bd9Sstevel@tonic-gate cmd_to_str(CMD_CREATE)); 1453bbec428eSgjelinek if ((answer = ask_yesno(B_FALSE, line)) == -1) { 14547c478bd9Sstevel@tonic-gate zerr(gettext("Zone exists, input not from terminal and -F not " 14557c478bd9Sstevel@tonic-gate "specified:\n%s command ignored, exiting."), 14567c478bd9Sstevel@tonic-gate cmd_to_str(CMD_CREATE)); 14577c478bd9Sstevel@tonic-gate exit(Z_ERR); 14587c478bd9Sstevel@tonic-gate } 14597c478bd9Sstevel@tonic-gate return (answer == 1 ? Z_OK : Z_ERR); 14607c478bd9Sstevel@tonic-gate } 14617c478bd9Sstevel@tonic-gate 1462bbec428eSgjelinek static boolean_t 14637c478bd9Sstevel@tonic-gate zone_is_read_only(int cmd_num) 14647c478bd9Sstevel@tonic-gate { 14657c478bd9Sstevel@tonic-gate if (strncmp(zone, "SUNW", 4) == 0) { 14667c478bd9Sstevel@tonic-gate zerr(gettext("%s: zones beginning with SUNW are read-only."), 14677c478bd9Sstevel@tonic-gate zone); 1468bbec428eSgjelinek saw_error = B_TRUE; 1469bbec428eSgjelinek return (B_TRUE); 14707c478bd9Sstevel@tonic-gate } 14717c478bd9Sstevel@tonic-gate if (read_only_mode) { 14727c478bd9Sstevel@tonic-gate zerr(gettext("%s: cannot %s in read-only mode."), zone, 14737c478bd9Sstevel@tonic-gate cmd_to_str(cmd_num)); 1474bbec428eSgjelinek saw_error = B_TRUE; 1475bbec428eSgjelinek return (B_TRUE); 14767c478bd9Sstevel@tonic-gate } 1477bbec428eSgjelinek return (B_FALSE); 14787c478bd9Sstevel@tonic-gate } 14797c478bd9Sstevel@tonic-gate 14807c478bd9Sstevel@tonic-gate /* 14817c478bd9Sstevel@tonic-gate * Create a new configuration. 14827c478bd9Sstevel@tonic-gate */ 14837c478bd9Sstevel@tonic-gate void 14847c478bd9Sstevel@tonic-gate create_func(cmd_t *cmd) 14857c478bd9Sstevel@tonic-gate { 14867c478bd9Sstevel@tonic-gate int err, arg; 14877c478bd9Sstevel@tonic-gate char zone_template[ZONENAME_MAX]; 1488ee519a1fSgjelinek char attach_path[MAXPATHLEN]; 14897c478bd9Sstevel@tonic-gate zone_dochandle_t tmphandle; 1490bbec428eSgjelinek boolean_t force = B_FALSE; 1491bbec428eSgjelinek boolean_t attach = B_FALSE; 1492bbec428eSgjelinek boolean_t arg_err = B_FALSE; 14937c478bd9Sstevel@tonic-gate 14947c478bd9Sstevel@tonic-gate assert(cmd != NULL); 14957c478bd9Sstevel@tonic-gate 14967c478bd9Sstevel@tonic-gate /* This is the default if no arguments are given. */ 14977c478bd9Sstevel@tonic-gate (void) strlcpy(zone_template, "SUNWdefault", sizeof (zone_template)); 14987c478bd9Sstevel@tonic-gate 14997c478bd9Sstevel@tonic-gate optind = 0; 15009acbbeafSnn35248 while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?a:bFt:")) 15019acbbeafSnn35248 != EOF) { 15027c478bd9Sstevel@tonic-gate switch (arg) { 15037c478bd9Sstevel@tonic-gate case '?': 15047c478bd9Sstevel@tonic-gate if (optopt == '?') 15057c478bd9Sstevel@tonic-gate longer_usage(CMD_CREATE); 15067c478bd9Sstevel@tonic-gate else 15077c478bd9Sstevel@tonic-gate short_usage(CMD_CREATE); 1508bbec428eSgjelinek arg_err = B_TRUE; 15097ec75eb8Sgjelinek break; 1510ee519a1fSgjelinek case 'a': 1511ee519a1fSgjelinek (void) strlcpy(attach_path, optarg, 1512ee519a1fSgjelinek sizeof (attach_path)); 1513bbec428eSgjelinek attach = B_TRUE; 1514ee519a1fSgjelinek break; 15157c478bd9Sstevel@tonic-gate case 'b': 15167c478bd9Sstevel@tonic-gate (void) strlcpy(zone_template, "SUNWblank", 15177c478bd9Sstevel@tonic-gate sizeof (zone_template)); 15187c478bd9Sstevel@tonic-gate break; 15197c478bd9Sstevel@tonic-gate case 'F': 1520bbec428eSgjelinek force = B_TRUE; 15217c478bd9Sstevel@tonic-gate break; 15227c478bd9Sstevel@tonic-gate case 't': 15237c478bd9Sstevel@tonic-gate (void) strlcpy(zone_template, optarg, 15247c478bd9Sstevel@tonic-gate sizeof (zone_template)); 15257c478bd9Sstevel@tonic-gate break; 15267c478bd9Sstevel@tonic-gate default: 15277c478bd9Sstevel@tonic-gate short_usage(CMD_CREATE); 1528bbec428eSgjelinek arg_err = B_TRUE; 15297ec75eb8Sgjelinek break; 15307ec75eb8Sgjelinek } 15317ec75eb8Sgjelinek } 15327ec75eb8Sgjelinek if (arg_err) 15337c478bd9Sstevel@tonic-gate return; 15347ec75eb8Sgjelinek 15357c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 15367c478bd9Sstevel@tonic-gate short_usage(CMD_CREATE); 15377c478bd9Sstevel@tonic-gate return; 15387c478bd9Sstevel@tonic-gate } 15397c478bd9Sstevel@tonic-gate 15407c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_CREATE)) 15417c478bd9Sstevel@tonic-gate return; 15427c478bd9Sstevel@tonic-gate 15437c478bd9Sstevel@tonic-gate if (check_if_zone_already_exists(force) != Z_OK) 15447c478bd9Sstevel@tonic-gate return; 15457c478bd9Sstevel@tonic-gate 15467c478bd9Sstevel@tonic-gate /* 15477c478bd9Sstevel@tonic-gate * Get a temporary handle first. If that fails, the old handle 15487c478bd9Sstevel@tonic-gate * will not be lost. Then finish whichever one we don't need, 15497c478bd9Sstevel@tonic-gate * to avoid leaks. Then get the handle for zone_template, and 15507c478bd9Sstevel@tonic-gate * set the name to zone: this "copy, rename" method is how 15517c478bd9Sstevel@tonic-gate * create -[b|t] works. 15527c478bd9Sstevel@tonic-gate */ 15537c478bd9Sstevel@tonic-gate if ((tmphandle = zonecfg_init_handle()) == NULL) { 1554bbec428eSgjelinek zone_perror(execname, Z_NOMEM, B_TRUE); 15557c478bd9Sstevel@tonic-gate exit(Z_ERR); 15567c478bd9Sstevel@tonic-gate } 1557ee519a1fSgjelinek 1558ee519a1fSgjelinek if (attach) 155916ab8c7bSgjelinek err = zonecfg_get_attach_handle(attach_path, ZONE_DETACHED, 156016ab8c7bSgjelinek zone, B_FALSE, tmphandle); 1561ee519a1fSgjelinek else 1562ee519a1fSgjelinek err = zonecfg_get_template_handle(zone_template, zone, 1563ee519a1fSgjelinek tmphandle); 1564ee519a1fSgjelinek 1565ee519a1fSgjelinek if (err != Z_OK) { 15667c478bd9Sstevel@tonic-gate zonecfg_fini_handle(tmphandle); 1567ee519a1fSgjelinek if (attach && err == Z_NO_ZONE) 1568ee519a1fSgjelinek (void) fprintf(stderr, gettext("invalid path to " 1569ee519a1fSgjelinek "detached zone\n")); 1570ee519a1fSgjelinek else if (attach && err == Z_INVALID_DOCUMENT) 1571ee519a1fSgjelinek (void) fprintf(stderr, gettext("Cannot attach to an " 1572ee519a1fSgjelinek "earlier release of the operating system\n")); 1573ee519a1fSgjelinek else 1574bbec428eSgjelinek zone_perror(zone_template, err, B_TRUE); 15757c478bd9Sstevel@tonic-gate return; 15767c478bd9Sstevel@tonic-gate } 1577087719fdSdp 1578bbec428eSgjelinek need_to_commit = B_TRUE; 15797c478bd9Sstevel@tonic-gate zonecfg_fini_handle(handle); 15807c478bd9Sstevel@tonic-gate handle = tmphandle; 1581bbec428eSgjelinek got_handle = B_TRUE; 15827c478bd9Sstevel@tonic-gate } 15837c478bd9Sstevel@tonic-gate 15847c478bd9Sstevel@tonic-gate /* 15857c478bd9Sstevel@tonic-gate * This malloc()'s memory, which must be freed by the caller. 15867c478bd9Sstevel@tonic-gate */ 15877c478bd9Sstevel@tonic-gate static char * 15887c478bd9Sstevel@tonic-gate quoteit(char *instr) 15897c478bd9Sstevel@tonic-gate { 15907c478bd9Sstevel@tonic-gate char *outstr; 15917c478bd9Sstevel@tonic-gate size_t outstrsize = strlen(instr) + 3; /* 2 quotes + '\0' */ 15927c478bd9Sstevel@tonic-gate 15937c478bd9Sstevel@tonic-gate if ((outstr = malloc(outstrsize)) == NULL) { 1594bbec428eSgjelinek zone_perror(zone, Z_NOMEM, B_FALSE); 15957c478bd9Sstevel@tonic-gate exit(Z_ERR); 15967c478bd9Sstevel@tonic-gate } 15977c478bd9Sstevel@tonic-gate if (strchr(instr, ' ') == NULL) { 15987c478bd9Sstevel@tonic-gate (void) strlcpy(outstr, instr, outstrsize); 15997c478bd9Sstevel@tonic-gate return (outstr); 16007c478bd9Sstevel@tonic-gate } 16017c478bd9Sstevel@tonic-gate (void) snprintf(outstr, outstrsize, "\"%s\"", instr); 16027c478bd9Sstevel@tonic-gate return (outstr); 16037c478bd9Sstevel@tonic-gate } 16047c478bd9Sstevel@tonic-gate 16057c478bd9Sstevel@tonic-gate static void 16067c478bd9Sstevel@tonic-gate export_prop(FILE *of, int prop_num, char *prop_id) 16077c478bd9Sstevel@tonic-gate { 16087c478bd9Sstevel@tonic-gate char *quote_str; 16097c478bd9Sstevel@tonic-gate 16107c478bd9Sstevel@tonic-gate if (strlen(prop_id) == 0) 16117c478bd9Sstevel@tonic-gate return; 16127c478bd9Sstevel@tonic-gate quote_str = quoteit(prop_id); 16137c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 16147c478bd9Sstevel@tonic-gate pt_to_str(prop_num), quote_str); 16157c478bd9Sstevel@tonic-gate free(quote_str); 16167c478bd9Sstevel@tonic-gate } 16177c478bd9Sstevel@tonic-gate 16187c478bd9Sstevel@tonic-gate void 16197c478bd9Sstevel@tonic-gate export_func(cmd_t *cmd) 16207c478bd9Sstevel@tonic-gate { 16217c478bd9Sstevel@tonic-gate struct zone_nwiftab nwiftab; 16227c478bd9Sstevel@tonic-gate struct zone_fstab fstab; 16237c478bd9Sstevel@tonic-gate struct zone_devtab devtab; 16247c478bd9Sstevel@tonic-gate struct zone_attrtab attrtab; 16257c478bd9Sstevel@tonic-gate struct zone_rctltab rctltab; 1626fa9e4066Sahrens struct zone_dstab dstab; 16270209230bSgjelinek struct zone_psettab psettab; 16280209230bSgjelinek struct zone_mcaptab mcaptab; 16297c478bd9Sstevel@tonic-gate struct zone_rctlvaltab *valptr; 16307c478bd9Sstevel@tonic-gate int err, arg; 16317c478bd9Sstevel@tonic-gate char zonepath[MAXPATHLEN], outfile[MAXPATHLEN], pool[MAXNAMELEN]; 16323f2f09c1Sdp char bootargs[BOOTARGS_MAX]; 16330209230bSgjelinek char sched[MAXNAMELEN]; 16349acbbeafSnn35248 char brand[MAXNAMELEN]; 16355679c89fSjv227347 char hostidp[HW_HOSTID_LEN]; 1636ffbafc53Scomay char *limitpriv; 16377c478bd9Sstevel@tonic-gate FILE *of; 16387c478bd9Sstevel@tonic-gate boolean_t autoboot; 1639f4b3ec61Sdh155122 zone_iptype_t iptype; 1640bbec428eSgjelinek boolean_t need_to_close = B_FALSE; 1641bbec428eSgjelinek boolean_t arg_err = B_FALSE; 16427c478bd9Sstevel@tonic-gate 16437c478bd9Sstevel@tonic-gate assert(cmd != NULL); 16447c478bd9Sstevel@tonic-gate 16457c478bd9Sstevel@tonic-gate outfile[0] = '\0'; 16467c478bd9Sstevel@tonic-gate optind = 0; 16477c478bd9Sstevel@tonic-gate while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?f:")) != EOF) { 16487c478bd9Sstevel@tonic-gate switch (arg) { 16497c478bd9Sstevel@tonic-gate case '?': 16507c478bd9Sstevel@tonic-gate if (optopt == '?') 16517c478bd9Sstevel@tonic-gate longer_usage(CMD_EXPORT); 16527c478bd9Sstevel@tonic-gate else 16537c478bd9Sstevel@tonic-gate short_usage(CMD_EXPORT); 1654bbec428eSgjelinek arg_err = B_TRUE; 16557ec75eb8Sgjelinek break; 16567c478bd9Sstevel@tonic-gate case 'f': 16577c478bd9Sstevel@tonic-gate (void) strlcpy(outfile, optarg, sizeof (outfile)); 16587c478bd9Sstevel@tonic-gate break; 16597c478bd9Sstevel@tonic-gate default: 16607c478bd9Sstevel@tonic-gate short_usage(CMD_EXPORT); 1661bbec428eSgjelinek arg_err = B_TRUE; 16627ec75eb8Sgjelinek break; 16637ec75eb8Sgjelinek } 16647ec75eb8Sgjelinek } 16657ec75eb8Sgjelinek if (arg_err) 16667c478bd9Sstevel@tonic-gate return; 16677ec75eb8Sgjelinek 16687c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 16697c478bd9Sstevel@tonic-gate short_usage(CMD_EXPORT); 16707c478bd9Sstevel@tonic-gate return; 16717c478bd9Sstevel@tonic-gate } 16727c478bd9Sstevel@tonic-gate if (strlen(outfile) == 0) { 16737c478bd9Sstevel@tonic-gate of = stdout; 16747c478bd9Sstevel@tonic-gate } else { 16757c478bd9Sstevel@tonic-gate if ((of = fopen(outfile, "w")) == NULL) { 16767c478bd9Sstevel@tonic-gate zerr(gettext("opening file %s: %s"), 16777c478bd9Sstevel@tonic-gate outfile, strerror(errno)); 16787c478bd9Sstevel@tonic-gate goto done; 16797c478bd9Sstevel@tonic-gate } 16807c478bd9Sstevel@tonic-gate setbuf(of, NULL); 1681bbec428eSgjelinek need_to_close = B_TRUE; 16827c478bd9Sstevel@tonic-gate } 16837c478bd9Sstevel@tonic-gate 1684bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK) 16857c478bd9Sstevel@tonic-gate goto done; 16867c478bd9Sstevel@tonic-gate 16877c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s -b\n", cmd_to_str(CMD_CREATE)); 16887c478bd9Sstevel@tonic-gate 16897c478bd9Sstevel@tonic-gate if (zonecfg_get_zonepath(handle, zonepath, sizeof (zonepath)) == Z_OK && 16907c478bd9Sstevel@tonic-gate strlen(zonepath) > 0) 16917c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 16927c478bd9Sstevel@tonic-gate pt_to_str(PT_ZONEPATH), zonepath); 16937c478bd9Sstevel@tonic-gate 16949acbbeafSnn35248 if ((zone_get_brand(zone, brand, sizeof (brand)) == Z_OK) && 16959acbbeafSnn35248 (strcmp(brand, NATIVE_BRAND_NAME) != 0)) 16969acbbeafSnn35248 (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 16979acbbeafSnn35248 pt_to_str(PT_BRAND), brand); 16989acbbeafSnn35248 16997c478bd9Sstevel@tonic-gate if (zonecfg_get_autoboot(handle, &autoboot) == Z_OK) 17007c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 17017c478bd9Sstevel@tonic-gate pt_to_str(PT_AUTOBOOT), autoboot ? "true" : "false"); 17027c478bd9Sstevel@tonic-gate 17033f2f09c1Sdp if (zonecfg_get_bootargs(handle, bootargs, sizeof (bootargs)) == Z_OK && 17043f2f09c1Sdp strlen(bootargs) > 0) { 17053f2f09c1Sdp (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 17063f2f09c1Sdp pt_to_str(PT_BOOTARGS), bootargs); 17073f2f09c1Sdp } 17083f2f09c1Sdp 17097c478bd9Sstevel@tonic-gate if (zonecfg_get_pool(handle, pool, sizeof (pool)) == Z_OK && 17107c478bd9Sstevel@tonic-gate strlen(pool) > 0) 17117c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 17127c478bd9Sstevel@tonic-gate pt_to_str(PT_POOL), pool); 17137c478bd9Sstevel@tonic-gate 1714ffbafc53Scomay if (zonecfg_get_limitpriv(handle, &limitpriv) == Z_OK && 1715ffbafc53Scomay strlen(limitpriv) > 0) { 1716ffbafc53Scomay (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 1717ffbafc53Scomay pt_to_str(PT_LIMITPRIV), limitpriv); 1718ffbafc53Scomay free(limitpriv); 1719ffbafc53Scomay } 1720ffbafc53Scomay 17210209230bSgjelinek if (zonecfg_get_sched_class(handle, sched, sizeof (sched)) == Z_OK && 17220209230bSgjelinek strlen(sched) > 0) 17230209230bSgjelinek (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 17240209230bSgjelinek pt_to_str(PT_SCHED), sched); 17253f2f09c1Sdp 1726f4b3ec61Sdh155122 if (zonecfg_get_iptype(handle, &iptype) == Z_OK) { 1727f4b3ec61Sdh155122 switch (iptype) { 1728f4b3ec61Sdh155122 case ZS_SHARED: 1729f4b3ec61Sdh155122 (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 1730f4b3ec61Sdh155122 pt_to_str(PT_IPTYPE), "shared"); 1731f4b3ec61Sdh155122 break; 1732f4b3ec61Sdh155122 case ZS_EXCLUSIVE: 1733f4b3ec61Sdh155122 (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 1734f4b3ec61Sdh155122 pt_to_str(PT_IPTYPE), "exclusive"); 1735f4b3ec61Sdh155122 break; 1736f4b3ec61Sdh155122 } 1737f4b3ec61Sdh155122 } 1738f4b3ec61Sdh155122 17395679c89fSjv227347 if (zonecfg_get_hostid(handle, hostidp, sizeof (hostidp)) == Z_OK) { 17405679c89fSjv227347 (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 17415679c89fSjv227347 pt_to_str(PT_HOSTID), hostidp); 17425679c89fSjv227347 } 17435679c89fSjv227347 17447c478bd9Sstevel@tonic-gate if ((err = zonecfg_setipdent(handle)) != Z_OK) { 1745bbec428eSgjelinek zone_perror(zone, err, B_FALSE); 17467c478bd9Sstevel@tonic-gate goto done; 17477c478bd9Sstevel@tonic-gate } 17487c478bd9Sstevel@tonic-gate while (zonecfg_getipdent(handle, &fstab) == Z_OK) { 17497c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 17507c478bd9Sstevel@tonic-gate rt_to_str(RT_IPD)); 17517c478bd9Sstevel@tonic-gate export_prop(of, PT_DIR, fstab.zone_fs_dir); 17527c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 17537c478bd9Sstevel@tonic-gate } 17547c478bd9Sstevel@tonic-gate (void) zonecfg_endipdent(handle); 17557c478bd9Sstevel@tonic-gate 17567c478bd9Sstevel@tonic-gate if ((err = zonecfg_setfsent(handle)) != Z_OK) { 1757bbec428eSgjelinek zone_perror(zone, err, B_FALSE); 17587c478bd9Sstevel@tonic-gate goto done; 17597c478bd9Sstevel@tonic-gate } 17607c478bd9Sstevel@tonic-gate while (zonecfg_getfsent(handle, &fstab) == Z_OK) { 17617c478bd9Sstevel@tonic-gate zone_fsopt_t *optptr; 17627c478bd9Sstevel@tonic-gate 17637c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 17647c478bd9Sstevel@tonic-gate rt_to_str(RT_FS)); 17657c478bd9Sstevel@tonic-gate export_prop(of, PT_DIR, fstab.zone_fs_dir); 17667c478bd9Sstevel@tonic-gate export_prop(of, PT_SPECIAL, fstab.zone_fs_special); 17677c478bd9Sstevel@tonic-gate export_prop(of, PT_RAW, fstab.zone_fs_raw); 17687c478bd9Sstevel@tonic-gate export_prop(of, PT_TYPE, fstab.zone_fs_type); 17697c478bd9Sstevel@tonic-gate for (optptr = fstab.zone_fs_options; optptr != NULL; 17707c478bd9Sstevel@tonic-gate optptr = optptr->zone_fsopt_next) { 17717c478bd9Sstevel@tonic-gate /* 17727c478bd9Sstevel@tonic-gate * Simple property values with embedded equal signs 17737c478bd9Sstevel@tonic-gate * need to be quoted to prevent the lexer from 17747c478bd9Sstevel@tonic-gate * mis-parsing them as complex name=value pairs. 17757c478bd9Sstevel@tonic-gate */ 17767c478bd9Sstevel@tonic-gate if (strchr(optptr->zone_fsopt_opt, '=')) 17777c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s \"%s\"\n", 17787c478bd9Sstevel@tonic-gate cmd_to_str(CMD_ADD), 17797c478bd9Sstevel@tonic-gate pt_to_str(PT_OPTIONS), 17807c478bd9Sstevel@tonic-gate optptr->zone_fsopt_opt); 17817c478bd9Sstevel@tonic-gate else 17827c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s %s\n", 17837c478bd9Sstevel@tonic-gate cmd_to_str(CMD_ADD), 17847c478bd9Sstevel@tonic-gate pt_to_str(PT_OPTIONS), 17857c478bd9Sstevel@tonic-gate optptr->zone_fsopt_opt); 17867c478bd9Sstevel@tonic-gate } 17877c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 17887c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(fstab.zone_fs_options); 17897c478bd9Sstevel@tonic-gate } 17907c478bd9Sstevel@tonic-gate (void) zonecfg_endfsent(handle); 17917c478bd9Sstevel@tonic-gate 17927c478bd9Sstevel@tonic-gate if ((err = zonecfg_setnwifent(handle)) != Z_OK) { 1793bbec428eSgjelinek zone_perror(zone, err, B_FALSE); 17947c478bd9Sstevel@tonic-gate goto done; 17957c478bd9Sstevel@tonic-gate } 17967c478bd9Sstevel@tonic-gate while (zonecfg_getnwifent(handle, &nwiftab) == Z_OK) { 17977c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 17987c478bd9Sstevel@tonic-gate rt_to_str(RT_NET)); 17997c478bd9Sstevel@tonic-gate export_prop(of, PT_ADDRESS, nwiftab.zone_nwif_address); 18007c478bd9Sstevel@tonic-gate export_prop(of, PT_PHYSICAL, nwiftab.zone_nwif_physical); 1801de860bd9Sgfaden export_prop(of, PT_DEFROUTER, nwiftab.zone_nwif_defrouter); 18027c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 18037c478bd9Sstevel@tonic-gate } 18047c478bd9Sstevel@tonic-gate (void) zonecfg_endnwifent(handle); 18057c478bd9Sstevel@tonic-gate 18067c478bd9Sstevel@tonic-gate if ((err = zonecfg_setdevent(handle)) != Z_OK) { 1807bbec428eSgjelinek zone_perror(zone, err, B_FALSE); 18087c478bd9Sstevel@tonic-gate goto done; 18097c478bd9Sstevel@tonic-gate } 18107c478bd9Sstevel@tonic-gate while (zonecfg_getdevent(handle, &devtab) == Z_OK) { 18117c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 18127c478bd9Sstevel@tonic-gate rt_to_str(RT_DEVICE)); 18137c478bd9Sstevel@tonic-gate export_prop(of, PT_MATCH, devtab.zone_dev_match); 18147c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 18157c478bd9Sstevel@tonic-gate } 18167c478bd9Sstevel@tonic-gate (void) zonecfg_enddevent(handle); 18177c478bd9Sstevel@tonic-gate 18187c478bd9Sstevel@tonic-gate if ((err = zonecfg_setrctlent(handle)) != Z_OK) { 1819bbec428eSgjelinek zone_perror(zone, err, B_FALSE); 18207c478bd9Sstevel@tonic-gate goto done; 18217c478bd9Sstevel@tonic-gate } 18227c478bd9Sstevel@tonic-gate while (zonecfg_getrctlent(handle, &rctltab) == Z_OK) { 18237c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s rctl\n", cmd_to_str(CMD_ADD)); 18247c478bd9Sstevel@tonic-gate export_prop(of, PT_NAME, rctltab.zone_rctl_name); 18257c478bd9Sstevel@tonic-gate for (valptr = rctltab.zone_rctl_valptr; valptr != NULL; 18267c478bd9Sstevel@tonic-gate valptr = valptr->zone_rctlval_next) { 18277c478bd9Sstevel@tonic-gate fprintf(of, "%s %s (%s=%s,%s=%s,%s=%s)\n", 18287c478bd9Sstevel@tonic-gate cmd_to_str(CMD_ADD), pt_to_str(PT_VALUE), 18297c478bd9Sstevel@tonic-gate pt_to_str(PT_PRIV), valptr->zone_rctlval_priv, 18307c478bd9Sstevel@tonic-gate pt_to_str(PT_LIMIT), valptr->zone_rctlval_limit, 18317c478bd9Sstevel@tonic-gate pt_to_str(PT_ACTION), valptr->zone_rctlval_action); 18327c478bd9Sstevel@tonic-gate } 18337c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 18347c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctltab.zone_rctl_valptr); 18357c478bd9Sstevel@tonic-gate } 18367c478bd9Sstevel@tonic-gate (void) zonecfg_endrctlent(handle); 18377c478bd9Sstevel@tonic-gate 18387c478bd9Sstevel@tonic-gate if ((err = zonecfg_setattrent(handle)) != Z_OK) { 1839bbec428eSgjelinek zone_perror(zone, err, B_FALSE); 18407c478bd9Sstevel@tonic-gate goto done; 18417c478bd9Sstevel@tonic-gate } 18427c478bd9Sstevel@tonic-gate while (zonecfg_getattrent(handle, &attrtab) == Z_OK) { 18437c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 18447c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR)); 18457c478bd9Sstevel@tonic-gate export_prop(of, PT_NAME, attrtab.zone_attr_name); 18467c478bd9Sstevel@tonic-gate export_prop(of, PT_TYPE, attrtab.zone_attr_type); 18477c478bd9Sstevel@tonic-gate export_prop(of, PT_VALUE, attrtab.zone_attr_value); 18487c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 18497c478bd9Sstevel@tonic-gate } 18507c478bd9Sstevel@tonic-gate (void) zonecfg_endattrent(handle); 18517c478bd9Sstevel@tonic-gate 1852fa9e4066Sahrens if ((err = zonecfg_setdsent(handle)) != Z_OK) { 1853bbec428eSgjelinek zone_perror(zone, err, B_FALSE); 1854fa9e4066Sahrens goto done; 1855fa9e4066Sahrens } 1856fa9e4066Sahrens while (zonecfg_getdsent(handle, &dstab) == Z_OK) { 1857fa9e4066Sahrens (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 1858fa9e4066Sahrens rt_to_str(RT_DATASET)); 1859fa9e4066Sahrens export_prop(of, PT_NAME, dstab.zone_dataset_name); 1860fa9e4066Sahrens (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 1861fa9e4066Sahrens } 1862fa9e4066Sahrens (void) zonecfg_enddsent(handle); 1863fa9e4066Sahrens 18640209230bSgjelinek if (zonecfg_getpsetent(handle, &psettab) == Z_OK) { 18650209230bSgjelinek (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 18660209230bSgjelinek rt_to_str(RT_DCPU)); 18670209230bSgjelinek if (strcmp(psettab.zone_ncpu_min, psettab.zone_ncpu_max) == 0) 18680209230bSgjelinek (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 18690209230bSgjelinek pt_to_str(PT_NCPUS), psettab.zone_ncpu_max); 18700209230bSgjelinek else 18710209230bSgjelinek (void) fprintf(of, "%s %s=%s-%s\n", cmd_to_str(CMD_SET), 18720209230bSgjelinek pt_to_str(PT_NCPUS), psettab.zone_ncpu_min, 18730209230bSgjelinek psettab.zone_ncpu_max); 18740209230bSgjelinek if (psettab.zone_importance[0] != '\0') 18750209230bSgjelinek (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 18760209230bSgjelinek pt_to_str(PT_IMPORTANCE), psettab.zone_importance); 18770209230bSgjelinek (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 18780209230bSgjelinek } 18790209230bSgjelinek 18800209230bSgjelinek if (zonecfg_getmcapent(handle, &mcaptab) == Z_OK) { 18810209230bSgjelinek char buf[128]; 18820209230bSgjelinek 18830209230bSgjelinek (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 18840209230bSgjelinek rt_to_str(RT_MCAP)); 18850209230bSgjelinek bytes_to_units(mcaptab.zone_physmem_cap, buf, sizeof (buf)); 18860209230bSgjelinek (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 18870209230bSgjelinek pt_to_str(PT_PHYSICAL), buf); 18880209230bSgjelinek (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 18890209230bSgjelinek } 18900209230bSgjelinek 1891c97ad5cdSakolb /* 1892c97ad5cdSakolb * There is nothing to export for pcap since this resource is just 1893c97ad5cdSakolb * a container for an rctl alias. 1894c97ad5cdSakolb */ 1895c97ad5cdSakolb 18967c478bd9Sstevel@tonic-gate done: 18977c478bd9Sstevel@tonic-gate if (need_to_close) 18987c478bd9Sstevel@tonic-gate (void) fclose(of); 18997c478bd9Sstevel@tonic-gate } 19007c478bd9Sstevel@tonic-gate 19017c478bd9Sstevel@tonic-gate void 19027c478bd9Sstevel@tonic-gate exit_func(cmd_t *cmd) 19037c478bd9Sstevel@tonic-gate { 19047c478bd9Sstevel@tonic-gate int arg, answer; 1905bbec428eSgjelinek boolean_t arg_err = B_FALSE; 19067c478bd9Sstevel@tonic-gate 19077c478bd9Sstevel@tonic-gate optind = 0; 19087c478bd9Sstevel@tonic-gate while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?F")) != EOF) { 19097c478bd9Sstevel@tonic-gate switch (arg) { 19107c478bd9Sstevel@tonic-gate case '?': 19117c478bd9Sstevel@tonic-gate longer_usage(CMD_EXIT); 1912bbec428eSgjelinek arg_err = B_TRUE; 19137ec75eb8Sgjelinek break; 19147c478bd9Sstevel@tonic-gate case 'F': 1915bbec428eSgjelinek force_exit = B_TRUE; 19167c478bd9Sstevel@tonic-gate break; 19177c478bd9Sstevel@tonic-gate default: 19187c478bd9Sstevel@tonic-gate short_usage(CMD_EXIT); 1919bbec428eSgjelinek arg_err = B_TRUE; 19207ec75eb8Sgjelinek break; 19217ec75eb8Sgjelinek } 19227ec75eb8Sgjelinek } 19237ec75eb8Sgjelinek if (arg_err) 19247c478bd9Sstevel@tonic-gate return; 19257ec75eb8Sgjelinek 19267c478bd9Sstevel@tonic-gate if (optind < cmd->cmd_argc) { 19277c478bd9Sstevel@tonic-gate short_usage(CMD_EXIT); 19287c478bd9Sstevel@tonic-gate return; 19297c478bd9Sstevel@tonic-gate } 19307c478bd9Sstevel@tonic-gate 19317c478bd9Sstevel@tonic-gate if (global_scope || force_exit) { 1932bbec428eSgjelinek time_to_exit = B_TRUE; 19337c478bd9Sstevel@tonic-gate return; 19347c478bd9Sstevel@tonic-gate } 19357c478bd9Sstevel@tonic-gate 1936bbec428eSgjelinek answer = ask_yesno(B_FALSE, "Resource incomplete; really quit"); 19377c478bd9Sstevel@tonic-gate if (answer == -1) { 19387c478bd9Sstevel@tonic-gate zerr(gettext("Resource incomplete, input " 19397c478bd9Sstevel@tonic-gate "not from terminal and -F not specified:\n%s command " 19407c478bd9Sstevel@tonic-gate "ignored, but exiting anyway."), cmd_to_str(CMD_EXIT)); 19417c478bd9Sstevel@tonic-gate exit(Z_ERR); 19427c478bd9Sstevel@tonic-gate } else if (answer == 1) { 1943bbec428eSgjelinek time_to_exit = B_TRUE; 19447c478bd9Sstevel@tonic-gate } 19457c478bd9Sstevel@tonic-gate /* (answer == 0) => just return */ 19467c478bd9Sstevel@tonic-gate } 19477c478bd9Sstevel@tonic-gate 19487c478bd9Sstevel@tonic-gate static int 19497c478bd9Sstevel@tonic-gate validate_zonepath_syntax(char *path) 19507c478bd9Sstevel@tonic-gate { 19517c478bd9Sstevel@tonic-gate if (path[0] != '/') { 19527c478bd9Sstevel@tonic-gate zerr(gettext("%s is not an absolute path."), path); 19537c478bd9Sstevel@tonic-gate return (Z_ERR); 19547c478bd9Sstevel@tonic-gate } 19557c478bd9Sstevel@tonic-gate if (strcmp(path, "/") == 0) { 19567c478bd9Sstevel@tonic-gate zerr(gettext("/ is not allowed as a %s."), 19577c478bd9Sstevel@tonic-gate pt_to_str(PT_ZONEPATH)); 19587c478bd9Sstevel@tonic-gate return (Z_ERR); 19597c478bd9Sstevel@tonic-gate } 19607c478bd9Sstevel@tonic-gate return (Z_OK); 19617c478bd9Sstevel@tonic-gate } 19627c478bd9Sstevel@tonic-gate 19637c478bd9Sstevel@tonic-gate static void 19647c478bd9Sstevel@tonic-gate add_resource(cmd_t *cmd) 19657c478bd9Sstevel@tonic-gate { 19667c478bd9Sstevel@tonic-gate int type; 19670209230bSgjelinek struct zone_psettab tmp_psettab; 19680209230bSgjelinek struct zone_mcaptab tmp_mcaptab; 1969c97ad5cdSakolb uint64_t tmp; 19700209230bSgjelinek uint64_t tmp_mcap; 19710209230bSgjelinek char pool[MAXNAMELEN]; 19727c478bd9Sstevel@tonic-gate 19737c478bd9Sstevel@tonic-gate if ((type = cmd->cmd_res_type) == RT_UNKNOWN) { 1974bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 19757c478bd9Sstevel@tonic-gate goto bad; 19767c478bd9Sstevel@tonic-gate } 19777c478bd9Sstevel@tonic-gate 19787c478bd9Sstevel@tonic-gate switch (type) { 19797c478bd9Sstevel@tonic-gate case RT_FS: 19807c478bd9Sstevel@tonic-gate bzero(&in_progress_fstab, sizeof (in_progress_fstab)); 19817c478bd9Sstevel@tonic-gate return; 19827c478bd9Sstevel@tonic-gate case RT_IPD: 1983087719fdSdp if (state_atleast(ZONE_STATE_INSTALLED)) { 19847c478bd9Sstevel@tonic-gate zerr(gettext("Zone %s already installed; %s %s not " 19857c478bd9Sstevel@tonic-gate "allowed."), zone, cmd_to_str(CMD_ADD), 19867c478bd9Sstevel@tonic-gate rt_to_str(RT_IPD)); 19877c478bd9Sstevel@tonic-gate goto bad; 19887c478bd9Sstevel@tonic-gate } 19897c478bd9Sstevel@tonic-gate bzero(&in_progress_ipdtab, sizeof (in_progress_ipdtab)); 19907c478bd9Sstevel@tonic-gate return; 19917c478bd9Sstevel@tonic-gate case RT_NET: 19927c478bd9Sstevel@tonic-gate bzero(&in_progress_nwiftab, sizeof (in_progress_nwiftab)); 19937c478bd9Sstevel@tonic-gate return; 19947c478bd9Sstevel@tonic-gate case RT_DEVICE: 19957c478bd9Sstevel@tonic-gate bzero(&in_progress_devtab, sizeof (in_progress_devtab)); 19967c478bd9Sstevel@tonic-gate return; 19977c478bd9Sstevel@tonic-gate case RT_RCTL: 19980209230bSgjelinek if (global_zone) 19990209230bSgjelinek zerr(gettext("WARNING: Setting a global zone resource " 20000209230bSgjelinek "control too low could deny\nservice " 20010209230bSgjelinek "to even the root user; " 20020209230bSgjelinek "this could render the system impossible\n" 20030209230bSgjelinek "to administer. Please use caution.")); 20047c478bd9Sstevel@tonic-gate bzero(&in_progress_rctltab, sizeof (in_progress_rctltab)); 20057c478bd9Sstevel@tonic-gate return; 20067c478bd9Sstevel@tonic-gate case RT_ATTR: 20077c478bd9Sstevel@tonic-gate bzero(&in_progress_attrtab, sizeof (in_progress_attrtab)); 20087c478bd9Sstevel@tonic-gate return; 2009fa9e4066Sahrens case RT_DATASET: 2010fa9e4066Sahrens bzero(&in_progress_dstab, sizeof (in_progress_dstab)); 2011fa9e4066Sahrens return; 20120209230bSgjelinek case RT_DCPU: 2013c97ad5cdSakolb /* Make sure there isn't already a cpu-set or cpu-cap entry. */ 20140209230bSgjelinek if (zonecfg_lookup_pset(handle, &tmp_psettab) == Z_OK) { 20150209230bSgjelinek zerr(gettext("The %s resource already exists."), 20160209230bSgjelinek rt_to_str(RT_DCPU)); 20170209230bSgjelinek goto bad; 20180209230bSgjelinek } 2019c97ad5cdSakolb if (zonecfg_get_aliased_rctl(handle, ALIAS_CPUCAP, &tmp) != 2020c97ad5cdSakolb Z_NO_ENTRY) { 2021c97ad5cdSakolb zerr(gettext("The %s resource already exists."), 2022c97ad5cdSakolb rt_to_str(RT_PCAP)); 2023c97ad5cdSakolb goto bad; 2024c97ad5cdSakolb } 20250209230bSgjelinek 20260209230bSgjelinek /* Make sure the pool property isn't set. */ 20270209230bSgjelinek if (zonecfg_get_pool(handle, pool, sizeof (pool)) == Z_OK && 20280209230bSgjelinek strlen(pool) > 0) { 20290209230bSgjelinek zerr(gettext("The %s property is already set. " 20300209230bSgjelinek "A persistent pool is incompatible with\nthe %s " 20310209230bSgjelinek "resource."), 20320209230bSgjelinek pt_to_str(PT_POOL), rt_to_str(RT_DCPU)); 20330209230bSgjelinek goto bad; 20340209230bSgjelinek } 20350209230bSgjelinek 20360209230bSgjelinek bzero(&in_progress_psettab, sizeof (in_progress_psettab)); 20370209230bSgjelinek return; 2038c97ad5cdSakolb case RT_PCAP: 2039c97ad5cdSakolb /* 2040c97ad5cdSakolb * Make sure there isn't already a cpu-set or incompatible 2041c97ad5cdSakolb * cpu-cap rctls. 2042c97ad5cdSakolb */ 2043c97ad5cdSakolb if (zonecfg_lookup_pset(handle, &tmp_psettab) == Z_OK) { 2044c97ad5cdSakolb zerr(gettext("The %s resource already exists."), 2045c97ad5cdSakolb rt_to_str(RT_DCPU)); 2046c97ad5cdSakolb goto bad; 2047c97ad5cdSakolb } 2048c97ad5cdSakolb 2049c97ad5cdSakolb switch (zonecfg_get_aliased_rctl(handle, ALIAS_CPUCAP, &tmp)) { 2050c97ad5cdSakolb case Z_ALIAS_DISALLOW: 2051c97ad5cdSakolb zone_perror(rt_to_str(RT_PCAP), Z_ALIAS_DISALLOW, 2052bbec428eSgjelinek B_FALSE); 2053c97ad5cdSakolb goto bad; 2054c97ad5cdSakolb 2055c97ad5cdSakolb case Z_OK: 2056c97ad5cdSakolb zerr(gettext("The %s resource already exists."), 2057c97ad5cdSakolb rt_to_str(RT_PCAP)); 2058c97ad5cdSakolb goto bad; 2059c97ad5cdSakolb 2060c97ad5cdSakolb default: 2061c97ad5cdSakolb break; 2062c97ad5cdSakolb } 2063c97ad5cdSakolb return; 20640209230bSgjelinek case RT_MCAP: 20650209230bSgjelinek /* 20660209230bSgjelinek * Make sure there isn't already a mem-cap entry or max-swap 20670209230bSgjelinek * or max-locked rctl. 20680209230bSgjelinek */ 20690209230bSgjelinek if (zonecfg_lookup_mcap(handle, &tmp_mcaptab) == Z_OK || 20700209230bSgjelinek zonecfg_get_aliased_rctl(handle, ALIAS_MAXSWAP, &tmp_mcap) 20710209230bSgjelinek == Z_OK || 20720209230bSgjelinek zonecfg_get_aliased_rctl(handle, ALIAS_MAXLOCKEDMEM, 20730209230bSgjelinek &tmp_mcap) == Z_OK) { 20740209230bSgjelinek zerr(gettext("The %s resource or a related resource " 20750209230bSgjelinek "control already exists."), rt_to_str(RT_MCAP)); 20760209230bSgjelinek goto bad; 20770209230bSgjelinek } 20780209230bSgjelinek if (global_zone) 20790209230bSgjelinek zerr(gettext("WARNING: Setting a global zone memory " 20800209230bSgjelinek "cap too low could deny\nservice " 20810209230bSgjelinek "to even the root user; " 20820209230bSgjelinek "this could render the system impossible\n" 20830209230bSgjelinek "to administer. Please use caution.")); 20840209230bSgjelinek bzero(&in_progress_mcaptab, sizeof (in_progress_mcaptab)); 20850209230bSgjelinek return; 20867c478bd9Sstevel@tonic-gate default: 2087bbec428eSgjelinek zone_perror(rt_to_str(type), Z_NO_RESOURCE_TYPE, B_TRUE); 2088bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 2089bbec428eSgjelinek usage(B_FALSE, HELP_RESOURCES); 20907c478bd9Sstevel@tonic-gate } 20917c478bd9Sstevel@tonic-gate bad: 2092bbec428eSgjelinek global_scope = B_TRUE; 20937c478bd9Sstevel@tonic-gate end_op = -1; 20947c478bd9Sstevel@tonic-gate } 20957c478bd9Sstevel@tonic-gate 20967c478bd9Sstevel@tonic-gate static void 20977c478bd9Sstevel@tonic-gate do_complex_rctl_val(complex_property_ptr_t cp) 20987c478bd9Sstevel@tonic-gate { 20997c478bd9Sstevel@tonic-gate struct zone_rctlvaltab *rctlvaltab; 21007c478bd9Sstevel@tonic-gate complex_property_ptr_t cx; 2101bbec428eSgjelinek boolean_t seen_priv = B_FALSE, seen_limit = B_FALSE, 2102bbec428eSgjelinek seen_action = B_FALSE; 21037c478bd9Sstevel@tonic-gate rctlblk_t *rctlblk; 21047c478bd9Sstevel@tonic-gate int err; 21057c478bd9Sstevel@tonic-gate 21067c478bd9Sstevel@tonic-gate if ((rctlvaltab = alloc_rctlvaltab()) == NULL) { 2107bbec428eSgjelinek zone_perror(zone, Z_NOMEM, B_TRUE); 21087c478bd9Sstevel@tonic-gate exit(Z_ERR); 21097c478bd9Sstevel@tonic-gate } 21107c478bd9Sstevel@tonic-gate for (cx = cp; cx != NULL; cx = cx->cp_next) { 21117c478bd9Sstevel@tonic-gate switch (cx->cp_type) { 21127c478bd9Sstevel@tonic-gate case PT_PRIV: 21137c478bd9Sstevel@tonic-gate if (seen_priv) { 21147c478bd9Sstevel@tonic-gate zerr(gettext("%s already specified"), 21157c478bd9Sstevel@tonic-gate pt_to_str(PT_PRIV)); 21167c478bd9Sstevel@tonic-gate goto bad; 21177c478bd9Sstevel@tonic-gate } 21187c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_priv, 21197c478bd9Sstevel@tonic-gate cx->cp_value, 21207c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_priv)); 2121bbec428eSgjelinek seen_priv = B_TRUE; 21227c478bd9Sstevel@tonic-gate break; 21237c478bd9Sstevel@tonic-gate case PT_LIMIT: 21247c478bd9Sstevel@tonic-gate if (seen_limit) { 21257c478bd9Sstevel@tonic-gate zerr(gettext("%s already specified"), 21267c478bd9Sstevel@tonic-gate pt_to_str(PT_LIMIT)); 21277c478bd9Sstevel@tonic-gate goto bad; 21287c478bd9Sstevel@tonic-gate } 21297c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_limit, 21307c478bd9Sstevel@tonic-gate cx->cp_value, 21317c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_limit)); 2132bbec428eSgjelinek seen_limit = B_TRUE; 21337c478bd9Sstevel@tonic-gate break; 21347c478bd9Sstevel@tonic-gate case PT_ACTION: 21357c478bd9Sstevel@tonic-gate if (seen_action) { 21367c478bd9Sstevel@tonic-gate zerr(gettext("%s already specified"), 21377c478bd9Sstevel@tonic-gate pt_to_str(PT_ACTION)); 21387c478bd9Sstevel@tonic-gate goto bad; 21397c478bd9Sstevel@tonic-gate } 21407c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_action, 21417c478bd9Sstevel@tonic-gate cx->cp_value, 21427c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_action)); 2143bbec428eSgjelinek seen_action = B_TRUE; 21447c478bd9Sstevel@tonic-gate break; 21457c478bd9Sstevel@tonic-gate default: 21467c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(PT_VALUE), 2147bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE); 2148bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 2149bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 21507c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctlvaltab); 21517c478bd9Sstevel@tonic-gate return; 21527c478bd9Sstevel@tonic-gate } 21537c478bd9Sstevel@tonic-gate } 21547c478bd9Sstevel@tonic-gate if (!seen_priv) 21557c478bd9Sstevel@tonic-gate zerr(gettext("%s not specified"), pt_to_str(PT_PRIV)); 21567c478bd9Sstevel@tonic-gate if (!seen_limit) 21577c478bd9Sstevel@tonic-gate zerr(gettext("%s not specified"), pt_to_str(PT_LIMIT)); 21587c478bd9Sstevel@tonic-gate if (!seen_action) 21597c478bd9Sstevel@tonic-gate zerr(gettext("%s not specified"), pt_to_str(PT_ACTION)); 21607c478bd9Sstevel@tonic-gate if (!seen_priv || !seen_limit || !seen_action) 21617c478bd9Sstevel@tonic-gate goto bad; 21627c478bd9Sstevel@tonic-gate rctlvaltab->zone_rctlval_next = NULL; 21637c478bd9Sstevel@tonic-gate rctlblk = alloca(rctlblk_size()); 21647c478bd9Sstevel@tonic-gate /* 21657c478bd9Sstevel@tonic-gate * Make sure the rctl value looks roughly correct; we won't know if 21667c478bd9Sstevel@tonic-gate * it's truly OK until we verify the configuration on the target 21677c478bd9Sstevel@tonic-gate * system. 21687c478bd9Sstevel@tonic-gate */ 21697c478bd9Sstevel@tonic-gate if (zonecfg_construct_rctlblk(rctlvaltab, rctlblk) != Z_OK || 21707c478bd9Sstevel@tonic-gate !zonecfg_valid_rctlblk(rctlblk)) { 21717c478bd9Sstevel@tonic-gate zerr(gettext("Invalid %s %s specification"), rt_to_str(RT_RCTL), 21727c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE)); 21737c478bd9Sstevel@tonic-gate goto bad; 21747c478bd9Sstevel@tonic-gate } 21757c478bd9Sstevel@tonic-gate err = zonecfg_add_rctl_value(&in_progress_rctltab, rctlvaltab); 21767c478bd9Sstevel@tonic-gate if (err != Z_OK) 2177bbec428eSgjelinek zone_perror(pt_to_str(PT_VALUE), err, B_TRUE); 21787c478bd9Sstevel@tonic-gate return; 21797c478bd9Sstevel@tonic-gate 21807c478bd9Sstevel@tonic-gate bad: 21817c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctlvaltab); 21827c478bd9Sstevel@tonic-gate } 21837c478bd9Sstevel@tonic-gate 21847c478bd9Sstevel@tonic-gate static void 21857c478bd9Sstevel@tonic-gate add_property(cmd_t *cmd) 21867c478bd9Sstevel@tonic-gate { 21877c478bd9Sstevel@tonic-gate char *prop_id; 21887c478bd9Sstevel@tonic-gate int err, res_type, prop_type; 21897c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 21907c478bd9Sstevel@tonic-gate list_property_ptr_t l; 21917c478bd9Sstevel@tonic-gate 21927c478bd9Sstevel@tonic-gate res_type = resource_scope; 21937c478bd9Sstevel@tonic-gate prop_type = cmd->cmd_prop_name[0]; 21947c478bd9Sstevel@tonic-gate if (res_type == RT_UNKNOWN || prop_type == PT_UNKNOWN) { 2195bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 21967c478bd9Sstevel@tonic-gate return; 21977c478bd9Sstevel@tonic-gate } 21987c478bd9Sstevel@tonic-gate 21997c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs != 1) { 2200bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 22017c478bd9Sstevel@tonic-gate return; 22027c478bd9Sstevel@tonic-gate } 22037c478bd9Sstevel@tonic-gate 2204bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 22057c478bd9Sstevel@tonic-gate return; 22067c478bd9Sstevel@tonic-gate 22077c478bd9Sstevel@tonic-gate switch (res_type) { 22087c478bd9Sstevel@tonic-gate case RT_FS: 22097c478bd9Sstevel@tonic-gate if (prop_type != PT_OPTIONS) { 22107c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 2211bbec428eSgjelinek B_TRUE); 2212bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 2213bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 22147c478bd9Sstevel@tonic-gate return; 22157c478bd9Sstevel@tonic-gate } 22167c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[0]; 22177c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE && 22187c478bd9Sstevel@tonic-gate pp->pv_type != PROP_VAL_LIST) { 22197c478bd9Sstevel@tonic-gate zerr(gettext("A %s or %s value was expected here."), 22207c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_SIMPLE), 22217c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_LIST)); 2222bbec428eSgjelinek saw_error = B_TRUE; 22237c478bd9Sstevel@tonic-gate return; 22247c478bd9Sstevel@tonic-gate } 22257c478bd9Sstevel@tonic-gate if (pp->pv_type == PROP_VAL_SIMPLE) { 22267c478bd9Sstevel@tonic-gate if (pp->pv_simple == NULL) { 2227bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 22287c478bd9Sstevel@tonic-gate return; 22297c478bd9Sstevel@tonic-gate } 22307c478bd9Sstevel@tonic-gate prop_id = pp->pv_simple; 22317c478bd9Sstevel@tonic-gate err = zonecfg_add_fs_option(&in_progress_fstab, 22327c478bd9Sstevel@tonic-gate prop_id); 22337c478bd9Sstevel@tonic-gate if (err != Z_OK) 2234bbec428eSgjelinek zone_perror(pt_to_str(prop_type), err, B_TRUE); 22357c478bd9Sstevel@tonic-gate } else { 22367c478bd9Sstevel@tonic-gate list_property_ptr_t list; 22377c478bd9Sstevel@tonic-gate 22387c478bd9Sstevel@tonic-gate for (list = pp->pv_list; list != NULL; 22397c478bd9Sstevel@tonic-gate list = list->lp_next) { 22407c478bd9Sstevel@tonic-gate prop_id = list->lp_simple; 22417c478bd9Sstevel@tonic-gate if (prop_id == NULL) 22427c478bd9Sstevel@tonic-gate break; 22437c478bd9Sstevel@tonic-gate err = zonecfg_add_fs_option( 22447c478bd9Sstevel@tonic-gate &in_progress_fstab, prop_id); 22457c478bd9Sstevel@tonic-gate if (err != Z_OK) 22467c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), err, 2247bbec428eSgjelinek B_TRUE); 22487c478bd9Sstevel@tonic-gate } 22497c478bd9Sstevel@tonic-gate } 22507c478bd9Sstevel@tonic-gate return; 22517c478bd9Sstevel@tonic-gate case RT_RCTL: 22527c478bd9Sstevel@tonic-gate if (prop_type != PT_VALUE) { 22537c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 2254bbec428eSgjelinek B_TRUE); 2255bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 2256bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 22577c478bd9Sstevel@tonic-gate return; 22587c478bd9Sstevel@tonic-gate } 22597c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[0]; 22607c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_COMPLEX && 22617c478bd9Sstevel@tonic-gate pp->pv_type != PROP_VAL_LIST) { 22627c478bd9Sstevel@tonic-gate zerr(gettext("A %s or %s value was expected here."), 22637c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_COMPLEX), 22647c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_LIST)); 2265bbec428eSgjelinek saw_error = B_TRUE; 22667c478bd9Sstevel@tonic-gate return; 22677c478bd9Sstevel@tonic-gate } 22687c478bd9Sstevel@tonic-gate if (pp->pv_type == PROP_VAL_COMPLEX) { 22697c478bd9Sstevel@tonic-gate do_complex_rctl_val(pp->pv_complex); 22707c478bd9Sstevel@tonic-gate return; 22717c478bd9Sstevel@tonic-gate } 22727c478bd9Sstevel@tonic-gate for (l = pp->pv_list; l != NULL; l = l->lp_next) 22737c478bd9Sstevel@tonic-gate do_complex_rctl_val(l->lp_complex); 22747c478bd9Sstevel@tonic-gate return; 22757c478bd9Sstevel@tonic-gate default: 2276bbec428eSgjelinek zone_perror(rt_to_str(res_type), Z_NO_RESOURCE_TYPE, B_TRUE); 2277bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 2278bbec428eSgjelinek usage(B_FALSE, HELP_RESOURCES); 22797c478bd9Sstevel@tonic-gate return; 22807c478bd9Sstevel@tonic-gate } 22817c478bd9Sstevel@tonic-gate } 22827c478bd9Sstevel@tonic-gate 22830209230bSgjelinek static boolean_t 22840209230bSgjelinek gz_invalid_resource(int type) 22850209230bSgjelinek { 22860209230bSgjelinek return (global_zone && (type == RT_FS || type == RT_IPD || 22870209230bSgjelinek type == RT_NET || type == RT_DEVICE || type == RT_ATTR || 22880209230bSgjelinek type == RT_DATASET)); 22890209230bSgjelinek } 22900209230bSgjelinek 22910209230bSgjelinek static boolean_t 22920209230bSgjelinek gz_invalid_rt_property(int type) 22930209230bSgjelinek { 22940209230bSgjelinek return (global_zone && (type == RT_ZONENAME || type == RT_ZONEPATH || 22950209230bSgjelinek type == RT_AUTOBOOT || type == RT_LIMITPRIV || 2296f4b3ec61Sdh155122 type == RT_BOOTARGS || type == RT_BRAND || type == RT_SCHED || 22975679c89fSjv227347 type == RT_IPTYPE || type == RT_HOSTID)); 22980209230bSgjelinek } 22990209230bSgjelinek 23000209230bSgjelinek static boolean_t 23010209230bSgjelinek gz_invalid_property(int type) 23020209230bSgjelinek { 23030209230bSgjelinek return (global_zone && (type == PT_ZONENAME || type == PT_ZONEPATH || 23040209230bSgjelinek type == PT_AUTOBOOT || type == PT_LIMITPRIV || 2305f4b3ec61Sdh155122 type == PT_BOOTARGS || type == PT_BRAND || type == PT_SCHED || 23065679c89fSjv227347 type == PT_IPTYPE || type == PT_HOSTID)); 23070209230bSgjelinek } 23080209230bSgjelinek 23097c478bd9Sstevel@tonic-gate void 23107c478bd9Sstevel@tonic-gate add_func(cmd_t *cmd) 23117c478bd9Sstevel@tonic-gate { 23127c478bd9Sstevel@tonic-gate int arg; 2313bbec428eSgjelinek boolean_t arg_err = B_FALSE; 23147c478bd9Sstevel@tonic-gate 23157c478bd9Sstevel@tonic-gate assert(cmd != NULL); 23167c478bd9Sstevel@tonic-gate 23177c478bd9Sstevel@tonic-gate optind = 0; 23187ec75eb8Sgjelinek while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?")) != EOF) { 23197c478bd9Sstevel@tonic-gate switch (arg) { 23207c478bd9Sstevel@tonic-gate case '?': 23217c478bd9Sstevel@tonic-gate longer_usage(CMD_ADD); 2322bbec428eSgjelinek arg_err = B_TRUE; 23237ec75eb8Sgjelinek break; 23247c478bd9Sstevel@tonic-gate default: 23257c478bd9Sstevel@tonic-gate short_usage(CMD_ADD); 2326bbec428eSgjelinek arg_err = B_TRUE; 23277ec75eb8Sgjelinek break; 23287ec75eb8Sgjelinek } 23297ec75eb8Sgjelinek } 23307ec75eb8Sgjelinek if (arg_err) 23317c478bd9Sstevel@tonic-gate return; 23327ec75eb8Sgjelinek 23337c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 23347c478bd9Sstevel@tonic-gate short_usage(CMD_ADD); 23357c478bd9Sstevel@tonic-gate return; 23367c478bd9Sstevel@tonic-gate } 23377c478bd9Sstevel@tonic-gate 23387c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_ADD)) 23397c478bd9Sstevel@tonic-gate return; 23407c478bd9Sstevel@tonic-gate 2341bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 23427c478bd9Sstevel@tonic-gate return; 23437c478bd9Sstevel@tonic-gate if (global_scope) { 23440209230bSgjelinek if (gz_invalid_resource(cmd->cmd_res_type)) { 23450209230bSgjelinek zerr(gettext("Cannot add a %s resource to the " 23460209230bSgjelinek "global zone."), rt_to_str(cmd->cmd_res_type)); 2347bbec428eSgjelinek saw_error = B_TRUE; 23480209230bSgjelinek return; 23490209230bSgjelinek } 23500209230bSgjelinek 2351bbec428eSgjelinek global_scope = B_FALSE; 23527c478bd9Sstevel@tonic-gate resource_scope = cmd->cmd_res_type; 23537c478bd9Sstevel@tonic-gate end_op = CMD_ADD; 23547c478bd9Sstevel@tonic-gate add_resource(cmd); 23557c478bd9Sstevel@tonic-gate } else 23567c478bd9Sstevel@tonic-gate add_property(cmd); 23577c478bd9Sstevel@tonic-gate } 23587c478bd9Sstevel@tonic-gate 2359087719fdSdp /* 2360087719fdSdp * This routine has an unusual implementation, because it tries very 2361087719fdSdp * hard to succeed in the face of a variety of failure modes. 2362087719fdSdp * The most common and most vexing occurs when the index file and 2363087719fdSdp * the /etc/zones/<zonename.xml> file are not both present. In 2364087719fdSdp * this case, delete must eradicate as much of the zone state as is left 2365087719fdSdp * so that the user can later create a new zone with the same name. 2366087719fdSdp */ 23677c478bd9Sstevel@tonic-gate void 23687c478bd9Sstevel@tonic-gate delete_func(cmd_t *cmd) 23697c478bd9Sstevel@tonic-gate { 23707c478bd9Sstevel@tonic-gate int err, arg, answer; 23717c478bd9Sstevel@tonic-gate char line[ZONENAME_MAX + 128]; /* enough to ask a question */ 2372bbec428eSgjelinek boolean_t force = B_FALSE; 2373bbec428eSgjelinek boolean_t arg_err = B_FALSE; 23747c478bd9Sstevel@tonic-gate 23757c478bd9Sstevel@tonic-gate optind = 0; 23767c478bd9Sstevel@tonic-gate while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?F")) != EOF) { 23777c478bd9Sstevel@tonic-gate switch (arg) { 23787c478bd9Sstevel@tonic-gate case '?': 23797c478bd9Sstevel@tonic-gate longer_usage(CMD_DELETE); 2380bbec428eSgjelinek arg_err = B_TRUE; 23817ec75eb8Sgjelinek break; 23827c478bd9Sstevel@tonic-gate case 'F': 2383bbec428eSgjelinek force = B_TRUE; 23847c478bd9Sstevel@tonic-gate break; 23857c478bd9Sstevel@tonic-gate default: 23867c478bd9Sstevel@tonic-gate short_usage(CMD_DELETE); 2387bbec428eSgjelinek arg_err = B_TRUE; 23887ec75eb8Sgjelinek break; 23897ec75eb8Sgjelinek } 23907ec75eb8Sgjelinek } 23917ec75eb8Sgjelinek if (arg_err) 23927c478bd9Sstevel@tonic-gate return; 23937ec75eb8Sgjelinek 23947c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 23957c478bd9Sstevel@tonic-gate short_usage(CMD_DELETE); 23967c478bd9Sstevel@tonic-gate return; 23977c478bd9Sstevel@tonic-gate } 23987c478bd9Sstevel@tonic-gate 23997c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_DELETE)) 24007c478bd9Sstevel@tonic-gate return; 24017c478bd9Sstevel@tonic-gate 2402087719fdSdp if (!force) { 2403087719fdSdp /* 2404087719fdSdp * Initialize sets up the global called "handle" and warns the 2405087719fdSdp * user if the zone is not configured. In force mode, we don't 2406087719fdSdp * trust that evaluation, and hence skip it. (We don't need the 2407087719fdSdp * handle to be loaded anyway, since zonecfg_destroy is done by 2408087719fdSdp * zonename). However, we also have to take care to emulate the 2409087719fdSdp * messages spit out by initialize; see below. 2410087719fdSdp */ 2411bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 24127c478bd9Sstevel@tonic-gate return; 24137c478bd9Sstevel@tonic-gate 24147c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), 24157c478bd9Sstevel@tonic-gate gettext("Are you sure you want to delete zone %s"), zone); 2416bbec428eSgjelinek if ((answer = ask_yesno(B_FALSE, line)) == -1) { 2417087719fdSdp zerr(gettext("Input not from terminal and -F not " 2418087719fdSdp "specified:\n%s command ignored, exiting."), 2419087719fdSdp cmd_to_str(CMD_DELETE)); 24207c478bd9Sstevel@tonic-gate exit(Z_ERR); 24217c478bd9Sstevel@tonic-gate } 24227c478bd9Sstevel@tonic-gate if (answer != 1) 24237c478bd9Sstevel@tonic-gate return; 24247c478bd9Sstevel@tonic-gate } 24257c478bd9Sstevel@tonic-gate 2426087719fdSdp if ((err = zonecfg_destroy(zone, force)) != Z_OK) { 2427087719fdSdp if ((err == Z_BAD_ZONE_STATE) && !force) { 2428087719fdSdp zerr(gettext("Zone %s not in %s state; %s not " 2429087719fdSdp "allowed. Use -F to force %s."), 2430087719fdSdp zone, zone_state_str(ZONE_STATE_CONFIGURED), 2431087719fdSdp cmd_to_str(CMD_DELETE), cmd_to_str(CMD_DELETE)); 2432087719fdSdp } else { 2433bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 24347c478bd9Sstevel@tonic-gate } 2435087719fdSdp } 2436bbec428eSgjelinek need_to_commit = B_FALSE; 2437087719fdSdp 2438087719fdSdp /* 2439087719fdSdp * Emulate initialize's messaging; if there wasn't a valid handle to 2440087719fdSdp * begin with, then user had typed delete (or delete -F) multiple 2441087719fdSdp * times. So we emit a message. 2442087719fdSdp * 2443087719fdSdp * We only do this in the 'force' case because normally, initialize() 2444087719fdSdp * takes care of this for us. 2445087719fdSdp */ 2446087719fdSdp if (force && zonecfg_check_handle(handle) != Z_OK && interactive_mode) 2447087719fdSdp (void) printf(gettext("Use '%s' to begin " 2448087719fdSdp "configuring a new zone.\n"), cmd_to_str(CMD_CREATE)); 24497c478bd9Sstevel@tonic-gate 24507c478bd9Sstevel@tonic-gate /* 24517c478bd9Sstevel@tonic-gate * Time for a new handle: finish the old one off first 24527c478bd9Sstevel@tonic-gate * then get a new one properly to avoid leaks. 24537c478bd9Sstevel@tonic-gate */ 2454087719fdSdp if (got_handle) { 24557c478bd9Sstevel@tonic-gate zonecfg_fini_handle(handle); 24567c478bd9Sstevel@tonic-gate if ((handle = zonecfg_init_handle()) == NULL) { 2457bbec428eSgjelinek zone_perror(execname, Z_NOMEM, B_TRUE); 24587c478bd9Sstevel@tonic-gate exit(Z_ERR); 24597c478bd9Sstevel@tonic-gate } 24607c478bd9Sstevel@tonic-gate if ((err = zonecfg_get_handle(zone, handle)) != Z_OK) { 24617c478bd9Sstevel@tonic-gate /* If there was no zone before, that's OK */ 24627c478bd9Sstevel@tonic-gate if (err != Z_NO_ZONE) 2463bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 2464bbec428eSgjelinek got_handle = B_FALSE; 24657c478bd9Sstevel@tonic-gate } 24667c478bd9Sstevel@tonic-gate } 2467087719fdSdp } 24687c478bd9Sstevel@tonic-gate 24697c478bd9Sstevel@tonic-gate static int 2470bbec428eSgjelinek fill_in_fstab(cmd_t *cmd, struct zone_fstab *fstab, boolean_t fill_in_only) 24717c478bd9Sstevel@tonic-gate { 24727c478bd9Sstevel@tonic-gate int err, i; 24737c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 24747c478bd9Sstevel@tonic-gate 2475bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK) 24767c478bd9Sstevel@tonic-gate return (err); 24777c478bd9Sstevel@tonic-gate 2478e193d1e6Svp157776 bzero(fstab, sizeof (*fstab)); 24797c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 24807c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i]; 24817c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 24827c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here.")); 2483bbec428eSgjelinek saw_error = B_TRUE; 24847c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 24857c478bd9Sstevel@tonic-gate } 24867c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) { 24877c478bd9Sstevel@tonic-gate case PT_DIR: 24887c478bd9Sstevel@tonic-gate (void) strlcpy(fstab->zone_fs_dir, pp->pv_simple, 24897c478bd9Sstevel@tonic-gate sizeof (fstab->zone_fs_dir)); 24907c478bd9Sstevel@tonic-gate break; 24917c478bd9Sstevel@tonic-gate case PT_SPECIAL: 24927c478bd9Sstevel@tonic-gate (void) strlcpy(fstab->zone_fs_special, pp->pv_simple, 24937c478bd9Sstevel@tonic-gate sizeof (fstab->zone_fs_special)); 24947c478bd9Sstevel@tonic-gate break; 24957c478bd9Sstevel@tonic-gate case PT_RAW: 24967c478bd9Sstevel@tonic-gate (void) strlcpy(fstab->zone_fs_raw, pp->pv_simple, 24977c478bd9Sstevel@tonic-gate sizeof (fstab->zone_fs_raw)); 24987c478bd9Sstevel@tonic-gate break; 24997c478bd9Sstevel@tonic-gate case PT_TYPE: 25007c478bd9Sstevel@tonic-gate (void) strlcpy(fstab->zone_fs_type, pp->pv_simple, 25017c478bd9Sstevel@tonic-gate sizeof (fstab->zone_fs_type)); 25027c478bd9Sstevel@tonic-gate break; 25037c478bd9Sstevel@tonic-gate default: 25047c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 2505bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE); 25067c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 25077c478bd9Sstevel@tonic-gate } 25087c478bd9Sstevel@tonic-gate } 25097c478bd9Sstevel@tonic-gate if (fill_in_only) 25107c478bd9Sstevel@tonic-gate return (Z_OK); 25117c478bd9Sstevel@tonic-gate return (zonecfg_lookup_filesystem(handle, fstab)); 25127c478bd9Sstevel@tonic-gate } 25137c478bd9Sstevel@tonic-gate 25147c478bd9Sstevel@tonic-gate static int 2515bbec428eSgjelinek fill_in_ipdtab(cmd_t *cmd, struct zone_fstab *ipdtab, boolean_t fill_in_only) 25167c478bd9Sstevel@tonic-gate { 25177c478bd9Sstevel@tonic-gate int err, i; 25187c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 25197c478bd9Sstevel@tonic-gate 2520bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK) 25217c478bd9Sstevel@tonic-gate return (err); 25227c478bd9Sstevel@tonic-gate 2523e193d1e6Svp157776 bzero(ipdtab, sizeof (*ipdtab)); 25247c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 25257c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i]; 25267c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 25277c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here.")); 2528bbec428eSgjelinek saw_error = B_TRUE; 25297c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 25307c478bd9Sstevel@tonic-gate } 25317c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) { 25327c478bd9Sstevel@tonic-gate case PT_DIR: 25337c478bd9Sstevel@tonic-gate (void) strlcpy(ipdtab->zone_fs_dir, pp->pv_simple, 25347c478bd9Sstevel@tonic-gate sizeof (ipdtab->zone_fs_dir)); 25357c478bd9Sstevel@tonic-gate break; 25367c478bd9Sstevel@tonic-gate default: 25377c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 2538bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE); 25397c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 25407c478bd9Sstevel@tonic-gate } 25417c478bd9Sstevel@tonic-gate } 25427c478bd9Sstevel@tonic-gate if (fill_in_only) 25437c478bd9Sstevel@tonic-gate return (Z_OK); 25447c478bd9Sstevel@tonic-gate return (zonecfg_lookup_ipd(handle, ipdtab)); 25457c478bd9Sstevel@tonic-gate } 25467c478bd9Sstevel@tonic-gate 25477c478bd9Sstevel@tonic-gate static int 2548bbec428eSgjelinek fill_in_nwiftab(cmd_t *cmd, struct zone_nwiftab *nwiftab, 2549bbec428eSgjelinek boolean_t fill_in_only) 25507c478bd9Sstevel@tonic-gate { 25517c478bd9Sstevel@tonic-gate int err, i; 25527c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 25537c478bd9Sstevel@tonic-gate 2554bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK) 25557c478bd9Sstevel@tonic-gate return (err); 25567c478bd9Sstevel@tonic-gate 2557e193d1e6Svp157776 bzero(nwiftab, sizeof (*nwiftab)); 25587c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 25597c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i]; 25607c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 25617c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here.")); 2562bbec428eSgjelinek saw_error = B_TRUE; 25637c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 25647c478bd9Sstevel@tonic-gate } 25657c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) { 25667c478bd9Sstevel@tonic-gate case PT_ADDRESS: 25677c478bd9Sstevel@tonic-gate (void) strlcpy(nwiftab->zone_nwif_address, 25687c478bd9Sstevel@tonic-gate pp->pv_simple, sizeof (nwiftab->zone_nwif_address)); 25697c478bd9Sstevel@tonic-gate break; 25707c478bd9Sstevel@tonic-gate case PT_PHYSICAL: 25717c478bd9Sstevel@tonic-gate (void) strlcpy(nwiftab->zone_nwif_physical, 25727c478bd9Sstevel@tonic-gate pp->pv_simple, 25737c478bd9Sstevel@tonic-gate sizeof (nwiftab->zone_nwif_physical)); 25747c478bd9Sstevel@tonic-gate break; 2575de860bd9Sgfaden case PT_DEFROUTER: 2576de860bd9Sgfaden (void) strlcpy(nwiftab->zone_nwif_defrouter, 2577de860bd9Sgfaden pp->pv_simple, 2578de860bd9Sgfaden sizeof (nwiftab->zone_nwif_defrouter)); 2579de860bd9Sgfaden break; 25807c478bd9Sstevel@tonic-gate default: 25817c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 2582bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE); 25837c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 25847c478bd9Sstevel@tonic-gate } 25857c478bd9Sstevel@tonic-gate } 25867c478bd9Sstevel@tonic-gate if (fill_in_only) 25877c478bd9Sstevel@tonic-gate return (Z_OK); 25887c478bd9Sstevel@tonic-gate err = zonecfg_lookup_nwif(handle, nwiftab); 25897c478bd9Sstevel@tonic-gate return (err); 25907c478bd9Sstevel@tonic-gate } 25917c478bd9Sstevel@tonic-gate 25927c478bd9Sstevel@tonic-gate static int 2593bbec428eSgjelinek fill_in_devtab(cmd_t *cmd, struct zone_devtab *devtab, boolean_t fill_in_only) 25947c478bd9Sstevel@tonic-gate { 25957c478bd9Sstevel@tonic-gate int err, i; 25967c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 25977c478bd9Sstevel@tonic-gate 2598bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK) 25997c478bd9Sstevel@tonic-gate return (err); 26007c478bd9Sstevel@tonic-gate 2601e193d1e6Svp157776 bzero(devtab, sizeof (*devtab)); 26027c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 26037c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i]; 26047c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 26057c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here.")); 2606bbec428eSgjelinek saw_error = B_TRUE; 26077c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 26087c478bd9Sstevel@tonic-gate } 26097c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) { 26107c478bd9Sstevel@tonic-gate case PT_MATCH: 26117c478bd9Sstevel@tonic-gate (void) strlcpy(devtab->zone_dev_match, pp->pv_simple, 26127c478bd9Sstevel@tonic-gate sizeof (devtab->zone_dev_match)); 26137c478bd9Sstevel@tonic-gate break; 26147c478bd9Sstevel@tonic-gate default: 26157c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 2616bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE); 26177c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 26187c478bd9Sstevel@tonic-gate } 26197c478bd9Sstevel@tonic-gate } 26207c478bd9Sstevel@tonic-gate if (fill_in_only) 26217c478bd9Sstevel@tonic-gate return (Z_OK); 26227c478bd9Sstevel@tonic-gate err = zonecfg_lookup_dev(handle, devtab); 26237c478bd9Sstevel@tonic-gate return (err); 26247c478bd9Sstevel@tonic-gate } 26257c478bd9Sstevel@tonic-gate 26267c478bd9Sstevel@tonic-gate static int 2627bbec428eSgjelinek fill_in_rctltab(cmd_t *cmd, struct zone_rctltab *rctltab, 2628bbec428eSgjelinek boolean_t fill_in_only) 26297c478bd9Sstevel@tonic-gate { 26307c478bd9Sstevel@tonic-gate int err, i; 26317c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 26327c478bd9Sstevel@tonic-gate 2633bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK) 26347c478bd9Sstevel@tonic-gate return (err); 26357c478bd9Sstevel@tonic-gate 2636e193d1e6Svp157776 bzero(rctltab, sizeof (*rctltab)); 26377c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 26387c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i]; 26397c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 26407c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here.")); 2641bbec428eSgjelinek saw_error = B_TRUE; 26427c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 26437c478bd9Sstevel@tonic-gate } 26447c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) { 26457c478bd9Sstevel@tonic-gate case PT_NAME: 26467c478bd9Sstevel@tonic-gate (void) strlcpy(rctltab->zone_rctl_name, pp->pv_simple, 26477c478bd9Sstevel@tonic-gate sizeof (rctltab->zone_rctl_name)); 26487c478bd9Sstevel@tonic-gate break; 26497c478bd9Sstevel@tonic-gate default: 26507c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 2651bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE); 26527c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 26537c478bd9Sstevel@tonic-gate } 26547c478bd9Sstevel@tonic-gate } 26557c478bd9Sstevel@tonic-gate if (fill_in_only) 26567c478bd9Sstevel@tonic-gate return (Z_OK); 26577c478bd9Sstevel@tonic-gate err = zonecfg_lookup_rctl(handle, rctltab); 26587c478bd9Sstevel@tonic-gate return (err); 26597c478bd9Sstevel@tonic-gate } 26607c478bd9Sstevel@tonic-gate 26617c478bd9Sstevel@tonic-gate static int 2662bbec428eSgjelinek fill_in_attrtab(cmd_t *cmd, struct zone_attrtab *attrtab, 2663bbec428eSgjelinek boolean_t fill_in_only) 26647c478bd9Sstevel@tonic-gate { 26657c478bd9Sstevel@tonic-gate int err, i; 26667c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 26677c478bd9Sstevel@tonic-gate 2668bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK) 26697c478bd9Sstevel@tonic-gate return (err); 26707c478bd9Sstevel@tonic-gate 2671e193d1e6Svp157776 bzero(attrtab, sizeof (*attrtab)); 26727c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 26737c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i]; 26747c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 26757c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here.")); 2676bbec428eSgjelinek saw_error = B_TRUE; 26777c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 26787c478bd9Sstevel@tonic-gate } 26797c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) { 26807c478bd9Sstevel@tonic-gate case PT_NAME: 26817c478bd9Sstevel@tonic-gate (void) strlcpy(attrtab->zone_attr_name, pp->pv_simple, 26827c478bd9Sstevel@tonic-gate sizeof (attrtab->zone_attr_name)); 26837c478bd9Sstevel@tonic-gate break; 26847c478bd9Sstevel@tonic-gate case PT_TYPE: 26857c478bd9Sstevel@tonic-gate (void) strlcpy(attrtab->zone_attr_type, pp->pv_simple, 26867c478bd9Sstevel@tonic-gate sizeof (attrtab->zone_attr_type)); 26877c478bd9Sstevel@tonic-gate break; 26887c478bd9Sstevel@tonic-gate case PT_VALUE: 26897c478bd9Sstevel@tonic-gate (void) strlcpy(attrtab->zone_attr_value, pp->pv_simple, 26907c478bd9Sstevel@tonic-gate sizeof (attrtab->zone_attr_value)); 26917c478bd9Sstevel@tonic-gate break; 26927c478bd9Sstevel@tonic-gate default: 26937c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 2694bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE); 26957c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 26967c478bd9Sstevel@tonic-gate } 26977c478bd9Sstevel@tonic-gate } 26987c478bd9Sstevel@tonic-gate if (fill_in_only) 26997c478bd9Sstevel@tonic-gate return (Z_OK); 27007c478bd9Sstevel@tonic-gate err = zonecfg_lookup_attr(handle, attrtab); 27017c478bd9Sstevel@tonic-gate return (err); 27027c478bd9Sstevel@tonic-gate } 27037c478bd9Sstevel@tonic-gate 2704fa9e4066Sahrens static int 2705bbec428eSgjelinek fill_in_dstab(cmd_t *cmd, struct zone_dstab *dstab, boolean_t fill_in_only) 2706fa9e4066Sahrens { 2707fa9e4066Sahrens int err, i; 2708fa9e4066Sahrens property_value_ptr_t pp; 2709fa9e4066Sahrens 2710bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK) 2711fa9e4066Sahrens return (err); 2712fa9e4066Sahrens 2713fa9e4066Sahrens dstab->zone_dataset_name[0] = '\0'; 2714fa9e4066Sahrens for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 2715fa9e4066Sahrens pp = cmd->cmd_property_ptr[i]; 2716fa9e4066Sahrens if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 2717fa9e4066Sahrens zerr(gettext("A simple value was expected here.")); 2718bbec428eSgjelinek saw_error = B_TRUE; 2719fa9e4066Sahrens return (Z_INSUFFICIENT_SPEC); 2720fa9e4066Sahrens } 2721fa9e4066Sahrens switch (cmd->cmd_prop_name[i]) { 2722fa9e4066Sahrens case PT_NAME: 2723fa9e4066Sahrens (void) strlcpy(dstab->zone_dataset_name, pp->pv_simple, 2724fa9e4066Sahrens sizeof (dstab->zone_dataset_name)); 2725fa9e4066Sahrens break; 2726fa9e4066Sahrens default: 2727fa9e4066Sahrens zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 2728bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE); 2729fa9e4066Sahrens return (Z_INSUFFICIENT_SPEC); 2730fa9e4066Sahrens } 2731fa9e4066Sahrens } 2732fa9e4066Sahrens if (fill_in_only) 2733fa9e4066Sahrens return (Z_OK); 2734fa9e4066Sahrens return (zonecfg_lookup_ds(handle, dstab)); 2735fa9e4066Sahrens } 2736fa9e4066Sahrens 27377c478bd9Sstevel@tonic-gate static void 27380209230bSgjelinek remove_aliased_rctl(int type, char *name) 27397c478bd9Sstevel@tonic-gate { 27400209230bSgjelinek int err; 27410209230bSgjelinek uint64_t tmp; 27427c478bd9Sstevel@tonic-gate 27430209230bSgjelinek if ((err = zonecfg_get_aliased_rctl(handle, name, &tmp)) != Z_OK) { 27440209230bSgjelinek zerr("%s %s: %s", cmd_to_str(CMD_CLEAR), pt_to_str(type), 27450209230bSgjelinek zonecfg_strerror(err)); 2746bbec428eSgjelinek saw_error = B_TRUE; 27477c478bd9Sstevel@tonic-gate return; 27487c478bd9Sstevel@tonic-gate } 27490209230bSgjelinek if ((err = zonecfg_rm_aliased_rctl(handle, name)) != Z_OK) { 27500209230bSgjelinek zerr("%s %s: %s", cmd_to_str(CMD_CLEAR), pt_to_str(type), 27510209230bSgjelinek zonecfg_strerror(err)); 2752bbec428eSgjelinek saw_error = B_TRUE; 27530209230bSgjelinek } else { 2754bbec428eSgjelinek need_to_commit = B_TRUE; 27550209230bSgjelinek } 27560209230bSgjelinek } 27577c478bd9Sstevel@tonic-gate 27580209230bSgjelinek static boolean_t 27590209230bSgjelinek prompt_remove_resource(cmd_t *cmd, char *rsrc) 27600209230bSgjelinek { 27610209230bSgjelinek int num; 27620209230bSgjelinek int answer; 27630209230bSgjelinek int arg; 27640209230bSgjelinek boolean_t force = B_FALSE; 27650209230bSgjelinek char prompt[128]; 2766bbec428eSgjelinek boolean_t arg_err = B_FALSE; 27677c478bd9Sstevel@tonic-gate 27680209230bSgjelinek optind = 0; 27690209230bSgjelinek while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "F")) != EOF) { 27700209230bSgjelinek switch (arg) { 27710209230bSgjelinek case 'F': 27720209230bSgjelinek force = B_TRUE; 27730209230bSgjelinek break; 27740209230bSgjelinek default: 2775bbec428eSgjelinek arg_err = B_TRUE; 27767ec75eb8Sgjelinek break; 27777ec75eb8Sgjelinek } 27787ec75eb8Sgjelinek } 27797ec75eb8Sgjelinek if (arg_err) 27800209230bSgjelinek return (B_FALSE); 27817ec75eb8Sgjelinek 27820209230bSgjelinek 27830209230bSgjelinek num = zonecfg_num_resources(handle, rsrc); 27840209230bSgjelinek 27850209230bSgjelinek if (num == 0) { 27860209230bSgjelinek z_cmd_rt_perror(CMD_REMOVE, cmd->cmd_res_type, Z_NO_ENTRY, 2787bbec428eSgjelinek B_TRUE); 27880209230bSgjelinek return (B_FALSE); 27890209230bSgjelinek } 27900209230bSgjelinek if (num > 1 && !force) { 27910209230bSgjelinek if (!interactive_mode) { 27920209230bSgjelinek zerr(gettext("There are multiple instances of this " 27930209230bSgjelinek "resource. Either qualify the resource to\n" 27940209230bSgjelinek "remove a single instance or use the -F option to " 27950209230bSgjelinek "remove all instances.")); 2796bbec428eSgjelinek saw_error = B_TRUE; 27970209230bSgjelinek return (B_FALSE); 27980209230bSgjelinek } 27990209230bSgjelinek (void) snprintf(prompt, sizeof (prompt), gettext( 28000209230bSgjelinek "Are you sure you want to remove ALL '%s' resources"), 28010209230bSgjelinek rsrc); 2802bbec428eSgjelinek answer = ask_yesno(B_FALSE, prompt); 28030209230bSgjelinek if (answer == -1) { 28040209230bSgjelinek zerr(gettext("Resource incomplete.")); 28050209230bSgjelinek return (B_FALSE); 28060209230bSgjelinek } 28070209230bSgjelinek if (answer != 1) 28080209230bSgjelinek return (B_FALSE); 28090209230bSgjelinek } 28100209230bSgjelinek return (B_TRUE); 28110209230bSgjelinek } 28120209230bSgjelinek 28130209230bSgjelinek static void 28140209230bSgjelinek remove_fs(cmd_t *cmd) 28150209230bSgjelinek { 28160209230bSgjelinek int err; 28170209230bSgjelinek 28180209230bSgjelinek /* traditional, qualified fs removal */ 28190209230bSgjelinek if (cmd->cmd_prop_nv_pairs > 0) { 28200209230bSgjelinek struct zone_fstab fstab; 28210209230bSgjelinek 2822bbec428eSgjelinek if ((err = fill_in_fstab(cmd, &fstab, B_FALSE)) != Z_OK) { 2823bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_FS, err, B_TRUE); 28247c478bd9Sstevel@tonic-gate return; 28257c478bd9Sstevel@tonic-gate } 28267c478bd9Sstevel@tonic-gate if ((err = zonecfg_delete_filesystem(handle, &fstab)) != Z_OK) 2827bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_FS, err, B_TRUE); 28287c478bd9Sstevel@tonic-gate else 2829bbec428eSgjelinek need_to_commit = B_TRUE; 28307c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(fstab.zone_fs_options); 28317c478bd9Sstevel@tonic-gate return; 28320209230bSgjelinek } 28330209230bSgjelinek 28340209230bSgjelinek /* 28350209230bSgjelinek * unqualified fs removal. remove all fs's but prompt if more 28360209230bSgjelinek * than one. 28370209230bSgjelinek */ 28380209230bSgjelinek if (!prompt_remove_resource(cmd, "fs")) 28390209230bSgjelinek return; 28400209230bSgjelinek 28410209230bSgjelinek if ((err = zonecfg_del_all_resources(handle, "fs")) != Z_OK) 2842bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_FS, err, B_TRUE); 28430209230bSgjelinek else 2844bbec428eSgjelinek need_to_commit = B_TRUE; 28450209230bSgjelinek } 28460209230bSgjelinek 28470209230bSgjelinek static void 28480209230bSgjelinek remove_ipd(cmd_t *cmd) 28490209230bSgjelinek { 28500209230bSgjelinek int err; 28510209230bSgjelinek 2852087719fdSdp if (state_atleast(ZONE_STATE_INSTALLED)) { 28530209230bSgjelinek zerr(gettext("Zone %s already installed; %s %s not allowed."), 28540209230bSgjelinek zone, cmd_to_str(CMD_REMOVE), rt_to_str(RT_IPD)); 28557c478bd9Sstevel@tonic-gate return; 28567c478bd9Sstevel@tonic-gate } 28570209230bSgjelinek 28580209230bSgjelinek /* traditional, qualified ipd removal */ 28590209230bSgjelinek if (cmd->cmd_prop_nv_pairs > 0) { 28600209230bSgjelinek struct zone_fstab fstab; 28610209230bSgjelinek 2862bbec428eSgjelinek if ((err = fill_in_ipdtab(cmd, &fstab, B_FALSE)) != Z_OK) { 2863bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_IPD, err, B_TRUE); 28647c478bd9Sstevel@tonic-gate return; 28657c478bd9Sstevel@tonic-gate } 28667c478bd9Sstevel@tonic-gate if ((err = zonecfg_delete_ipd(handle, &fstab)) != Z_OK) 2867bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_IPD, err, B_TRUE); 28687c478bd9Sstevel@tonic-gate else 2869bbec428eSgjelinek need_to_commit = B_TRUE; 28707c478bd9Sstevel@tonic-gate return; 28710209230bSgjelinek } 28720209230bSgjelinek 28730209230bSgjelinek /* 28740209230bSgjelinek * unqualified ipd removal. remove all ipds but prompt if more 28750209230bSgjelinek * than one. 28760209230bSgjelinek */ 28770209230bSgjelinek if (!prompt_remove_resource(cmd, "inherit-pkg-dir")) 28780209230bSgjelinek return; 28790209230bSgjelinek 28800209230bSgjelinek if ((err = zonecfg_del_all_resources(handle, "inherit-pkg-dir")) 28810209230bSgjelinek != Z_OK) 2882bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_IPD, err, B_TRUE); 28830209230bSgjelinek else 2884bbec428eSgjelinek need_to_commit = B_TRUE; 28850209230bSgjelinek } 28860209230bSgjelinek 28870209230bSgjelinek static void 28880209230bSgjelinek remove_net(cmd_t *cmd) 28890209230bSgjelinek { 28900209230bSgjelinek int err; 28910209230bSgjelinek 28920209230bSgjelinek /* traditional, qualified net removal */ 28930209230bSgjelinek if (cmd->cmd_prop_nv_pairs > 0) { 28940209230bSgjelinek struct zone_nwiftab nwiftab; 28950209230bSgjelinek 2896bbec428eSgjelinek if ((err = fill_in_nwiftab(cmd, &nwiftab, B_FALSE)) != Z_OK) { 2897bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_NET, err, B_TRUE); 28987c478bd9Sstevel@tonic-gate return; 28997c478bd9Sstevel@tonic-gate } 29007c478bd9Sstevel@tonic-gate if ((err = zonecfg_delete_nwif(handle, &nwiftab)) != Z_OK) 2901bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_NET, err, B_TRUE); 29027c478bd9Sstevel@tonic-gate else 2903bbec428eSgjelinek need_to_commit = B_TRUE; 29047c478bd9Sstevel@tonic-gate return; 29050209230bSgjelinek } 29060209230bSgjelinek 29070209230bSgjelinek /* 29080209230bSgjelinek * unqualified net removal. remove all nets but prompt if more 29090209230bSgjelinek * than one. 29100209230bSgjelinek */ 29110209230bSgjelinek if (!prompt_remove_resource(cmd, "net")) 29120209230bSgjelinek return; 29130209230bSgjelinek 29140209230bSgjelinek if ((err = zonecfg_del_all_resources(handle, "net")) != Z_OK) 2915bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_NET, err, B_TRUE); 29160209230bSgjelinek else 2917bbec428eSgjelinek need_to_commit = B_TRUE; 29180209230bSgjelinek } 29190209230bSgjelinek 29200209230bSgjelinek static void 29210209230bSgjelinek remove_device(cmd_t *cmd) 29220209230bSgjelinek { 29230209230bSgjelinek int err; 29240209230bSgjelinek 29250209230bSgjelinek /* traditional, qualified device removal */ 29260209230bSgjelinek if (cmd->cmd_prop_nv_pairs > 0) { 29270209230bSgjelinek struct zone_devtab devtab; 29280209230bSgjelinek 2929bbec428eSgjelinek if ((err = fill_in_devtab(cmd, &devtab, B_FALSE)) != Z_OK) { 2930bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DEVICE, err, B_TRUE); 29317c478bd9Sstevel@tonic-gate return; 29327c478bd9Sstevel@tonic-gate } 29337c478bd9Sstevel@tonic-gate if ((err = zonecfg_delete_dev(handle, &devtab)) != Z_OK) 2934bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DEVICE, err, B_TRUE); 29357c478bd9Sstevel@tonic-gate else 2936bbec428eSgjelinek need_to_commit = B_TRUE; 29377c478bd9Sstevel@tonic-gate return; 29380209230bSgjelinek } 29390209230bSgjelinek 29400209230bSgjelinek /* 29410209230bSgjelinek * unqualified device removal. remove all devices but prompt if more 29420209230bSgjelinek * than one. 29430209230bSgjelinek */ 29440209230bSgjelinek if (!prompt_remove_resource(cmd, "device")) 29450209230bSgjelinek return; 29460209230bSgjelinek 29470209230bSgjelinek if ((err = zonecfg_del_all_resources(handle, "device")) != Z_OK) 2948bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DEVICE, err, B_TRUE); 29490209230bSgjelinek else 2950bbec428eSgjelinek need_to_commit = B_TRUE; 29510209230bSgjelinek } 29520209230bSgjelinek 29530209230bSgjelinek static void 29540209230bSgjelinek remove_attr(cmd_t *cmd) 29550209230bSgjelinek { 29560209230bSgjelinek int err; 29570209230bSgjelinek 29580209230bSgjelinek /* traditional, qualified attr removal */ 29590209230bSgjelinek if (cmd->cmd_prop_nv_pairs > 0) { 29600209230bSgjelinek struct zone_attrtab attrtab; 29610209230bSgjelinek 2962bbec428eSgjelinek if ((err = fill_in_attrtab(cmd, &attrtab, B_FALSE)) != Z_OK) { 2963bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_ATTR, err, B_TRUE); 29640209230bSgjelinek return; 29650209230bSgjelinek } 29660209230bSgjelinek if ((err = zonecfg_delete_attr(handle, &attrtab)) != Z_OK) 2967bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_ATTR, err, B_TRUE); 29680209230bSgjelinek else 2969bbec428eSgjelinek need_to_commit = B_TRUE; 29700209230bSgjelinek return; 29710209230bSgjelinek } 29720209230bSgjelinek 29730209230bSgjelinek /* 29740209230bSgjelinek * unqualified attr removal. remove all attrs but prompt if more 29750209230bSgjelinek * than one. 29760209230bSgjelinek */ 29770209230bSgjelinek if (!prompt_remove_resource(cmd, "attr")) 29780209230bSgjelinek return; 29790209230bSgjelinek 29800209230bSgjelinek if ((err = zonecfg_del_all_resources(handle, "attr")) != Z_OK) 2981bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_ATTR, err, B_TRUE); 29820209230bSgjelinek else 2983bbec428eSgjelinek need_to_commit = B_TRUE; 29840209230bSgjelinek } 29850209230bSgjelinek 29860209230bSgjelinek static void 29870209230bSgjelinek remove_dataset(cmd_t *cmd) 29880209230bSgjelinek { 29890209230bSgjelinek int err; 29900209230bSgjelinek 29910209230bSgjelinek /* traditional, qualified dataset removal */ 29920209230bSgjelinek if (cmd->cmd_prop_nv_pairs > 0) { 29930209230bSgjelinek struct zone_dstab dstab; 29940209230bSgjelinek 2995bbec428eSgjelinek if ((err = fill_in_dstab(cmd, &dstab, B_FALSE)) != Z_OK) { 2996bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DATASET, err, B_TRUE); 29970209230bSgjelinek return; 29980209230bSgjelinek } 29990209230bSgjelinek if ((err = zonecfg_delete_ds(handle, &dstab)) != Z_OK) 3000bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DATASET, err, B_TRUE); 30010209230bSgjelinek else 3002bbec428eSgjelinek need_to_commit = B_TRUE; 30030209230bSgjelinek return; 30040209230bSgjelinek } 30050209230bSgjelinek 30060209230bSgjelinek /* 30070209230bSgjelinek * unqualified dataset removal. remove all datasets but prompt if more 30080209230bSgjelinek * than one. 30090209230bSgjelinek */ 30100209230bSgjelinek if (!prompt_remove_resource(cmd, "dataset")) 30110209230bSgjelinek return; 30120209230bSgjelinek 30130209230bSgjelinek if ((err = zonecfg_del_all_resources(handle, "dataset")) != Z_OK) 3014bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DATASET, err, B_TRUE); 30150209230bSgjelinek else 3016bbec428eSgjelinek need_to_commit = B_TRUE; 30170209230bSgjelinek } 30180209230bSgjelinek 30190209230bSgjelinek static void 30200209230bSgjelinek remove_rctl(cmd_t *cmd) 30210209230bSgjelinek { 30220209230bSgjelinek int err; 30230209230bSgjelinek 30240209230bSgjelinek /* traditional, qualified rctl removal */ 30250209230bSgjelinek if (cmd->cmd_prop_nv_pairs > 0) { 30260209230bSgjelinek struct zone_rctltab rctltab; 30270209230bSgjelinek 3028bbec428eSgjelinek if ((err = fill_in_rctltab(cmd, &rctltab, B_FALSE)) != Z_OK) { 3029bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_RCTL, err, B_TRUE); 30307c478bd9Sstevel@tonic-gate return; 30317c478bd9Sstevel@tonic-gate } 30327c478bd9Sstevel@tonic-gate if ((err = zonecfg_delete_rctl(handle, &rctltab)) != Z_OK) 3033bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_RCTL, err, B_TRUE); 30347c478bd9Sstevel@tonic-gate else 3035bbec428eSgjelinek need_to_commit = B_TRUE; 30367c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctltab.zone_rctl_valptr); 30377c478bd9Sstevel@tonic-gate return; 30387c478bd9Sstevel@tonic-gate } 30390209230bSgjelinek 30400209230bSgjelinek /* 30410209230bSgjelinek * unqualified rctl removal. remove all rctls but prompt if more 30420209230bSgjelinek * than one. 30430209230bSgjelinek */ 30440209230bSgjelinek if (!prompt_remove_resource(cmd, "rctl")) 30450209230bSgjelinek return; 30460209230bSgjelinek 30470209230bSgjelinek if ((err = zonecfg_del_all_resources(handle, "rctl")) != Z_OK) 3048bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_RCTL, err, B_TRUE); 30497c478bd9Sstevel@tonic-gate else 3050bbec428eSgjelinek need_to_commit = B_TRUE; 30510209230bSgjelinek } 30520209230bSgjelinek 30530209230bSgjelinek static void 30540209230bSgjelinek remove_pset() 30550209230bSgjelinek { 30560209230bSgjelinek int err; 30570209230bSgjelinek struct zone_psettab psettab; 30580209230bSgjelinek 30590209230bSgjelinek if ((err = zonecfg_lookup_pset(handle, &psettab)) != Z_OK) { 3060bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DCPU, err, B_TRUE); 30610209230bSgjelinek return; 30620209230bSgjelinek } 30630209230bSgjelinek if ((err = zonecfg_delete_pset(handle)) != Z_OK) 3064bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DCPU, err, B_TRUE); 30650209230bSgjelinek else 3066bbec428eSgjelinek need_to_commit = B_TRUE; 30670209230bSgjelinek } 30680209230bSgjelinek 30690209230bSgjelinek static void 3070c97ad5cdSakolb remove_pcap() 3071c97ad5cdSakolb { 3072c97ad5cdSakolb int err; 3073c97ad5cdSakolb uint64_t tmp; 3074c97ad5cdSakolb 3075c97ad5cdSakolb if (zonecfg_get_aliased_rctl(handle, ALIAS_CPUCAP, &tmp) != Z_OK) { 3076c97ad5cdSakolb zerr("%s %s: %s", cmd_to_str(CMD_REMOVE), rt_to_str(RT_PCAP), 3077c97ad5cdSakolb zonecfg_strerror(Z_NO_RESOURCE_TYPE)); 3078bbec428eSgjelinek saw_error = B_TRUE; 3079c97ad5cdSakolb return; 3080c97ad5cdSakolb } 3081c97ad5cdSakolb 3082c97ad5cdSakolb if ((err = zonecfg_rm_aliased_rctl(handle, ALIAS_CPUCAP)) != Z_OK) 3083bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_PCAP, err, B_TRUE); 3084c97ad5cdSakolb else 3085bbec428eSgjelinek need_to_commit = B_TRUE; 3086c97ad5cdSakolb } 3087c97ad5cdSakolb 3088c97ad5cdSakolb static void 30890209230bSgjelinek remove_mcap() 30900209230bSgjelinek { 30910209230bSgjelinek int err, res1, res2, res3; 30920209230bSgjelinek uint64_t tmp; 30930209230bSgjelinek struct zone_mcaptab mcaptab; 30940209230bSgjelinek boolean_t revert = B_FALSE; 30950209230bSgjelinek 30960209230bSgjelinek res1 = zonecfg_lookup_mcap(handle, &mcaptab); 30970209230bSgjelinek res2 = zonecfg_get_aliased_rctl(handle, ALIAS_MAXSWAP, &tmp); 30980209230bSgjelinek res3 = zonecfg_get_aliased_rctl(handle, ALIAS_MAXLOCKEDMEM, &tmp); 30990209230bSgjelinek 31000209230bSgjelinek /* if none of these exist, there is no resource to remove */ 31010209230bSgjelinek if (res1 != Z_OK && res2 != Z_OK && res3 != Z_OK) { 31020209230bSgjelinek zerr("%s %s: %s", cmd_to_str(CMD_REMOVE), rt_to_str(RT_MCAP), 31030209230bSgjelinek zonecfg_strerror(Z_NO_RESOURCE_TYPE)); 3104bbec428eSgjelinek saw_error = B_TRUE; 31050209230bSgjelinek return; 31060209230bSgjelinek } 31070209230bSgjelinek if (res1 == Z_OK) { 31080209230bSgjelinek if ((err = zonecfg_delete_mcap(handle)) != Z_OK) { 3109bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_MCAP, err, B_TRUE); 31100209230bSgjelinek revert = B_TRUE; 31110209230bSgjelinek } else { 3112bbec428eSgjelinek need_to_commit = B_TRUE; 31130209230bSgjelinek } 31140209230bSgjelinek } 31150209230bSgjelinek if (res2 == Z_OK) { 31160209230bSgjelinek if ((err = zonecfg_rm_aliased_rctl(handle, ALIAS_MAXSWAP)) 31170209230bSgjelinek != Z_OK) { 3118bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_MCAP, err, B_TRUE); 31190209230bSgjelinek revert = B_TRUE; 31200209230bSgjelinek } else { 3121bbec428eSgjelinek need_to_commit = B_TRUE; 31220209230bSgjelinek } 31230209230bSgjelinek } 31240209230bSgjelinek if (res3 == Z_OK) { 31250209230bSgjelinek if ((err = zonecfg_rm_aliased_rctl(handle, ALIAS_MAXLOCKEDMEM)) 31260209230bSgjelinek != Z_OK) { 3127bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_MCAP, err, B_TRUE); 31280209230bSgjelinek revert = B_TRUE; 31290209230bSgjelinek } else { 3130bbec428eSgjelinek need_to_commit = B_TRUE; 31310209230bSgjelinek } 31320209230bSgjelinek } 31330209230bSgjelinek 31340209230bSgjelinek if (revert) 3135bbec428eSgjelinek need_to_commit = B_FALSE; 31360209230bSgjelinek } 31370209230bSgjelinek 31380209230bSgjelinek static void 31390209230bSgjelinek remove_resource(cmd_t *cmd) 31400209230bSgjelinek { 31410209230bSgjelinek int type; 31420209230bSgjelinek int arg; 3143bbec428eSgjelinek boolean_t arg_err = B_FALSE; 31440209230bSgjelinek 31450209230bSgjelinek if ((type = cmd->cmd_res_type) == RT_UNKNOWN) { 3146bbec428eSgjelinek long_usage(CMD_REMOVE, B_TRUE); 31470209230bSgjelinek return; 31480209230bSgjelinek } 31490209230bSgjelinek 31500209230bSgjelinek optind = 0; 31510209230bSgjelinek while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?F")) != EOF) { 31520209230bSgjelinek switch (arg) { 31530209230bSgjelinek case '?': 31540209230bSgjelinek longer_usage(CMD_REMOVE); 3155bbec428eSgjelinek arg_err = B_TRUE; 31567ec75eb8Sgjelinek break; 31570209230bSgjelinek case 'F': 31580209230bSgjelinek break; 31590209230bSgjelinek default: 31600209230bSgjelinek short_usage(CMD_REMOVE); 3161bbec428eSgjelinek arg_err = B_TRUE; 31627ec75eb8Sgjelinek break; 31637ec75eb8Sgjelinek } 31647ec75eb8Sgjelinek } 31657ec75eb8Sgjelinek if (arg_err) 31660209230bSgjelinek return; 31670209230bSgjelinek 3168bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 31690209230bSgjelinek return; 31700209230bSgjelinek 31710209230bSgjelinek switch (type) { 31720209230bSgjelinek case RT_FS: 31730209230bSgjelinek remove_fs(cmd); 31740209230bSgjelinek return; 31750209230bSgjelinek case RT_IPD: 31760209230bSgjelinek remove_ipd(cmd); 31770209230bSgjelinek return; 31780209230bSgjelinek case RT_NET: 31790209230bSgjelinek remove_net(cmd); 31800209230bSgjelinek return; 31810209230bSgjelinek case RT_DEVICE: 31820209230bSgjelinek remove_device(cmd); 31830209230bSgjelinek return; 31840209230bSgjelinek case RT_RCTL: 31850209230bSgjelinek remove_rctl(cmd); 31860209230bSgjelinek return; 31870209230bSgjelinek case RT_ATTR: 31880209230bSgjelinek remove_attr(cmd); 31897c478bd9Sstevel@tonic-gate return; 3190fa9e4066Sahrens case RT_DATASET: 31910209230bSgjelinek remove_dataset(cmd); 3192fa9e4066Sahrens return; 31930209230bSgjelinek case RT_DCPU: 31940209230bSgjelinek remove_pset(); 31950209230bSgjelinek return; 3196c97ad5cdSakolb case RT_PCAP: 3197c97ad5cdSakolb remove_pcap(); 3198c97ad5cdSakolb return; 31990209230bSgjelinek case RT_MCAP: 32000209230bSgjelinek remove_mcap(); 3201fa9e4066Sahrens return; 32027c478bd9Sstevel@tonic-gate default: 3203bbec428eSgjelinek zone_perror(rt_to_str(type), Z_NO_RESOURCE_TYPE, B_TRUE); 3204bbec428eSgjelinek long_usage(CMD_REMOVE, B_TRUE); 3205bbec428eSgjelinek usage(B_FALSE, HELP_RESOURCES); 32067c478bd9Sstevel@tonic-gate return; 32077c478bd9Sstevel@tonic-gate } 32087c478bd9Sstevel@tonic-gate } 32097c478bd9Sstevel@tonic-gate 32107c478bd9Sstevel@tonic-gate static void 32117c478bd9Sstevel@tonic-gate remove_property(cmd_t *cmd) 32127c478bd9Sstevel@tonic-gate { 32137c478bd9Sstevel@tonic-gate char *prop_id; 32147c478bd9Sstevel@tonic-gate int err, res_type, prop_type; 32157c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 32167c478bd9Sstevel@tonic-gate struct zone_rctlvaltab *rctlvaltab; 32177c478bd9Sstevel@tonic-gate complex_property_ptr_t cx; 32187c478bd9Sstevel@tonic-gate 32197c478bd9Sstevel@tonic-gate res_type = resource_scope; 32207c478bd9Sstevel@tonic-gate prop_type = cmd->cmd_prop_name[0]; 32217c478bd9Sstevel@tonic-gate if (res_type == RT_UNKNOWN || prop_type == PT_UNKNOWN) { 3222bbec428eSgjelinek long_usage(CMD_REMOVE, B_TRUE); 32237c478bd9Sstevel@tonic-gate return; 32247c478bd9Sstevel@tonic-gate } 32257c478bd9Sstevel@tonic-gate 32267c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs != 1) { 3227bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 32287c478bd9Sstevel@tonic-gate return; 32297c478bd9Sstevel@tonic-gate } 32307c478bd9Sstevel@tonic-gate 3231bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 32327c478bd9Sstevel@tonic-gate return; 32337c478bd9Sstevel@tonic-gate 32347c478bd9Sstevel@tonic-gate switch (res_type) { 32357c478bd9Sstevel@tonic-gate case RT_FS: 32367c478bd9Sstevel@tonic-gate if (prop_type != PT_OPTIONS) { 32377c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 3238bbec428eSgjelinek B_TRUE); 3239bbec428eSgjelinek long_usage(CMD_REMOVE, B_TRUE); 3240bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 32417c478bd9Sstevel@tonic-gate return; 32427c478bd9Sstevel@tonic-gate } 32437c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[0]; 32447c478bd9Sstevel@tonic-gate if (pp->pv_type == PROP_VAL_COMPLEX) { 32457c478bd9Sstevel@tonic-gate zerr(gettext("A %s or %s value was expected here."), 32467c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_SIMPLE), 32477c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_LIST)); 3248bbec428eSgjelinek saw_error = B_TRUE; 32497c478bd9Sstevel@tonic-gate return; 32507c478bd9Sstevel@tonic-gate } 32517c478bd9Sstevel@tonic-gate if (pp->pv_type == PROP_VAL_SIMPLE) { 32527c478bd9Sstevel@tonic-gate if (pp->pv_simple == NULL) { 3253bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 32547c478bd9Sstevel@tonic-gate return; 32557c478bd9Sstevel@tonic-gate } 32567c478bd9Sstevel@tonic-gate prop_id = pp->pv_simple; 32577c478bd9Sstevel@tonic-gate err = zonecfg_remove_fs_option(&in_progress_fstab, 32587c478bd9Sstevel@tonic-gate prop_id); 32597c478bd9Sstevel@tonic-gate if (err != Z_OK) 3260bbec428eSgjelinek zone_perror(pt_to_str(prop_type), err, B_TRUE); 32617c478bd9Sstevel@tonic-gate } else { 32627c478bd9Sstevel@tonic-gate list_property_ptr_t list; 32637c478bd9Sstevel@tonic-gate 32647c478bd9Sstevel@tonic-gate for (list = pp->pv_list; list != NULL; 32657c478bd9Sstevel@tonic-gate list = list->lp_next) { 32667c478bd9Sstevel@tonic-gate prop_id = list->lp_simple; 32677c478bd9Sstevel@tonic-gate if (prop_id == NULL) 32687c478bd9Sstevel@tonic-gate break; 32697c478bd9Sstevel@tonic-gate err = zonecfg_remove_fs_option( 32707c478bd9Sstevel@tonic-gate &in_progress_fstab, prop_id); 32717c478bd9Sstevel@tonic-gate if (err != Z_OK) 32727c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), err, 3273bbec428eSgjelinek B_TRUE); 32747c478bd9Sstevel@tonic-gate } 32757c478bd9Sstevel@tonic-gate } 32767c478bd9Sstevel@tonic-gate return; 32777c478bd9Sstevel@tonic-gate case RT_RCTL: 32787c478bd9Sstevel@tonic-gate if (prop_type != PT_VALUE) { 32797c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 3280bbec428eSgjelinek B_TRUE); 3281bbec428eSgjelinek long_usage(CMD_REMOVE, B_TRUE); 3282bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 32837c478bd9Sstevel@tonic-gate return; 32847c478bd9Sstevel@tonic-gate } 32857c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[0]; 32867c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_COMPLEX) { 32877c478bd9Sstevel@tonic-gate zerr(gettext("A %s value was expected here."), 32887c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_COMPLEX)); 3289bbec428eSgjelinek saw_error = B_TRUE; 32907c478bd9Sstevel@tonic-gate return; 32917c478bd9Sstevel@tonic-gate } 32927c478bd9Sstevel@tonic-gate if ((rctlvaltab = alloc_rctlvaltab()) == NULL) { 3293bbec428eSgjelinek zone_perror(zone, Z_NOMEM, B_TRUE); 32947c478bd9Sstevel@tonic-gate exit(Z_ERR); 32957c478bd9Sstevel@tonic-gate } 32967c478bd9Sstevel@tonic-gate for (cx = pp->pv_complex; cx != NULL; cx = cx->cp_next) { 32977c478bd9Sstevel@tonic-gate switch (cx->cp_type) { 32987c478bd9Sstevel@tonic-gate case PT_PRIV: 32997c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_priv, 33007c478bd9Sstevel@tonic-gate cx->cp_value, 33017c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_priv)); 33027c478bd9Sstevel@tonic-gate break; 33037c478bd9Sstevel@tonic-gate case PT_LIMIT: 33047c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_limit, 33057c478bd9Sstevel@tonic-gate cx->cp_value, 33067c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_limit)); 33077c478bd9Sstevel@tonic-gate break; 33087c478bd9Sstevel@tonic-gate case PT_ACTION: 33097c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_action, 33107c478bd9Sstevel@tonic-gate cx->cp_value, 33117c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_action)); 33127c478bd9Sstevel@tonic-gate break; 33137c478bd9Sstevel@tonic-gate default: 33147c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), 3315bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE); 3316bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 3317bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 33187c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctlvaltab); 33197c478bd9Sstevel@tonic-gate return; 33207c478bd9Sstevel@tonic-gate } 33217c478bd9Sstevel@tonic-gate } 33227c478bd9Sstevel@tonic-gate rctlvaltab->zone_rctlval_next = NULL; 33237c478bd9Sstevel@tonic-gate err = zonecfg_remove_rctl_value(&in_progress_rctltab, 33247c478bd9Sstevel@tonic-gate rctlvaltab); 33257c478bd9Sstevel@tonic-gate if (err != Z_OK) 3326bbec428eSgjelinek zone_perror(pt_to_str(prop_type), err, B_TRUE); 33277c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctlvaltab); 33287c478bd9Sstevel@tonic-gate return; 3329de860bd9Sgfaden case RT_NET: 3330de860bd9Sgfaden if (prop_type != PT_DEFROUTER) { 3331de860bd9Sgfaden zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 3332bbec428eSgjelinek B_TRUE); 3333bbec428eSgjelinek long_usage(CMD_REMOVE, B_TRUE); 3334bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 3335de860bd9Sgfaden return; 3336de860bd9Sgfaden } else { 3337de860bd9Sgfaden bzero(&in_progress_nwiftab.zone_nwif_defrouter, 3338de860bd9Sgfaden sizeof (in_progress_nwiftab.zone_nwif_defrouter)); 3339de860bd9Sgfaden return; 3340de860bd9Sgfaden } 33417c478bd9Sstevel@tonic-gate default: 3342bbec428eSgjelinek zone_perror(rt_to_str(res_type), Z_NO_RESOURCE_TYPE, B_TRUE); 3343bbec428eSgjelinek long_usage(CMD_REMOVE, B_TRUE); 3344bbec428eSgjelinek usage(B_FALSE, HELP_RESOURCES); 33457c478bd9Sstevel@tonic-gate return; 33467c478bd9Sstevel@tonic-gate } 33477c478bd9Sstevel@tonic-gate } 33487c478bd9Sstevel@tonic-gate 33497c478bd9Sstevel@tonic-gate void 33507c478bd9Sstevel@tonic-gate remove_func(cmd_t *cmd) 33517c478bd9Sstevel@tonic-gate { 33527c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_REMOVE)) 33537c478bd9Sstevel@tonic-gate return; 33547c478bd9Sstevel@tonic-gate 33557c478bd9Sstevel@tonic-gate assert(cmd != NULL); 33567c478bd9Sstevel@tonic-gate 33570209230bSgjelinek if (global_scope) { 33580209230bSgjelinek if (gz_invalid_resource(cmd->cmd_res_type)) { 33590209230bSgjelinek zerr(gettext("%s is not a valid resource for the " 33600209230bSgjelinek "global zone."), rt_to_str(cmd->cmd_res_type)); 3361bbec428eSgjelinek saw_error = B_TRUE; 33620209230bSgjelinek return; 33630209230bSgjelinek } 33647c478bd9Sstevel@tonic-gate remove_resource(cmd); 33650209230bSgjelinek } else { 33667c478bd9Sstevel@tonic-gate remove_property(cmd); 33677c478bd9Sstevel@tonic-gate } 33680209230bSgjelinek } 33690209230bSgjelinek 33700209230bSgjelinek static void 33710209230bSgjelinek clear_property(cmd_t *cmd) 33720209230bSgjelinek { 33730209230bSgjelinek int res_type, prop_type; 33740209230bSgjelinek 33750209230bSgjelinek res_type = resource_scope; 33760209230bSgjelinek prop_type = cmd->cmd_res_type; 33770209230bSgjelinek if (res_type == RT_UNKNOWN || prop_type == PT_UNKNOWN) { 3378bbec428eSgjelinek long_usage(CMD_CLEAR, B_TRUE); 33790209230bSgjelinek return; 33800209230bSgjelinek } 33810209230bSgjelinek 3382bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 33830209230bSgjelinek return; 33840209230bSgjelinek 33850209230bSgjelinek switch (res_type) { 33860209230bSgjelinek case RT_FS: 33870209230bSgjelinek if (prop_type == PT_RAW) { 33880209230bSgjelinek in_progress_fstab.zone_fs_raw[0] = '\0'; 3389bbec428eSgjelinek need_to_commit = B_TRUE; 33900209230bSgjelinek return; 33910209230bSgjelinek } 33920209230bSgjelinek break; 33930209230bSgjelinek case RT_DCPU: 33940209230bSgjelinek if (prop_type == PT_IMPORTANCE) { 33950209230bSgjelinek in_progress_psettab.zone_importance[0] = '\0'; 3396bbec428eSgjelinek need_to_commit = B_TRUE; 33970209230bSgjelinek return; 33980209230bSgjelinek } 33990209230bSgjelinek break; 34000209230bSgjelinek case RT_MCAP: 34010209230bSgjelinek switch (prop_type) { 34020209230bSgjelinek case PT_PHYSICAL: 34030209230bSgjelinek in_progress_mcaptab.zone_physmem_cap[0] = '\0'; 3404bbec428eSgjelinek need_to_commit = B_TRUE; 34050209230bSgjelinek return; 34060209230bSgjelinek case PT_SWAP: 34070209230bSgjelinek remove_aliased_rctl(PT_SWAP, ALIAS_MAXSWAP); 34080209230bSgjelinek return; 34090209230bSgjelinek case PT_LOCKED: 34100209230bSgjelinek remove_aliased_rctl(PT_LOCKED, ALIAS_MAXLOCKEDMEM); 34110209230bSgjelinek return; 34120209230bSgjelinek } 34130209230bSgjelinek break; 34140209230bSgjelinek default: 34150209230bSgjelinek break; 34160209230bSgjelinek } 34170209230bSgjelinek 3418bbec428eSgjelinek zone_perror(pt_to_str(prop_type), Z_CLEAR_DISALLOW, B_TRUE); 34190209230bSgjelinek } 34200209230bSgjelinek 34210209230bSgjelinek static void 34220209230bSgjelinek clear_global(cmd_t *cmd) 34230209230bSgjelinek { 34240209230bSgjelinek int err, type; 34250209230bSgjelinek 34260209230bSgjelinek if ((type = cmd->cmd_res_type) == RT_UNKNOWN) { 3427bbec428eSgjelinek long_usage(CMD_CLEAR, B_TRUE); 34280209230bSgjelinek return; 34290209230bSgjelinek } 34300209230bSgjelinek 3431bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 34320209230bSgjelinek return; 34330209230bSgjelinek 34340209230bSgjelinek switch (type) { 34350209230bSgjelinek case PT_ZONENAME: 34360209230bSgjelinek /* FALLTHRU */ 34370209230bSgjelinek case PT_ZONEPATH: 34380209230bSgjelinek /* FALLTHRU */ 34390209230bSgjelinek case PT_BRAND: 3440bbec428eSgjelinek zone_perror(pt_to_str(type), Z_CLEAR_DISALLOW, B_TRUE); 34410209230bSgjelinek return; 34420209230bSgjelinek case PT_AUTOBOOT: 34430209230bSgjelinek /* false is default; we'll treat as equivalent to clearing */ 34440209230bSgjelinek if ((err = zonecfg_set_autoboot(handle, B_FALSE)) != Z_OK) 3445bbec428eSgjelinek z_cmd_rt_perror(CMD_CLEAR, RT_AUTOBOOT, err, B_TRUE); 34460209230bSgjelinek else 3447bbec428eSgjelinek need_to_commit = B_TRUE; 34480209230bSgjelinek return; 34490209230bSgjelinek case PT_POOL: 34500209230bSgjelinek if ((err = zonecfg_set_pool(handle, NULL)) != Z_OK) 3451bbec428eSgjelinek z_cmd_rt_perror(CMD_CLEAR, RT_POOL, err, B_TRUE); 34520209230bSgjelinek else 3453bbec428eSgjelinek need_to_commit = B_TRUE; 34540209230bSgjelinek return; 34550209230bSgjelinek case PT_LIMITPRIV: 34560209230bSgjelinek if ((err = zonecfg_set_limitpriv(handle, NULL)) != Z_OK) 3457bbec428eSgjelinek z_cmd_rt_perror(CMD_CLEAR, RT_LIMITPRIV, err, B_TRUE); 34580209230bSgjelinek else 3459bbec428eSgjelinek need_to_commit = B_TRUE; 34600209230bSgjelinek return; 34610209230bSgjelinek case PT_BOOTARGS: 34620209230bSgjelinek if ((err = zonecfg_set_bootargs(handle, NULL)) != Z_OK) 3463bbec428eSgjelinek z_cmd_rt_perror(CMD_CLEAR, RT_BOOTARGS, err, B_TRUE); 34640209230bSgjelinek else 3465bbec428eSgjelinek need_to_commit = B_TRUE; 34660209230bSgjelinek return; 34670209230bSgjelinek case PT_SCHED: 34680209230bSgjelinek if ((err = zonecfg_set_sched(handle, NULL)) != Z_OK) 3469bbec428eSgjelinek z_cmd_rt_perror(CMD_CLEAR, RT_SCHED, err, B_TRUE); 34700209230bSgjelinek else 3471bbec428eSgjelinek need_to_commit = B_TRUE; 34720209230bSgjelinek return; 3473f4b3ec61Sdh155122 case PT_IPTYPE: 3474f4b3ec61Sdh155122 /* shared is default; we'll treat as equivalent to clearing */ 3475f4b3ec61Sdh155122 if ((err = zonecfg_set_iptype(handle, ZS_SHARED)) != Z_OK) 3476bbec428eSgjelinek z_cmd_rt_perror(CMD_CLEAR, RT_IPTYPE, err, B_TRUE); 3477f4b3ec61Sdh155122 else 3478bbec428eSgjelinek need_to_commit = B_TRUE; 3479f4b3ec61Sdh155122 return; 34800209230bSgjelinek case PT_MAXLWPS: 34810209230bSgjelinek remove_aliased_rctl(PT_MAXLWPS, ALIAS_MAXLWPS); 34820209230bSgjelinek return; 34830209230bSgjelinek case PT_MAXSHMMEM: 34840209230bSgjelinek remove_aliased_rctl(PT_MAXSHMMEM, ALIAS_MAXSHMMEM); 34850209230bSgjelinek return; 34860209230bSgjelinek case PT_MAXSHMIDS: 34870209230bSgjelinek remove_aliased_rctl(PT_MAXSHMIDS, ALIAS_MAXSHMIDS); 34880209230bSgjelinek return; 34890209230bSgjelinek case PT_MAXMSGIDS: 34900209230bSgjelinek remove_aliased_rctl(PT_MAXMSGIDS, ALIAS_MAXMSGIDS); 34910209230bSgjelinek return; 34920209230bSgjelinek case PT_MAXSEMIDS: 34930209230bSgjelinek remove_aliased_rctl(PT_MAXSEMIDS, ALIAS_MAXSEMIDS); 34940209230bSgjelinek return; 34950209230bSgjelinek case PT_SHARES: 34960209230bSgjelinek remove_aliased_rctl(PT_SHARES, ALIAS_SHARES); 34970209230bSgjelinek return; 34985679c89fSjv227347 case PT_HOSTID: 34995679c89fSjv227347 if ((err = zonecfg_set_hostid(handle, NULL)) != Z_OK) 35005679c89fSjv227347 z_cmd_rt_perror(CMD_CLEAR, RT_HOSTID, err, B_TRUE); 35015679c89fSjv227347 else 35025679c89fSjv227347 need_to_commit = B_TRUE; 35035679c89fSjv227347 return; 35040209230bSgjelinek default: 3505bbec428eSgjelinek zone_perror(pt_to_str(type), Z_NO_PROPERTY_TYPE, B_TRUE); 3506bbec428eSgjelinek long_usage(CMD_CLEAR, B_TRUE); 3507bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 35080209230bSgjelinek return; 35090209230bSgjelinek } 35100209230bSgjelinek } 35110209230bSgjelinek 35120209230bSgjelinek void 35130209230bSgjelinek clear_func(cmd_t *cmd) 35140209230bSgjelinek { 35150209230bSgjelinek if (zone_is_read_only(CMD_CLEAR)) 35160209230bSgjelinek return; 35170209230bSgjelinek 35180209230bSgjelinek assert(cmd != NULL); 35190209230bSgjelinek 35200209230bSgjelinek if (global_scope) { 35210209230bSgjelinek if (gz_invalid_property(cmd->cmd_res_type)) { 35220209230bSgjelinek zerr(gettext("%s is not a valid property for the " 35230209230bSgjelinek "global zone."), pt_to_str(cmd->cmd_res_type)); 3524bbec428eSgjelinek saw_error = B_TRUE; 35250209230bSgjelinek return; 35260209230bSgjelinek } 35270209230bSgjelinek 35280209230bSgjelinek clear_global(cmd); 35290209230bSgjelinek } else { 35300209230bSgjelinek clear_property(cmd); 35310209230bSgjelinek } 35320209230bSgjelinek } 35337c478bd9Sstevel@tonic-gate 35347c478bd9Sstevel@tonic-gate void 35357c478bd9Sstevel@tonic-gate select_func(cmd_t *cmd) 35367c478bd9Sstevel@tonic-gate { 35370209230bSgjelinek int type, err, res; 35380209230bSgjelinek uint64_t limit; 3539c97ad5cdSakolb uint64_t tmp; 35407c478bd9Sstevel@tonic-gate 35417c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_SELECT)) 35427c478bd9Sstevel@tonic-gate return; 35437c478bd9Sstevel@tonic-gate 35447c478bd9Sstevel@tonic-gate assert(cmd != NULL); 35457c478bd9Sstevel@tonic-gate 35467c478bd9Sstevel@tonic-gate if (global_scope) { 3547bbec428eSgjelinek global_scope = B_FALSE; 35487c478bd9Sstevel@tonic-gate resource_scope = cmd->cmd_res_type; 35497c478bd9Sstevel@tonic-gate end_op = CMD_SELECT; 35507c478bd9Sstevel@tonic-gate } else { 35517c478bd9Sstevel@tonic-gate scope_usage(CMD_SELECT); 35527c478bd9Sstevel@tonic-gate return; 35537c478bd9Sstevel@tonic-gate } 35547c478bd9Sstevel@tonic-gate 35557c478bd9Sstevel@tonic-gate if ((type = cmd->cmd_res_type) == RT_UNKNOWN) { 3556bbec428eSgjelinek long_usage(CMD_SELECT, B_TRUE); 35577c478bd9Sstevel@tonic-gate return; 35587c478bd9Sstevel@tonic-gate } 35597c478bd9Sstevel@tonic-gate 3560bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 35617c478bd9Sstevel@tonic-gate return; 35627c478bd9Sstevel@tonic-gate 35637c478bd9Sstevel@tonic-gate switch (type) { 35647c478bd9Sstevel@tonic-gate case RT_FS: 3565bbec428eSgjelinek if ((err = fill_in_fstab(cmd, &old_fstab, B_FALSE)) != Z_OK) { 3566bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_FS, err, B_TRUE); 3567bbec428eSgjelinek global_scope = B_TRUE; 35687c478bd9Sstevel@tonic-gate } 35697c478bd9Sstevel@tonic-gate bcopy(&old_fstab, &in_progress_fstab, 35707c478bd9Sstevel@tonic-gate sizeof (struct zone_fstab)); 35717c478bd9Sstevel@tonic-gate return; 35727c478bd9Sstevel@tonic-gate case RT_IPD: 3573087719fdSdp if (state_atleast(ZONE_STATE_INCOMPLETE)) { 35747c478bd9Sstevel@tonic-gate zerr(gettext("Zone %s not in %s state; %s %s not " 35757c478bd9Sstevel@tonic-gate "allowed."), zone, 35767c478bd9Sstevel@tonic-gate zone_state_str(ZONE_STATE_CONFIGURED), 35777c478bd9Sstevel@tonic-gate cmd_to_str(CMD_SELECT), rt_to_str(RT_IPD)); 3578bbec428eSgjelinek global_scope = B_TRUE; 35797c478bd9Sstevel@tonic-gate end_op = -1; 35807c478bd9Sstevel@tonic-gate return; 35817c478bd9Sstevel@tonic-gate } 3582bbec428eSgjelinek if ((err = fill_in_ipdtab(cmd, &old_ipdtab, B_FALSE)) != Z_OK) { 3583bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_IPD, err, B_TRUE); 3584bbec428eSgjelinek global_scope = B_TRUE; 35857c478bd9Sstevel@tonic-gate } 35867c478bd9Sstevel@tonic-gate bcopy(&old_ipdtab, &in_progress_ipdtab, 35877c478bd9Sstevel@tonic-gate sizeof (struct zone_fstab)); 35887c478bd9Sstevel@tonic-gate return; 35897c478bd9Sstevel@tonic-gate case RT_NET: 3590bbec428eSgjelinek if ((err = fill_in_nwiftab(cmd, &old_nwiftab, B_FALSE)) 3591bbec428eSgjelinek != Z_OK) { 3592bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_NET, err, B_TRUE); 3593bbec428eSgjelinek global_scope = B_TRUE; 35947c478bd9Sstevel@tonic-gate } 35957c478bd9Sstevel@tonic-gate bcopy(&old_nwiftab, &in_progress_nwiftab, 35967c478bd9Sstevel@tonic-gate sizeof (struct zone_nwiftab)); 35977c478bd9Sstevel@tonic-gate return; 35987c478bd9Sstevel@tonic-gate case RT_DEVICE: 3599bbec428eSgjelinek if ((err = fill_in_devtab(cmd, &old_devtab, B_FALSE)) != Z_OK) { 3600bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_DEVICE, err, B_TRUE); 3601bbec428eSgjelinek global_scope = B_TRUE; 36027c478bd9Sstevel@tonic-gate } 36037c478bd9Sstevel@tonic-gate bcopy(&old_devtab, &in_progress_devtab, 36047c478bd9Sstevel@tonic-gate sizeof (struct zone_devtab)); 36057c478bd9Sstevel@tonic-gate return; 36067c478bd9Sstevel@tonic-gate case RT_RCTL: 3607bbec428eSgjelinek if ((err = fill_in_rctltab(cmd, &old_rctltab, B_FALSE)) 3608bbec428eSgjelinek != Z_OK) { 3609bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_RCTL, err, B_TRUE); 3610bbec428eSgjelinek global_scope = B_TRUE; 36117c478bd9Sstevel@tonic-gate } 36127c478bd9Sstevel@tonic-gate bcopy(&old_rctltab, &in_progress_rctltab, 36137c478bd9Sstevel@tonic-gate sizeof (struct zone_rctltab)); 36147c478bd9Sstevel@tonic-gate return; 36157c478bd9Sstevel@tonic-gate case RT_ATTR: 3616bbec428eSgjelinek if ((err = fill_in_attrtab(cmd, &old_attrtab, B_FALSE)) 3617bbec428eSgjelinek != Z_OK) { 3618bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_ATTR, err, B_TRUE); 3619bbec428eSgjelinek global_scope = B_TRUE; 36207c478bd9Sstevel@tonic-gate } 36217c478bd9Sstevel@tonic-gate bcopy(&old_attrtab, &in_progress_attrtab, 36227c478bd9Sstevel@tonic-gate sizeof (struct zone_attrtab)); 36237c478bd9Sstevel@tonic-gate return; 3624fa9e4066Sahrens case RT_DATASET: 3625bbec428eSgjelinek if ((err = fill_in_dstab(cmd, &old_dstab, B_FALSE)) != Z_OK) { 3626bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_DATASET, err, B_TRUE); 3627bbec428eSgjelinek global_scope = B_TRUE; 3628fa9e4066Sahrens } 3629fa9e4066Sahrens bcopy(&old_dstab, &in_progress_dstab, 3630fa9e4066Sahrens sizeof (struct zone_dstab)); 3631fa9e4066Sahrens return; 36320209230bSgjelinek case RT_DCPU: 36330209230bSgjelinek if ((err = zonecfg_lookup_pset(handle, &old_psettab)) != Z_OK) { 3634bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_DCPU, err, B_TRUE); 3635bbec428eSgjelinek global_scope = B_TRUE; 36360209230bSgjelinek } 36370209230bSgjelinek bcopy(&old_psettab, &in_progress_psettab, 36380209230bSgjelinek sizeof (struct zone_psettab)); 36390209230bSgjelinek return; 3640c97ad5cdSakolb case RT_PCAP: 3641c97ad5cdSakolb if ((err = zonecfg_get_aliased_rctl(handle, ALIAS_CPUCAP, &tmp)) 3642c97ad5cdSakolb != Z_OK) { 3643bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_PCAP, err, B_TRUE); 3644bbec428eSgjelinek global_scope = B_TRUE; 3645c97ad5cdSakolb } 3646c97ad5cdSakolb return; 36470209230bSgjelinek case RT_MCAP: 36480209230bSgjelinek /* if none of these exist, there is no resource to select */ 36490209230bSgjelinek if ((res = zonecfg_lookup_mcap(handle, &old_mcaptab)) != Z_OK && 36500209230bSgjelinek zonecfg_get_aliased_rctl(handle, ALIAS_MAXSWAP, &limit) 36510209230bSgjelinek != Z_OK && 36520209230bSgjelinek zonecfg_get_aliased_rctl(handle, ALIAS_MAXLOCKEDMEM, &limit) 36530209230bSgjelinek != Z_OK) { 36540209230bSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_MCAP, Z_NO_RESOURCE_TYPE, 3655bbec428eSgjelinek B_TRUE); 3656bbec428eSgjelinek global_scope = B_TRUE; 36570209230bSgjelinek } 36580209230bSgjelinek if (res == Z_OK) 36590209230bSgjelinek bcopy(&old_mcaptab, &in_progress_mcaptab, 36600209230bSgjelinek sizeof (struct zone_mcaptab)); 36610209230bSgjelinek else 36620209230bSgjelinek bzero(&in_progress_mcaptab, 36630209230bSgjelinek sizeof (in_progress_mcaptab)); 36640209230bSgjelinek return; 36657c478bd9Sstevel@tonic-gate default: 3666bbec428eSgjelinek zone_perror(rt_to_str(type), Z_NO_RESOURCE_TYPE, B_TRUE); 3667bbec428eSgjelinek long_usage(CMD_SELECT, B_TRUE); 3668bbec428eSgjelinek usage(B_FALSE, HELP_RESOURCES); 36697c478bd9Sstevel@tonic-gate return; 36707c478bd9Sstevel@tonic-gate } 36717c478bd9Sstevel@tonic-gate } 36727c478bd9Sstevel@tonic-gate 36737c478bd9Sstevel@tonic-gate /* 36747c478bd9Sstevel@tonic-gate * Network "addresses" can be one of the following forms: 36757c478bd9Sstevel@tonic-gate * <IPv4 address> 36767c478bd9Sstevel@tonic-gate * <IPv4 address>/<prefix length> 36777c478bd9Sstevel@tonic-gate * <IPv6 address>/<prefix length> 36787c478bd9Sstevel@tonic-gate * <host name> 36797c478bd9Sstevel@tonic-gate * <host name>/<prefix length> 36807c478bd9Sstevel@tonic-gate * In other words, the "/" followed by a prefix length is allowed but not 36817c478bd9Sstevel@tonic-gate * required for IPv4 addresses and host names, and required for IPv6 addresses. 36827c478bd9Sstevel@tonic-gate * If a prefix length is given, it must be in the allowable range: 0 to 32 for 36837c478bd9Sstevel@tonic-gate * IPv4 addresses and host names, 0 to 128 for IPv6 addresses. 36847c478bd9Sstevel@tonic-gate * Host names must start with an alpha-numeric character, and all subsequent 36857c478bd9Sstevel@tonic-gate * characters must be either alpha-numeric or "-". 36867c478bd9Sstevel@tonic-gate */ 36877c478bd9Sstevel@tonic-gate 36887c478bd9Sstevel@tonic-gate static int 36897c478bd9Sstevel@tonic-gate validate_net_address_syntax(char *address) 36907c478bd9Sstevel@tonic-gate { 36917c478bd9Sstevel@tonic-gate char *slashp, part1[MAXHOSTNAMELEN]; 36927c478bd9Sstevel@tonic-gate struct in6_addr in6; 36937c478bd9Sstevel@tonic-gate struct in_addr in4; 36947c478bd9Sstevel@tonic-gate int prefixlen, i; 36957c478bd9Sstevel@tonic-gate 36967c478bd9Sstevel@tonic-gate /* 36977c478bd9Sstevel@tonic-gate * Copy the part before any '/' into part1 or copy the whole 36987c478bd9Sstevel@tonic-gate * thing if there is no '/'. 36997c478bd9Sstevel@tonic-gate */ 37007c478bd9Sstevel@tonic-gate if ((slashp = strchr(address, '/')) != NULL) { 37017c478bd9Sstevel@tonic-gate *slashp = '\0'; 37027c478bd9Sstevel@tonic-gate (void) strlcpy(part1, address, sizeof (part1)); 37037c478bd9Sstevel@tonic-gate *slashp = '/'; 37047c478bd9Sstevel@tonic-gate prefixlen = atoi(++slashp); 37057c478bd9Sstevel@tonic-gate } else { 37067c478bd9Sstevel@tonic-gate (void) strlcpy(part1, address, sizeof (part1)); 37077c478bd9Sstevel@tonic-gate } 37087c478bd9Sstevel@tonic-gate 37097c478bd9Sstevel@tonic-gate if (inet_pton(AF_INET6, part1, &in6) == 1) { 37107c478bd9Sstevel@tonic-gate if (slashp == NULL) { 37117c478bd9Sstevel@tonic-gate zerr(gettext("%s: IPv6 addresses " 37127c478bd9Sstevel@tonic-gate "require /prefix-length suffix."), address); 37137c478bd9Sstevel@tonic-gate return (Z_ERR); 37147c478bd9Sstevel@tonic-gate } 37157c478bd9Sstevel@tonic-gate if (prefixlen < 0 || prefixlen > 128) { 37167c478bd9Sstevel@tonic-gate zerr(gettext("%s: IPv6 address " 37177c478bd9Sstevel@tonic-gate "prefix lengths must be 0 - 128."), address); 37187c478bd9Sstevel@tonic-gate return (Z_ERR); 37197c478bd9Sstevel@tonic-gate } 37207c478bd9Sstevel@tonic-gate return (Z_OK); 37217c478bd9Sstevel@tonic-gate } 37227c478bd9Sstevel@tonic-gate 37237c478bd9Sstevel@tonic-gate /* At this point, any /prefix must be for IPv4. */ 37247c478bd9Sstevel@tonic-gate if (slashp != NULL) { 37257c478bd9Sstevel@tonic-gate if (prefixlen < 0 || prefixlen > 32) { 37267c478bd9Sstevel@tonic-gate zerr(gettext("%s: IPv4 address " 37277c478bd9Sstevel@tonic-gate "prefix lengths must be 0 - 32."), address); 37287c478bd9Sstevel@tonic-gate return (Z_ERR); 37297c478bd9Sstevel@tonic-gate } 37307c478bd9Sstevel@tonic-gate } 37317c478bd9Sstevel@tonic-gate if (inet_pton(AF_INET, part1, &in4) == 1) 37327c478bd9Sstevel@tonic-gate return (Z_OK); 37337c478bd9Sstevel@tonic-gate 37347c478bd9Sstevel@tonic-gate /* address may also be a host name */ 37357c478bd9Sstevel@tonic-gate if (!isalnum(part1[0])) { 37367c478bd9Sstevel@tonic-gate zerr(gettext("%s: bogus host name or network address syntax"), 37377c478bd9Sstevel@tonic-gate part1); 3738bbec428eSgjelinek saw_error = B_TRUE; 3739bbec428eSgjelinek usage(B_FALSE, HELP_NETADDR); 37407c478bd9Sstevel@tonic-gate return (Z_ERR); 37417c478bd9Sstevel@tonic-gate } 37427c478bd9Sstevel@tonic-gate for (i = 1; part1[i]; i++) 37437c478bd9Sstevel@tonic-gate if (!isalnum(part1[i]) && part1[i] != '-' && part1[i] != '.') { 37447c478bd9Sstevel@tonic-gate zerr(gettext("%s: bogus host name or " 37457c478bd9Sstevel@tonic-gate "network address syntax"), part1); 3746bbec428eSgjelinek saw_error = B_TRUE; 3747bbec428eSgjelinek usage(B_FALSE, HELP_NETADDR); 37487c478bd9Sstevel@tonic-gate return (Z_ERR); 37497c478bd9Sstevel@tonic-gate } 37507c478bd9Sstevel@tonic-gate return (Z_OK); 37517c478bd9Sstevel@tonic-gate } 37527c478bd9Sstevel@tonic-gate 37537c478bd9Sstevel@tonic-gate static int 3754c9f134eaSjv227347 validate_net_physical_syntax(const char *ifname) 37557c478bd9Sstevel@tonic-gate { 3756c9f134eaSjv227347 ifspec_t ifnameprop; 3757c9f134eaSjv227347 zone_iptype_t iptype; 3758c9f134eaSjv227347 375937b210dcSjv227347 if (zonecfg_get_iptype(handle, &iptype) != Z_OK) { 3760c9f134eaSjv227347 zerr(gettext("zone configuration has an invalid or nonexistent " 3761c9f134eaSjv227347 "ip-type property")); 37627c478bd9Sstevel@tonic-gate return (Z_ERR); 37637c478bd9Sstevel@tonic-gate } 3764c9f134eaSjv227347 switch (iptype) { 3765c9f134eaSjv227347 case ZS_SHARED: 3766c9f134eaSjv227347 if (ifparse_ifspec(ifname, &ifnameprop) == B_FALSE) { 3767c9f134eaSjv227347 zerr(gettext("%s: invalid physical interface name"), 3768c9f134eaSjv227347 ifname); 3769c9f134eaSjv227347 return (Z_ERR); 3770c9f134eaSjv227347 } 3771c9f134eaSjv227347 if (ifnameprop.ifsp_lunvalid) { 3772c9f134eaSjv227347 zerr(gettext("%s: LUNs not allowed in physical " 3773c9f134eaSjv227347 "interface names"), ifname); 3774c9f134eaSjv227347 return (Z_ERR); 3775c9f134eaSjv227347 } 3776c9f134eaSjv227347 break; 3777c9f134eaSjv227347 case ZS_EXCLUSIVE: 3778c9f134eaSjv227347 if (dladm_valid_linkname(ifname) == B_FALSE) { 3779c9f134eaSjv227347 if (strchr(ifname, ':') != NULL) 3780c9f134eaSjv227347 zerr(gettext("%s: physical interface name " 3781c9f134eaSjv227347 "required; logical interface name not " 3782c9f134eaSjv227347 "allowed"), ifname); 3783c9f134eaSjv227347 else 3784c9f134eaSjv227347 zerr(gettext("%s: invalid physical interface " 3785c9f134eaSjv227347 "name"), ifname); 3786c9f134eaSjv227347 return (Z_ERR); 3787c9f134eaSjv227347 } 3788c9f134eaSjv227347 break; 3789c9f134eaSjv227347 } 3790c9f134eaSjv227347 return (Z_OK); 3791c9f134eaSjv227347 } 37927c478bd9Sstevel@tonic-gate 37937c478bd9Sstevel@tonic-gate static boolean_t 37947c478bd9Sstevel@tonic-gate valid_fs_type(const char *type) 37957c478bd9Sstevel@tonic-gate { 37967c478bd9Sstevel@tonic-gate /* 37977c478bd9Sstevel@tonic-gate * Is this a valid path component? 37987c478bd9Sstevel@tonic-gate */ 37997c478bd9Sstevel@tonic-gate if (strlen(type) + 1 > MAXNAMELEN) 38007c478bd9Sstevel@tonic-gate return (B_FALSE); 38017c478bd9Sstevel@tonic-gate /* 38027c478bd9Sstevel@tonic-gate * Make sure a bad value for "type" doesn't make 38037c478bd9Sstevel@tonic-gate * /usr/lib/fs/<type>/mount turn into something else. 38047c478bd9Sstevel@tonic-gate */ 38057c478bd9Sstevel@tonic-gate if (strchr(type, '/') != NULL || type[0] == '\0' || 38067c478bd9Sstevel@tonic-gate strcmp(type, ".") == 0 || strcmp(type, "..") == 0) 38077c478bd9Sstevel@tonic-gate return (B_FALSE); 38087c478bd9Sstevel@tonic-gate /* 38097c478bd9Sstevel@tonic-gate * More detailed verification happens later by zoneadm(1m). 38107c478bd9Sstevel@tonic-gate */ 38117c478bd9Sstevel@tonic-gate return (B_TRUE); 38127c478bd9Sstevel@tonic-gate } 38137c478bd9Sstevel@tonic-gate 3814f4b3ec61Sdh155122 static boolean_t 3815f4b3ec61Sdh155122 allow_exclusive() 3816f4b3ec61Sdh155122 { 3817f4b3ec61Sdh155122 brand_handle_t bh; 3818f4b3ec61Sdh155122 char brand[MAXNAMELEN]; 3819f4b3ec61Sdh155122 boolean_t ret; 3820f4b3ec61Sdh155122 3821f4b3ec61Sdh155122 if (zonecfg_get_brand(handle, brand, sizeof (brand)) != Z_OK) { 3822f4b3ec61Sdh155122 zerr("%s: %s\n", zone, gettext("could not get zone brand")); 3823f4b3ec61Sdh155122 return (B_FALSE); 3824f4b3ec61Sdh155122 } 3825f4b3ec61Sdh155122 if ((bh = brand_open(brand)) == NULL) { 3826f4b3ec61Sdh155122 zerr("%s: %s\n", zone, gettext("unknown brand.")); 3827f4b3ec61Sdh155122 return (B_FALSE); 3828f4b3ec61Sdh155122 } 3829f4b3ec61Sdh155122 ret = brand_allow_exclusive_ip(bh); 3830f4b3ec61Sdh155122 brand_close(bh); 3831f4b3ec61Sdh155122 if (!ret) 3832f4b3ec61Sdh155122 zerr(gettext("%s cannot be '%s' when %s is '%s'."), 3833f4b3ec61Sdh155122 pt_to_str(PT_IPTYPE), "exclusive", 3834f4b3ec61Sdh155122 pt_to_str(PT_BRAND), brand); 3835f4b3ec61Sdh155122 return (ret); 3836f4b3ec61Sdh155122 } 3837f4b3ec61Sdh155122 38380209230bSgjelinek static void 38390209230bSgjelinek set_aliased_rctl(char *alias, int prop_type, char *s) 38400209230bSgjelinek { 38410209230bSgjelinek uint64_t limit; 38420209230bSgjelinek int err; 38430209230bSgjelinek char tmp[128]; 38440209230bSgjelinek 38450209230bSgjelinek if (global_zone && strcmp(alias, ALIAS_SHARES) != 0) 38460209230bSgjelinek zerr(gettext("WARNING: Setting a global zone resource " 38470209230bSgjelinek "control too low could deny\nservice " 38480209230bSgjelinek "to even the root user; " 38490209230bSgjelinek "this could render the system impossible\n" 38500209230bSgjelinek "to administer. Please use caution.")); 38510209230bSgjelinek 38520209230bSgjelinek /* convert memory based properties */ 38530209230bSgjelinek if (prop_type == PT_MAXSHMMEM) { 38540209230bSgjelinek if (!zonecfg_valid_memlimit(s, &limit)) { 38550209230bSgjelinek zerr(gettext("A non-negative number with a required " 38560209230bSgjelinek "scale suffix (K, M, G or T) was expected\nhere.")); 3857bbec428eSgjelinek saw_error = B_TRUE; 38580209230bSgjelinek return; 38590209230bSgjelinek } 38600209230bSgjelinek 38610209230bSgjelinek (void) snprintf(tmp, sizeof (tmp), "%llu", limit); 38620209230bSgjelinek s = tmp; 38630209230bSgjelinek } 38640209230bSgjelinek 38650209230bSgjelinek if (!zonecfg_aliased_rctl_ok(handle, alias)) { 3866bbec428eSgjelinek zone_perror(pt_to_str(prop_type), Z_ALIAS_DISALLOW, B_FALSE); 3867bbec428eSgjelinek saw_error = B_TRUE; 38680209230bSgjelinek } else if (!zonecfg_valid_alias_limit(alias, s, &limit)) { 38690209230bSgjelinek zerr(gettext("%s property is out of range."), 38700209230bSgjelinek pt_to_str(prop_type)); 3871bbec428eSgjelinek saw_error = B_TRUE; 38720209230bSgjelinek } else if ((err = zonecfg_set_aliased_rctl(handle, alias, limit)) 38730209230bSgjelinek != Z_OK) { 3874bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 3875bbec428eSgjelinek saw_error = B_TRUE; 38760209230bSgjelinek } else { 3877bbec428eSgjelinek need_to_commit = B_TRUE; 38780209230bSgjelinek } 38790209230bSgjelinek } 38800209230bSgjelinek 38817c478bd9Sstevel@tonic-gate void 38827c478bd9Sstevel@tonic-gate set_func(cmd_t *cmd) 38837c478bd9Sstevel@tonic-gate { 38847c478bd9Sstevel@tonic-gate char *prop_id; 3885555afedfScarlsonj int arg, err, res_type, prop_type; 38867c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 38877c478bd9Sstevel@tonic-gate boolean_t autoboot; 3888f4b3ec61Sdh155122 zone_iptype_t iptype; 3889bbec428eSgjelinek boolean_t force_set = B_FALSE; 38900209230bSgjelinek size_t physmem_size = sizeof (in_progress_mcaptab.zone_physmem_cap); 38910209230bSgjelinek uint64_t mem_cap, mem_limit; 3892c97ad5cdSakolb float cap; 3893c97ad5cdSakolb char *unitp; 38940209230bSgjelinek struct zone_psettab tmp_psettab; 3895bbec428eSgjelinek boolean_t arg_err = B_FALSE; 38967c478bd9Sstevel@tonic-gate 38977c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_SET)) 38987c478bd9Sstevel@tonic-gate return; 38997c478bd9Sstevel@tonic-gate 39007c478bd9Sstevel@tonic-gate assert(cmd != NULL); 39017c478bd9Sstevel@tonic-gate 3902555afedfScarlsonj optind = opterr = 0; 3903555afedfScarlsonj while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "F")) != EOF) { 3904555afedfScarlsonj switch (arg) { 3905555afedfScarlsonj case 'F': 3906bbec428eSgjelinek force_set = B_TRUE; 3907555afedfScarlsonj break; 3908555afedfScarlsonj default: 3909555afedfScarlsonj if (optopt == '?') 3910555afedfScarlsonj longer_usage(CMD_SET); 3911555afedfScarlsonj else 3912555afedfScarlsonj short_usage(CMD_SET); 3913bbec428eSgjelinek arg_err = B_TRUE; 39147ec75eb8Sgjelinek break; 39157ec75eb8Sgjelinek } 39167ec75eb8Sgjelinek } 39177ec75eb8Sgjelinek if (arg_err) 3918555afedfScarlsonj return; 3919555afedfScarlsonj 39207c478bd9Sstevel@tonic-gate prop_type = cmd->cmd_prop_name[0]; 39217c478bd9Sstevel@tonic-gate if (global_scope) { 39220209230bSgjelinek if (gz_invalid_property(prop_type)) { 39230209230bSgjelinek zerr(gettext("%s is not a valid property for the " 39240209230bSgjelinek "global zone."), pt_to_str(prop_type)); 3925bbec428eSgjelinek saw_error = B_TRUE; 39260209230bSgjelinek return; 39270209230bSgjelinek } 39280209230bSgjelinek 3929087719fdSdp if (prop_type == PT_ZONENAME) { 3930087719fdSdp res_type = RT_ZONENAME; 3931087719fdSdp } else if (prop_type == PT_ZONEPATH) { 39327c478bd9Sstevel@tonic-gate res_type = RT_ZONEPATH; 39337c478bd9Sstevel@tonic-gate } else if (prop_type == PT_AUTOBOOT) { 39347c478bd9Sstevel@tonic-gate res_type = RT_AUTOBOOT; 39359acbbeafSnn35248 } else if (prop_type == PT_BRAND) { 39369acbbeafSnn35248 res_type = RT_BRAND; 39377c478bd9Sstevel@tonic-gate } else if (prop_type == PT_POOL) { 39387c478bd9Sstevel@tonic-gate res_type = RT_POOL; 3939ffbafc53Scomay } else if (prop_type == PT_LIMITPRIV) { 3940ffbafc53Scomay res_type = RT_LIMITPRIV; 39413f2f09c1Sdp } else if (prop_type == PT_BOOTARGS) { 39423f2f09c1Sdp res_type = RT_BOOTARGS; 39430209230bSgjelinek } else if (prop_type == PT_SCHED) { 39440209230bSgjelinek res_type = RT_SCHED; 3945f4b3ec61Sdh155122 } else if (prop_type == PT_IPTYPE) { 3946f4b3ec61Sdh155122 res_type = RT_IPTYPE; 39470209230bSgjelinek } else if (prop_type == PT_MAXLWPS) { 39480209230bSgjelinek res_type = RT_MAXLWPS; 39490209230bSgjelinek } else if (prop_type == PT_MAXSHMMEM) { 39500209230bSgjelinek res_type = RT_MAXSHMMEM; 39510209230bSgjelinek } else if (prop_type == PT_MAXSHMIDS) { 39520209230bSgjelinek res_type = RT_MAXSHMIDS; 39530209230bSgjelinek } else if (prop_type == PT_MAXMSGIDS) { 39540209230bSgjelinek res_type = RT_MAXMSGIDS; 39550209230bSgjelinek } else if (prop_type == PT_MAXSEMIDS) { 39560209230bSgjelinek res_type = RT_MAXSEMIDS; 39570209230bSgjelinek } else if (prop_type == PT_SHARES) { 39580209230bSgjelinek res_type = RT_SHARES; 39595679c89fSjv227347 } else if (prop_type == PT_HOSTID) { 39605679c89fSjv227347 res_type = RT_HOSTID; 39617c478bd9Sstevel@tonic-gate } else { 39627c478bd9Sstevel@tonic-gate zerr(gettext("Cannot set a resource-specific property " 39637c478bd9Sstevel@tonic-gate "from the global scope.")); 3964bbec428eSgjelinek saw_error = B_TRUE; 39657c478bd9Sstevel@tonic-gate return; 39667c478bd9Sstevel@tonic-gate } 39677c478bd9Sstevel@tonic-gate } else { 39687c478bd9Sstevel@tonic-gate res_type = resource_scope; 39697c478bd9Sstevel@tonic-gate } 39707c478bd9Sstevel@tonic-gate 3971555afedfScarlsonj if (force_set) { 3972555afedfScarlsonj if (res_type != RT_ZONEPATH) { 3973555afedfScarlsonj zerr(gettext("Only zonepath setting can be forced.")); 3974bbec428eSgjelinek saw_error = B_TRUE; 3975555afedfScarlsonj return; 3976555afedfScarlsonj } 3977555afedfScarlsonj if (!zonecfg_in_alt_root()) { 3978555afedfScarlsonj zerr(gettext("Zonepath is changeable only in an " 3979555afedfScarlsonj "alternate root.")); 3980bbec428eSgjelinek saw_error = B_TRUE; 3981555afedfScarlsonj return; 3982555afedfScarlsonj } 3983555afedfScarlsonj } 3984555afedfScarlsonj 39857c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[0]; 39867c478bd9Sstevel@tonic-gate /* 39877c478bd9Sstevel@tonic-gate * A nasty expression but not that complicated: 39887c478bd9Sstevel@tonic-gate * 1. fs options are simple or list (tested below) 39897c478bd9Sstevel@tonic-gate * 2. rctl value's are complex or list (tested below) 39907c478bd9Sstevel@tonic-gate * Anything else should be simple. 39917c478bd9Sstevel@tonic-gate */ 39927c478bd9Sstevel@tonic-gate if (!(res_type == RT_FS && prop_type == PT_OPTIONS) && 39937c478bd9Sstevel@tonic-gate !(res_type == RT_RCTL && prop_type == PT_VALUE) && 39947c478bd9Sstevel@tonic-gate (pp->pv_type != PROP_VAL_SIMPLE || 39957c478bd9Sstevel@tonic-gate (prop_id = pp->pv_simple) == NULL)) { 39967c478bd9Sstevel@tonic-gate zerr(gettext("A %s value was expected here."), 39977c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_SIMPLE)); 3998bbec428eSgjelinek saw_error = B_TRUE; 39997c478bd9Sstevel@tonic-gate return; 40007c478bd9Sstevel@tonic-gate } 40017c478bd9Sstevel@tonic-gate if (prop_type == PT_UNKNOWN) { 4002bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 40037c478bd9Sstevel@tonic-gate return; 40047c478bd9Sstevel@tonic-gate } 40057c478bd9Sstevel@tonic-gate 4006087719fdSdp /* 4007087719fdSdp * Special case: the user can change the zone name prior to 'create'; 4008087719fdSdp * if the zone already exists, we fall through letting initialize() 4009087719fdSdp * and the rest of the logic run. 4010087719fdSdp */ 4011bbec428eSgjelinek if (res_type == RT_ZONENAME && got_handle == B_FALSE && 4012087719fdSdp !state_atleast(ZONE_STATE_CONFIGURED)) { 4013fb03efaaSdp if ((err = zonecfg_validate_zonename(prop_id)) != Z_OK) { 4014bbec428eSgjelinek zone_perror(prop_id, err, B_TRUE); 4015bbec428eSgjelinek usage(B_FALSE, HELP_SYNTAX); 4016fb03efaaSdp return; 4017fb03efaaSdp } 4018087719fdSdp (void) strlcpy(zone, prop_id, sizeof (zone)); 4019087719fdSdp return; 4020087719fdSdp } 4021087719fdSdp 4022bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 40237c478bd9Sstevel@tonic-gate return; 40247c478bd9Sstevel@tonic-gate 40257c478bd9Sstevel@tonic-gate switch (res_type) { 4026087719fdSdp case RT_ZONENAME: 4027087719fdSdp if ((err = zonecfg_set_name(handle, prop_id)) != Z_OK) { 4028087719fdSdp /* 4029087719fdSdp * Use prop_id instead of 'zone' here, since we're 4030087719fdSdp * reporting a problem about the *new* zonename. 4031087719fdSdp */ 4032bbec428eSgjelinek zone_perror(prop_id, err, B_TRUE); 4033bbec428eSgjelinek usage(B_FALSE, HELP_SYNTAX); 4034087719fdSdp } else { 4035bbec428eSgjelinek need_to_commit = B_TRUE; 4036087719fdSdp (void) strlcpy(zone, prop_id, sizeof (zone)); 4037087719fdSdp } 4038087719fdSdp return; 40397c478bd9Sstevel@tonic-gate case RT_ZONEPATH: 4040555afedfScarlsonj if (!force_set && state_atleast(ZONE_STATE_INSTALLED)) { 40417c478bd9Sstevel@tonic-gate zerr(gettext("Zone %s already installed; %s %s not " 40427c478bd9Sstevel@tonic-gate "allowed."), zone, cmd_to_str(CMD_SET), 40437c478bd9Sstevel@tonic-gate rt_to_str(RT_ZONEPATH)); 40447c478bd9Sstevel@tonic-gate return; 40457c478bd9Sstevel@tonic-gate } 40467c478bd9Sstevel@tonic-gate if (validate_zonepath_syntax(prop_id) != Z_OK) { 4047bbec428eSgjelinek saw_error = B_TRUE; 40487c478bd9Sstevel@tonic-gate return; 40497c478bd9Sstevel@tonic-gate } 40507c478bd9Sstevel@tonic-gate if ((err = zonecfg_set_zonepath(handle, prop_id)) != Z_OK) 4051bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 40527c478bd9Sstevel@tonic-gate else 4053bbec428eSgjelinek need_to_commit = B_TRUE; 40547c478bd9Sstevel@tonic-gate return; 40559acbbeafSnn35248 case RT_BRAND: 40569acbbeafSnn35248 if (state_atleast(ZONE_STATE_INSTALLED)) { 40579acbbeafSnn35248 zerr(gettext("Zone %s already installed; %s %s not " 40589acbbeafSnn35248 "allowed."), zone, cmd_to_str(CMD_SET), 40599acbbeafSnn35248 rt_to_str(RT_BRAND)); 40609acbbeafSnn35248 return; 40619acbbeafSnn35248 } 40629acbbeafSnn35248 if ((err = zonecfg_set_brand(handle, prop_id)) != Z_OK) 4063bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 40649acbbeafSnn35248 else 4065bbec428eSgjelinek need_to_commit = B_TRUE; 40669acbbeafSnn35248 return; 40677c478bd9Sstevel@tonic-gate case RT_AUTOBOOT: 40687c478bd9Sstevel@tonic-gate if (strcmp(prop_id, "true") == 0) { 40697c478bd9Sstevel@tonic-gate autoboot = B_TRUE; 40707c478bd9Sstevel@tonic-gate } else if (strcmp(prop_id, "false") == 0) { 40717c478bd9Sstevel@tonic-gate autoboot = B_FALSE; 40727c478bd9Sstevel@tonic-gate } else { 40737c478bd9Sstevel@tonic-gate zerr(gettext("%s value must be '%s' or '%s'."), 40747c478bd9Sstevel@tonic-gate pt_to_str(PT_AUTOBOOT), "true", "false"); 4075bbec428eSgjelinek saw_error = B_TRUE; 40767c478bd9Sstevel@tonic-gate return; 40777c478bd9Sstevel@tonic-gate } 40787c478bd9Sstevel@tonic-gate if ((err = zonecfg_set_autoboot(handle, autoboot)) != Z_OK) 4079bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 40807c478bd9Sstevel@tonic-gate else 4081bbec428eSgjelinek need_to_commit = B_TRUE; 40827c478bd9Sstevel@tonic-gate return; 40837c478bd9Sstevel@tonic-gate case RT_POOL: 40840209230bSgjelinek /* don't allow use of the reserved temporary pool names */ 40850209230bSgjelinek if (strncmp("SUNW", prop_id, 4) == 0) { 40860209230bSgjelinek zerr(gettext("pool names starting with SUNW are " 40870209230bSgjelinek "reserved.")); 4088bbec428eSgjelinek saw_error = B_TRUE; 40890209230bSgjelinek return; 40900209230bSgjelinek } 40910209230bSgjelinek 40920209230bSgjelinek /* can't set pool if dedicated-cpu exists */ 40930209230bSgjelinek if (zonecfg_lookup_pset(handle, &tmp_psettab) == Z_OK) { 40940209230bSgjelinek zerr(gettext("The %s resource already exists. " 40950209230bSgjelinek "A persistent pool is incompatible\nwith the %s " 40960209230bSgjelinek "resource."), rt_to_str(RT_DCPU), 40970209230bSgjelinek rt_to_str(RT_DCPU)); 4098bbec428eSgjelinek saw_error = B_TRUE; 40990209230bSgjelinek return; 41000209230bSgjelinek } 41010209230bSgjelinek 41027c478bd9Sstevel@tonic-gate if ((err = zonecfg_set_pool(handle, prop_id)) != Z_OK) 4103bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 41047c478bd9Sstevel@tonic-gate else 4105bbec428eSgjelinek need_to_commit = B_TRUE; 41067c478bd9Sstevel@tonic-gate return; 4107ffbafc53Scomay case RT_LIMITPRIV: 4108ffbafc53Scomay if ((err = zonecfg_set_limitpriv(handle, prop_id)) != Z_OK) 4109bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 4110ffbafc53Scomay else 4111bbec428eSgjelinek need_to_commit = B_TRUE; 4112ffbafc53Scomay return; 41133f2f09c1Sdp case RT_BOOTARGS: 41143f2f09c1Sdp if ((err = zonecfg_set_bootargs(handle, prop_id)) != Z_OK) 4115bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 41163f2f09c1Sdp else 4117bbec428eSgjelinek need_to_commit = B_TRUE; 41183f2f09c1Sdp return; 41190209230bSgjelinek case RT_SCHED: 41200209230bSgjelinek if ((err = zonecfg_set_sched(handle, prop_id)) != Z_OK) 4121bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 41220209230bSgjelinek else 4123bbec428eSgjelinek need_to_commit = B_TRUE; 41240209230bSgjelinek return; 4125f4b3ec61Sdh155122 case RT_IPTYPE: 4126f4b3ec61Sdh155122 if (strcmp(prop_id, "shared") == 0) { 4127f4b3ec61Sdh155122 iptype = ZS_SHARED; 4128f4b3ec61Sdh155122 } else if (strcmp(prop_id, "exclusive") == 0) { 4129f4b3ec61Sdh155122 iptype = ZS_EXCLUSIVE; 4130f4b3ec61Sdh155122 } else { 4131f4b3ec61Sdh155122 zerr(gettext("%s value must be '%s' or '%s'."), 4132f4b3ec61Sdh155122 pt_to_str(PT_IPTYPE), "shared", "exclusive"); 4133bbec428eSgjelinek saw_error = B_TRUE; 4134f4b3ec61Sdh155122 return; 4135f4b3ec61Sdh155122 } 4136f4b3ec61Sdh155122 if (iptype == ZS_EXCLUSIVE && !allow_exclusive()) { 4137bbec428eSgjelinek saw_error = B_TRUE; 4138f4b3ec61Sdh155122 return; 4139f4b3ec61Sdh155122 } 4140f4b3ec61Sdh155122 if ((err = zonecfg_set_iptype(handle, iptype)) != Z_OK) 4141bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 4142f4b3ec61Sdh155122 else 4143bbec428eSgjelinek need_to_commit = B_TRUE; 4144f4b3ec61Sdh155122 return; 41450209230bSgjelinek case RT_MAXLWPS: 41460209230bSgjelinek set_aliased_rctl(ALIAS_MAXLWPS, prop_type, prop_id); 41470209230bSgjelinek return; 41480209230bSgjelinek case RT_MAXSHMMEM: 41490209230bSgjelinek set_aliased_rctl(ALIAS_MAXSHMMEM, prop_type, prop_id); 41500209230bSgjelinek return; 41510209230bSgjelinek case RT_MAXSHMIDS: 41520209230bSgjelinek set_aliased_rctl(ALIAS_MAXSHMIDS, prop_type, prop_id); 41530209230bSgjelinek return; 41540209230bSgjelinek case RT_MAXMSGIDS: 41550209230bSgjelinek set_aliased_rctl(ALIAS_MAXMSGIDS, prop_type, prop_id); 41560209230bSgjelinek return; 41570209230bSgjelinek case RT_MAXSEMIDS: 41580209230bSgjelinek set_aliased_rctl(ALIAS_MAXSEMIDS, prop_type, prop_id); 41590209230bSgjelinek return; 41600209230bSgjelinek case RT_SHARES: 41610209230bSgjelinek set_aliased_rctl(ALIAS_SHARES, prop_type, prop_id); 41620209230bSgjelinek return; 41635679c89fSjv227347 case RT_HOSTID: 41645679c89fSjv227347 if ((err = zonecfg_set_hostid(handle, prop_id)) != Z_OK) { 41655679c89fSjv227347 if (err == Z_TOO_BIG) { 41665679c89fSjv227347 zerr(gettext("hostid string is too large: %s"), 41675679c89fSjv227347 prop_id); 41685679c89fSjv227347 saw_error = B_TRUE; 41695679c89fSjv227347 } else { 41705679c89fSjv227347 zone_perror(pt_to_str(prop_type), err, B_TRUE); 41715679c89fSjv227347 } 41725679c89fSjv227347 return; 41735679c89fSjv227347 } 41745679c89fSjv227347 need_to_commit = B_TRUE; 41755679c89fSjv227347 return; 41767c478bd9Sstevel@tonic-gate case RT_FS: 41777c478bd9Sstevel@tonic-gate switch (prop_type) { 41787c478bd9Sstevel@tonic-gate case PT_DIR: 41797c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_fstab.zone_fs_dir, prop_id, 41807c478bd9Sstevel@tonic-gate sizeof (in_progress_fstab.zone_fs_dir)); 41817c478bd9Sstevel@tonic-gate return; 41827c478bd9Sstevel@tonic-gate case PT_SPECIAL: 41837c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_fstab.zone_fs_special, 41847c478bd9Sstevel@tonic-gate prop_id, 41857c478bd9Sstevel@tonic-gate sizeof (in_progress_fstab.zone_fs_special)); 41867c478bd9Sstevel@tonic-gate return; 41877c478bd9Sstevel@tonic-gate case PT_RAW: 41887c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_fstab.zone_fs_raw, 41897c478bd9Sstevel@tonic-gate prop_id, sizeof (in_progress_fstab.zone_fs_raw)); 41907c478bd9Sstevel@tonic-gate return; 41917c478bd9Sstevel@tonic-gate case PT_TYPE: 41927c478bd9Sstevel@tonic-gate if (!valid_fs_type(prop_id)) { 41937c478bd9Sstevel@tonic-gate zerr(gettext("\"%s\" is not a valid %s."), 41947c478bd9Sstevel@tonic-gate prop_id, pt_to_str(PT_TYPE)); 4195bbec428eSgjelinek saw_error = B_TRUE; 41967c478bd9Sstevel@tonic-gate return; 41977c478bd9Sstevel@tonic-gate } 41987c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_fstab.zone_fs_type, prop_id, 41997c478bd9Sstevel@tonic-gate sizeof (in_progress_fstab.zone_fs_type)); 42007c478bd9Sstevel@tonic-gate return; 42017c478bd9Sstevel@tonic-gate case PT_OPTIONS: 42027c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE && 42037c478bd9Sstevel@tonic-gate pp->pv_type != PROP_VAL_LIST) { 42047c478bd9Sstevel@tonic-gate zerr(gettext("A %s or %s value was expected " 42057c478bd9Sstevel@tonic-gate "here."), pvt_to_str(PROP_VAL_SIMPLE), 42067c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_LIST)); 4207bbec428eSgjelinek saw_error = B_TRUE; 42087c478bd9Sstevel@tonic-gate return; 42097c478bd9Sstevel@tonic-gate } 42107c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list( 42117c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_options); 42127c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_options = NULL; 42137c478bd9Sstevel@tonic-gate if (!(pp->pv_type == PROP_VAL_LIST && 42147c478bd9Sstevel@tonic-gate pp->pv_list == NULL)) 42157c478bd9Sstevel@tonic-gate add_property(cmd); 42167c478bd9Sstevel@tonic-gate return; 42177c478bd9Sstevel@tonic-gate default: 42187c478bd9Sstevel@tonic-gate break; 42197c478bd9Sstevel@tonic-gate } 4220bbec428eSgjelinek zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, B_TRUE); 4221bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4222bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 42237c478bd9Sstevel@tonic-gate return; 42247c478bd9Sstevel@tonic-gate case RT_IPD: 42257c478bd9Sstevel@tonic-gate switch (prop_type) { 42267c478bd9Sstevel@tonic-gate case PT_DIR: 42277c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_ipdtab.zone_fs_dir, prop_id, 42287c478bd9Sstevel@tonic-gate sizeof (in_progress_ipdtab.zone_fs_dir)); 42297c478bd9Sstevel@tonic-gate return; 42307c478bd9Sstevel@tonic-gate default: 42317c478bd9Sstevel@tonic-gate break; 42327c478bd9Sstevel@tonic-gate } 4233bbec428eSgjelinek zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, B_TRUE); 4234bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4235bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 42367c478bd9Sstevel@tonic-gate return; 42377c478bd9Sstevel@tonic-gate case RT_NET: 42387c478bd9Sstevel@tonic-gate switch (prop_type) { 42397c478bd9Sstevel@tonic-gate case PT_ADDRESS: 42407c478bd9Sstevel@tonic-gate if (validate_net_address_syntax(prop_id) != Z_OK) { 4241bbec428eSgjelinek saw_error = B_TRUE; 42427c478bd9Sstevel@tonic-gate return; 42437c478bd9Sstevel@tonic-gate } 42447c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_nwiftab.zone_nwif_address, 42457c478bd9Sstevel@tonic-gate prop_id, 42467c478bd9Sstevel@tonic-gate sizeof (in_progress_nwiftab.zone_nwif_address)); 42477c478bd9Sstevel@tonic-gate break; 42487c478bd9Sstevel@tonic-gate case PT_PHYSICAL: 42497c478bd9Sstevel@tonic-gate if (validate_net_physical_syntax(prop_id) != Z_OK) { 4250bbec428eSgjelinek saw_error = B_TRUE; 42517c478bd9Sstevel@tonic-gate return; 42527c478bd9Sstevel@tonic-gate } 42537c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_nwiftab.zone_nwif_physical, 42547c478bd9Sstevel@tonic-gate prop_id, 42557c478bd9Sstevel@tonic-gate sizeof (in_progress_nwiftab.zone_nwif_physical)); 42567c478bd9Sstevel@tonic-gate break; 4257de860bd9Sgfaden case PT_DEFROUTER: 4258de860bd9Sgfaden if (validate_net_address_syntax(prop_id) != Z_OK) { 4259bbec428eSgjelinek saw_error = B_TRUE; 4260de860bd9Sgfaden return; 4261de860bd9Sgfaden } 4262de860bd9Sgfaden (void) strlcpy(in_progress_nwiftab.zone_nwif_defrouter, 4263de860bd9Sgfaden prop_id, 4264de860bd9Sgfaden sizeof (in_progress_nwiftab.zone_nwif_defrouter)); 4265de860bd9Sgfaden break; 42667c478bd9Sstevel@tonic-gate default: 42677c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 4268bbec428eSgjelinek B_TRUE); 4269bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4270bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 42717c478bd9Sstevel@tonic-gate return; 42727c478bd9Sstevel@tonic-gate } 42737c478bd9Sstevel@tonic-gate return; 42747c478bd9Sstevel@tonic-gate case RT_DEVICE: 42757c478bd9Sstevel@tonic-gate switch (prop_type) { 42767c478bd9Sstevel@tonic-gate case PT_MATCH: 42777c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_devtab.zone_dev_match, 42787c478bd9Sstevel@tonic-gate prop_id, 42797c478bd9Sstevel@tonic-gate sizeof (in_progress_devtab.zone_dev_match)); 42807c478bd9Sstevel@tonic-gate break; 42817c478bd9Sstevel@tonic-gate default: 42827c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 4283bbec428eSgjelinek B_TRUE); 4284bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4285bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 42867c478bd9Sstevel@tonic-gate return; 42877c478bd9Sstevel@tonic-gate } 42887c478bd9Sstevel@tonic-gate return; 42897c478bd9Sstevel@tonic-gate case RT_RCTL: 42907c478bd9Sstevel@tonic-gate switch (prop_type) { 42917c478bd9Sstevel@tonic-gate case PT_NAME: 42927c478bd9Sstevel@tonic-gate if (!zonecfg_valid_rctlname(prop_id)) { 42937c478bd9Sstevel@tonic-gate zerr(gettext("'%s' is not a valid zone %s " 42947c478bd9Sstevel@tonic-gate "name."), prop_id, rt_to_str(RT_RCTL)); 42957c478bd9Sstevel@tonic-gate return; 42967c478bd9Sstevel@tonic-gate } 42977c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_rctltab.zone_rctl_name, 42987c478bd9Sstevel@tonic-gate prop_id, 42997c478bd9Sstevel@tonic-gate sizeof (in_progress_rctltab.zone_rctl_name)); 43007c478bd9Sstevel@tonic-gate break; 43017c478bd9Sstevel@tonic-gate case PT_VALUE: 43027c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_COMPLEX && 43037c478bd9Sstevel@tonic-gate pp->pv_type != PROP_VAL_LIST) { 43047c478bd9Sstevel@tonic-gate zerr(gettext("A %s or %s value was expected " 43057c478bd9Sstevel@tonic-gate "here."), pvt_to_str(PROP_VAL_COMPLEX), 43067c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_LIST)); 4307bbec428eSgjelinek saw_error = B_TRUE; 43087c478bd9Sstevel@tonic-gate return; 43097c478bd9Sstevel@tonic-gate } 43107c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list( 43117c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_valptr); 43127c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_valptr = NULL; 43137c478bd9Sstevel@tonic-gate if (!(pp->pv_type == PROP_VAL_LIST && 43147c478bd9Sstevel@tonic-gate pp->pv_list == NULL)) 43157c478bd9Sstevel@tonic-gate add_property(cmd); 43167c478bd9Sstevel@tonic-gate break; 43177c478bd9Sstevel@tonic-gate default: 43187c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 4319bbec428eSgjelinek B_TRUE); 4320bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4321bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 43227c478bd9Sstevel@tonic-gate return; 43237c478bd9Sstevel@tonic-gate } 43247c478bd9Sstevel@tonic-gate return; 43257c478bd9Sstevel@tonic-gate case RT_ATTR: 43267c478bd9Sstevel@tonic-gate switch (prop_type) { 43277c478bd9Sstevel@tonic-gate case PT_NAME: 43287c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_attrtab.zone_attr_name, 43297c478bd9Sstevel@tonic-gate prop_id, 43307c478bd9Sstevel@tonic-gate sizeof (in_progress_attrtab.zone_attr_name)); 43317c478bd9Sstevel@tonic-gate break; 43327c478bd9Sstevel@tonic-gate case PT_TYPE: 43337c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_attrtab.zone_attr_type, 43347c478bd9Sstevel@tonic-gate prop_id, 43357c478bd9Sstevel@tonic-gate sizeof (in_progress_attrtab.zone_attr_type)); 43367c478bd9Sstevel@tonic-gate break; 43377c478bd9Sstevel@tonic-gate case PT_VALUE: 43387c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_attrtab.zone_attr_value, 43397c478bd9Sstevel@tonic-gate prop_id, 43407c478bd9Sstevel@tonic-gate sizeof (in_progress_attrtab.zone_attr_value)); 43417c478bd9Sstevel@tonic-gate break; 43427c478bd9Sstevel@tonic-gate default: 43437c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 4344bbec428eSgjelinek B_TRUE); 4345bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4346bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 43477c478bd9Sstevel@tonic-gate return; 43487c478bd9Sstevel@tonic-gate } 43497c478bd9Sstevel@tonic-gate return; 4350fa9e4066Sahrens case RT_DATASET: 4351fa9e4066Sahrens switch (prop_type) { 4352fa9e4066Sahrens case PT_NAME: 4353fa9e4066Sahrens (void) strlcpy(in_progress_dstab.zone_dataset_name, 4354fa9e4066Sahrens prop_id, 4355fa9e4066Sahrens sizeof (in_progress_dstab.zone_dataset_name)); 4356fa9e4066Sahrens return; 4357fa9e4066Sahrens default: 4358fa9e4066Sahrens break; 4359fa9e4066Sahrens } 4360bbec428eSgjelinek zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, B_TRUE); 4361bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4362bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 4363fa9e4066Sahrens return; 43640209230bSgjelinek case RT_DCPU: 43650209230bSgjelinek switch (prop_type) { 43660209230bSgjelinek char *lowp, *highp; 43670209230bSgjelinek 43680209230bSgjelinek case PT_NCPUS: 43690209230bSgjelinek lowp = prop_id; 43700209230bSgjelinek if ((highp = strchr(prop_id, '-')) != NULL) 43710209230bSgjelinek *highp++ = '\0'; 43720209230bSgjelinek else 43730209230bSgjelinek highp = lowp; 43740209230bSgjelinek 43750209230bSgjelinek /* Make sure the input makes sense. */ 43760209230bSgjelinek if (!zonecfg_valid_ncpus(lowp, highp)) { 43770209230bSgjelinek zerr(gettext("%s property is out of range."), 43780209230bSgjelinek pt_to_str(PT_NCPUS)); 4379bbec428eSgjelinek saw_error = B_TRUE; 43800209230bSgjelinek return; 43810209230bSgjelinek } 43820209230bSgjelinek 43830209230bSgjelinek (void) strlcpy( 43840209230bSgjelinek in_progress_psettab.zone_ncpu_min, lowp, 43850209230bSgjelinek sizeof (in_progress_psettab.zone_ncpu_min)); 43860209230bSgjelinek (void) strlcpy( 43870209230bSgjelinek in_progress_psettab.zone_ncpu_max, highp, 43880209230bSgjelinek sizeof (in_progress_psettab.zone_ncpu_max)); 43890209230bSgjelinek return; 43900209230bSgjelinek case PT_IMPORTANCE: 43910209230bSgjelinek /* Make sure the value makes sense. */ 43920209230bSgjelinek if (!zonecfg_valid_importance(prop_id)) { 43930209230bSgjelinek zerr(gettext("%s property is out of range."), 43940209230bSgjelinek pt_to_str(PT_IMPORTANCE)); 4395bbec428eSgjelinek saw_error = B_TRUE; 43960209230bSgjelinek return; 43970209230bSgjelinek } 43980209230bSgjelinek 43990209230bSgjelinek (void) strlcpy(in_progress_psettab.zone_importance, 44000209230bSgjelinek prop_id, 44010209230bSgjelinek sizeof (in_progress_psettab.zone_importance)); 44020209230bSgjelinek return; 44030209230bSgjelinek default: 44040209230bSgjelinek break; 44050209230bSgjelinek } 4406bbec428eSgjelinek zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, B_TRUE); 4407bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4408bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 44090209230bSgjelinek return; 4410c97ad5cdSakolb case RT_PCAP: 4411c97ad5cdSakolb if (prop_type != PT_NCPUS) { 4412c97ad5cdSakolb zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 4413bbec428eSgjelinek B_TRUE); 4414bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4415bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 4416c97ad5cdSakolb return; 4417c97ad5cdSakolb } 4418c97ad5cdSakolb 4419c97ad5cdSakolb /* 4420c97ad5cdSakolb * We already checked that an rctl alias is allowed in 4421c97ad5cdSakolb * the add_resource() function. 4422c97ad5cdSakolb */ 4423c97ad5cdSakolb 4424c97ad5cdSakolb if ((cap = strtof(prop_id, &unitp)) <= 0 || *unitp != '\0' || 4425c97ad5cdSakolb (int)(cap * 100) < 1) { 4426c97ad5cdSakolb zerr(gettext("%s property is out of range."), 4427c97ad5cdSakolb pt_to_str(PT_NCPUS)); 4428bbec428eSgjelinek saw_error = B_TRUE; 4429c97ad5cdSakolb return; 4430c97ad5cdSakolb } 4431c97ad5cdSakolb 4432c97ad5cdSakolb if ((err = zonecfg_set_aliased_rctl(handle, ALIAS_CPUCAP, 4433c97ad5cdSakolb (int)(cap * 100))) != Z_OK) 4434bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 4435c97ad5cdSakolb else 4436bbec428eSgjelinek need_to_commit = B_TRUE; 4437c97ad5cdSakolb return; 44380209230bSgjelinek case RT_MCAP: 44390209230bSgjelinek switch (prop_type) { 44400209230bSgjelinek case PT_PHYSICAL: 44410209230bSgjelinek if (!zonecfg_valid_memlimit(prop_id, &mem_cap)) { 44420209230bSgjelinek zerr(gettext("A positive number with a " 44430209230bSgjelinek "required scale suffix (K, M, G or T) was " 44440209230bSgjelinek "expected here.")); 4445bbec428eSgjelinek saw_error = B_TRUE; 44460209230bSgjelinek } else if (mem_cap < ONE_MB) { 44470209230bSgjelinek zerr(gettext("%s value is too small. It must " 44480209230bSgjelinek "be at least 1M."), pt_to_str(PT_PHYSICAL)); 4449bbec428eSgjelinek saw_error = B_TRUE; 44500209230bSgjelinek } else { 44510209230bSgjelinek snprintf(in_progress_mcaptab.zone_physmem_cap, 44520209230bSgjelinek physmem_size, "%llu", mem_cap); 44530209230bSgjelinek } 44540209230bSgjelinek break; 44550209230bSgjelinek case PT_SWAP: 44560209230bSgjelinek /* 44570209230bSgjelinek * We have to check if an rctl is allowed here since 44580209230bSgjelinek * there might already be a rctl defined that blocks 44590209230bSgjelinek * the alias. 44600209230bSgjelinek */ 44610209230bSgjelinek if (!zonecfg_aliased_rctl_ok(handle, ALIAS_MAXSWAP)) { 44620209230bSgjelinek zone_perror(pt_to_str(PT_MAXSWAP), 4463bbec428eSgjelinek Z_ALIAS_DISALLOW, B_FALSE); 4464bbec428eSgjelinek saw_error = B_TRUE; 44650209230bSgjelinek return; 44660209230bSgjelinek } 44670209230bSgjelinek 44680209230bSgjelinek if (global_zone) 44690209230bSgjelinek mem_limit = ONE_MB * 100; 44700209230bSgjelinek else 44710209230bSgjelinek mem_limit = ONE_MB * 50; 44720209230bSgjelinek 44730209230bSgjelinek if (!zonecfg_valid_memlimit(prop_id, &mem_cap)) { 44740209230bSgjelinek zerr(gettext("A positive number with a " 44750209230bSgjelinek "required scale suffix (K, M, G or T) was " 44760209230bSgjelinek "expected here.")); 4477bbec428eSgjelinek saw_error = B_TRUE; 44780209230bSgjelinek } else if (mem_cap < mem_limit) { 44790209230bSgjelinek char buf[128]; 44800209230bSgjelinek 44810209230bSgjelinek (void) snprintf(buf, sizeof (buf), "%llu", 44820209230bSgjelinek mem_limit); 44830209230bSgjelinek bytes_to_units(buf, buf, sizeof (buf)); 44840209230bSgjelinek zerr(gettext("%s value is too small. It must " 44850209230bSgjelinek "be at least %s."), pt_to_str(PT_SWAP), 44860209230bSgjelinek buf); 4487bbec428eSgjelinek saw_error = B_TRUE; 44880209230bSgjelinek } else { 44890209230bSgjelinek if ((err = zonecfg_set_aliased_rctl(handle, 44900209230bSgjelinek ALIAS_MAXSWAP, mem_cap)) != Z_OK) 4491bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 44920209230bSgjelinek else 4493bbec428eSgjelinek need_to_commit = B_TRUE; 44940209230bSgjelinek } 44950209230bSgjelinek break; 44960209230bSgjelinek case PT_LOCKED: 44970209230bSgjelinek /* 44980209230bSgjelinek * We have to check if an rctl is allowed here since 44990209230bSgjelinek * there might already be a rctl defined that blocks 45000209230bSgjelinek * the alias. 45010209230bSgjelinek */ 45020209230bSgjelinek if (!zonecfg_aliased_rctl_ok(handle, 45030209230bSgjelinek ALIAS_MAXLOCKEDMEM)) { 45040209230bSgjelinek zone_perror(pt_to_str(PT_LOCKED), 4505bbec428eSgjelinek Z_ALIAS_DISALLOW, B_FALSE); 4506bbec428eSgjelinek saw_error = B_TRUE; 45070209230bSgjelinek return; 45080209230bSgjelinek } 45090209230bSgjelinek 45100209230bSgjelinek if (!zonecfg_valid_memlimit(prop_id, &mem_cap)) { 45110209230bSgjelinek zerr(gettext("A non-negative number with a " 45120209230bSgjelinek "required scale suffix (K, M, G or T) was " 45130209230bSgjelinek "expected\nhere.")); 4514bbec428eSgjelinek saw_error = B_TRUE; 45150209230bSgjelinek } else { 45160209230bSgjelinek if ((err = zonecfg_set_aliased_rctl(handle, 45170209230bSgjelinek ALIAS_MAXLOCKEDMEM, mem_cap)) != Z_OK) 4518bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 45190209230bSgjelinek else 4520bbec428eSgjelinek need_to_commit = B_TRUE; 45210209230bSgjelinek } 45220209230bSgjelinek break; 45230209230bSgjelinek default: 45240209230bSgjelinek zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 4525bbec428eSgjelinek B_TRUE); 4526bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4527bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 45280209230bSgjelinek return; 45290209230bSgjelinek } 45300209230bSgjelinek 45310209230bSgjelinek return; 45327c478bd9Sstevel@tonic-gate default: 4533bbec428eSgjelinek zone_perror(rt_to_str(res_type), Z_NO_RESOURCE_TYPE, B_TRUE); 4534bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4535bbec428eSgjelinek usage(B_FALSE, HELP_RESOURCES); 45367c478bd9Sstevel@tonic-gate return; 45377c478bd9Sstevel@tonic-gate } 45387c478bd9Sstevel@tonic-gate } 45397c478bd9Sstevel@tonic-gate 45407c478bd9Sstevel@tonic-gate static void 4541bbec428eSgjelinek output_prop(FILE *fp, int pnum, char *pval, boolean_t print_notspec) 45427c478bd9Sstevel@tonic-gate { 45437c478bd9Sstevel@tonic-gate char *qstr; 45447c478bd9Sstevel@tonic-gate 45457c478bd9Sstevel@tonic-gate if (*pval != '\0') { 45467c478bd9Sstevel@tonic-gate qstr = quoteit(pval); 45470209230bSgjelinek if (pnum == PT_SWAP || pnum == PT_LOCKED) 45480209230bSgjelinek (void) fprintf(fp, "\t[%s: %s]\n", pt_to_str(pnum), 45490209230bSgjelinek qstr); 45500209230bSgjelinek else 45517c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s: %s\n", pt_to_str(pnum), qstr); 45527c478bd9Sstevel@tonic-gate free(qstr); 45537c478bd9Sstevel@tonic-gate } else if (print_notspec) 4554087719fdSdp (void) fprintf(fp, gettext("\t%s not specified\n"), 4555087719fdSdp pt_to_str(pnum)); 4556087719fdSdp } 4557087719fdSdp 4558087719fdSdp static void 4559087719fdSdp info_zonename(zone_dochandle_t handle, FILE *fp) 4560087719fdSdp { 4561087719fdSdp char zonename[ZONENAME_MAX]; 4562087719fdSdp 4563087719fdSdp if (zonecfg_get_name(handle, zonename, sizeof (zonename)) == Z_OK) 4564087719fdSdp (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_ZONENAME), 4565087719fdSdp zonename); 4566087719fdSdp else 4567087719fdSdp (void) fprintf(fp, gettext("%s not specified\n"), 4568087719fdSdp pt_to_str(PT_ZONENAME)); 45697c478bd9Sstevel@tonic-gate } 45707c478bd9Sstevel@tonic-gate 45717c478bd9Sstevel@tonic-gate static void 45727c478bd9Sstevel@tonic-gate info_zonepath(zone_dochandle_t handle, FILE *fp) 45737c478bd9Sstevel@tonic-gate { 45747c478bd9Sstevel@tonic-gate char zonepath[MAXPATHLEN]; 45757c478bd9Sstevel@tonic-gate 45767c478bd9Sstevel@tonic-gate if (zonecfg_get_zonepath(handle, zonepath, sizeof (zonepath)) == Z_OK) 45777c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_ZONEPATH), 45787c478bd9Sstevel@tonic-gate zonepath); 4579087719fdSdp else { 4580087719fdSdp (void) fprintf(fp, gettext("%s not specified\n"), 4581087719fdSdp pt_to_str(PT_ZONEPATH)); 4582087719fdSdp } 45837c478bd9Sstevel@tonic-gate } 45847c478bd9Sstevel@tonic-gate 45857c478bd9Sstevel@tonic-gate static void 45869acbbeafSnn35248 info_brand(zone_dochandle_t handle, FILE *fp) 45879acbbeafSnn35248 { 45889acbbeafSnn35248 char brand[MAXNAMELEN]; 45899acbbeafSnn35248 45909acbbeafSnn35248 if (zonecfg_get_brand(handle, brand, sizeof (brand)) == Z_OK) 45919acbbeafSnn35248 (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_BRAND), 45929acbbeafSnn35248 brand); 45939acbbeafSnn35248 else 45949acbbeafSnn35248 (void) fprintf(fp, "%s %s\n", pt_to_str(PT_BRAND), 45959acbbeafSnn35248 gettext("not specified")); 45969acbbeafSnn35248 } 45979acbbeafSnn35248 45989acbbeafSnn35248 static void 45997c478bd9Sstevel@tonic-gate info_autoboot(zone_dochandle_t handle, FILE *fp) 46007c478bd9Sstevel@tonic-gate { 46017c478bd9Sstevel@tonic-gate boolean_t autoboot; 46027c478bd9Sstevel@tonic-gate int err; 46037c478bd9Sstevel@tonic-gate 46047c478bd9Sstevel@tonic-gate if ((err = zonecfg_get_autoboot(handle, &autoboot)) == Z_OK) 46057c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_AUTOBOOT), 46067c478bd9Sstevel@tonic-gate autoboot ? "true" : "false"); 46077c478bd9Sstevel@tonic-gate else 4608bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 46097c478bd9Sstevel@tonic-gate } 46107c478bd9Sstevel@tonic-gate 46117c478bd9Sstevel@tonic-gate static void 46127c478bd9Sstevel@tonic-gate info_pool(zone_dochandle_t handle, FILE *fp) 46137c478bd9Sstevel@tonic-gate { 46147c478bd9Sstevel@tonic-gate char pool[MAXNAMELEN]; 46157c478bd9Sstevel@tonic-gate int err; 46167c478bd9Sstevel@tonic-gate 46177c478bd9Sstevel@tonic-gate if ((err = zonecfg_get_pool(handle, pool, sizeof (pool))) == Z_OK) 46187c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_POOL), pool); 46197c478bd9Sstevel@tonic-gate else 4620bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 46217c478bd9Sstevel@tonic-gate } 46227c478bd9Sstevel@tonic-gate 46237c478bd9Sstevel@tonic-gate static void 4624ffbafc53Scomay info_limitpriv(zone_dochandle_t handle, FILE *fp) 4625ffbafc53Scomay { 4626ffbafc53Scomay char *limitpriv; 4627ffbafc53Scomay int err; 4628ffbafc53Scomay 4629ffbafc53Scomay if ((err = zonecfg_get_limitpriv(handle, &limitpriv)) == Z_OK) { 4630ffbafc53Scomay (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_LIMITPRIV), 4631ffbafc53Scomay limitpriv); 4632ffbafc53Scomay free(limitpriv); 4633ffbafc53Scomay } else { 4634bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 4635ffbafc53Scomay } 4636ffbafc53Scomay } 4637ffbafc53Scomay 4638ffbafc53Scomay static void 46393f2f09c1Sdp info_bootargs(zone_dochandle_t handle, FILE *fp) 46403f2f09c1Sdp { 46413f2f09c1Sdp char bootargs[BOOTARGS_MAX]; 46423f2f09c1Sdp int err; 46433f2f09c1Sdp 46443f2f09c1Sdp if ((err = zonecfg_get_bootargs(handle, bootargs, 46453f2f09c1Sdp sizeof (bootargs))) == Z_OK) { 46463f2f09c1Sdp (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_BOOTARGS), 46473f2f09c1Sdp bootargs); 46483f2f09c1Sdp } else { 4649bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 46503f2f09c1Sdp } 46513f2f09c1Sdp } 46523f2f09c1Sdp 46533f2f09c1Sdp static void 46540209230bSgjelinek info_sched(zone_dochandle_t handle, FILE *fp) 46550209230bSgjelinek { 46560209230bSgjelinek char sched[MAXNAMELEN]; 46570209230bSgjelinek int err; 46580209230bSgjelinek 46590209230bSgjelinek if ((err = zonecfg_get_sched_class(handle, sched, sizeof (sched))) 46600209230bSgjelinek == Z_OK) { 46610209230bSgjelinek (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_SCHED), sched); 46620209230bSgjelinek } else { 4663bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 46640209230bSgjelinek } 46650209230bSgjelinek } 46660209230bSgjelinek 46670209230bSgjelinek static void 4668f4b3ec61Sdh155122 info_iptype(zone_dochandle_t handle, FILE *fp) 4669f4b3ec61Sdh155122 { 4670f4b3ec61Sdh155122 zone_iptype_t iptype; 4671f4b3ec61Sdh155122 int err; 4672f4b3ec61Sdh155122 4673f4b3ec61Sdh155122 if ((err = zonecfg_get_iptype(handle, &iptype)) == Z_OK) { 4674f4b3ec61Sdh155122 switch (iptype) { 4675f4b3ec61Sdh155122 case ZS_SHARED: 4676f4b3ec61Sdh155122 (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_IPTYPE), 4677f4b3ec61Sdh155122 "shared"); 4678f4b3ec61Sdh155122 break; 4679f4b3ec61Sdh155122 case ZS_EXCLUSIVE: 4680f4b3ec61Sdh155122 (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_IPTYPE), 4681f4b3ec61Sdh155122 "exclusive"); 4682f4b3ec61Sdh155122 break; 4683f4b3ec61Sdh155122 } 4684f4b3ec61Sdh155122 } else { 4685bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 4686f4b3ec61Sdh155122 } 4687f4b3ec61Sdh155122 } 4688f4b3ec61Sdh155122 4689f4b3ec61Sdh155122 static void 46905679c89fSjv227347 info_hostid(zone_dochandle_t handle, FILE *fp) 46915679c89fSjv227347 { 46925679c89fSjv227347 char hostidp[HW_HOSTID_LEN]; 46935679c89fSjv227347 46945679c89fSjv227347 /* 46955679c89fSjv227347 * This will display "hostid: " if there isn't a hostid or an 46965679c89fSjv227347 * error occurs while retrieving the hostid from the configuration 46975679c89fSjv227347 * file. 46985679c89fSjv227347 */ 46995679c89fSjv227347 if (zonecfg_get_hostid(handle, hostidp, sizeof (hostidp)) != Z_OK) 47005679c89fSjv227347 hostidp[0] = '\0'; 47015679c89fSjv227347 (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_HOSTID), hostidp); 47025679c89fSjv227347 } 47035679c89fSjv227347 47045679c89fSjv227347 static void 47057c478bd9Sstevel@tonic-gate output_fs(FILE *fp, struct zone_fstab *fstab) 47067c478bd9Sstevel@tonic-gate { 47077c478bd9Sstevel@tonic-gate zone_fsopt_t *this; 47087c478bd9Sstevel@tonic-gate 47097c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n", rt_to_str(RT_FS)); 47107c478bd9Sstevel@tonic-gate output_prop(fp, PT_DIR, fstab->zone_fs_dir, B_TRUE); 47117c478bd9Sstevel@tonic-gate output_prop(fp, PT_SPECIAL, fstab->zone_fs_special, B_TRUE); 47127c478bd9Sstevel@tonic-gate output_prop(fp, PT_RAW, fstab->zone_fs_raw, B_TRUE); 47137c478bd9Sstevel@tonic-gate output_prop(fp, PT_TYPE, fstab->zone_fs_type, B_TRUE); 47147c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s: [", pt_to_str(PT_OPTIONS)); 47157c478bd9Sstevel@tonic-gate for (this = fstab->zone_fs_options; this != NULL; 47167c478bd9Sstevel@tonic-gate this = this->zone_fsopt_next) { 47177c478bd9Sstevel@tonic-gate if (strchr(this->zone_fsopt_opt, '=')) 47187c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\"%s\"", this->zone_fsopt_opt); 47197c478bd9Sstevel@tonic-gate else 47207c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s", this->zone_fsopt_opt); 47217c478bd9Sstevel@tonic-gate if (this->zone_fsopt_next != NULL) 47227c478bd9Sstevel@tonic-gate (void) fprintf(fp, ","); 47237c478bd9Sstevel@tonic-gate } 47247c478bd9Sstevel@tonic-gate (void) fprintf(fp, "]\n"); 47257c478bd9Sstevel@tonic-gate } 47267c478bd9Sstevel@tonic-gate 47277c478bd9Sstevel@tonic-gate static void 47287c478bd9Sstevel@tonic-gate output_ipd(FILE *fp, struct zone_fstab *ipdtab) 47297c478bd9Sstevel@tonic-gate { 47307c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n", rt_to_str(RT_IPD)); 47317c478bd9Sstevel@tonic-gate output_prop(fp, PT_DIR, ipdtab->zone_fs_dir, B_TRUE); 47327c478bd9Sstevel@tonic-gate } 47337c478bd9Sstevel@tonic-gate 47347c478bd9Sstevel@tonic-gate static void 47357c478bd9Sstevel@tonic-gate info_fs(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 47367c478bd9Sstevel@tonic-gate { 47377c478bd9Sstevel@tonic-gate struct zone_fstab lookup, user; 4738bbec428eSgjelinek boolean_t output = B_FALSE; 47397c478bd9Sstevel@tonic-gate 47407c478bd9Sstevel@tonic-gate if (zonecfg_setfsent(handle) != Z_OK) 47417c478bd9Sstevel@tonic-gate return; 47427c478bd9Sstevel@tonic-gate while (zonecfg_getfsent(handle, &lookup) == Z_OK) { 47437c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) { 47447c478bd9Sstevel@tonic-gate output_fs(fp, &lookup); 47457c478bd9Sstevel@tonic-gate goto loopend; 47467c478bd9Sstevel@tonic-gate } 4747bbec428eSgjelinek if (fill_in_fstab(cmd, &user, B_TRUE) != Z_OK) 47487c478bd9Sstevel@tonic-gate goto loopend; 47497c478bd9Sstevel@tonic-gate if (strlen(user.zone_fs_dir) > 0 && 47507c478bd9Sstevel@tonic-gate strcmp(user.zone_fs_dir, lookup.zone_fs_dir) != 0) 47517c478bd9Sstevel@tonic-gate goto loopend; /* no match */ 47527c478bd9Sstevel@tonic-gate if (strlen(user.zone_fs_special) > 0 && 47537c478bd9Sstevel@tonic-gate strcmp(user.zone_fs_special, lookup.zone_fs_special) != 0) 47547c478bd9Sstevel@tonic-gate goto loopend; /* no match */ 47557c478bd9Sstevel@tonic-gate if (strlen(user.zone_fs_type) > 0 && 47567c478bd9Sstevel@tonic-gate strcmp(user.zone_fs_type, lookup.zone_fs_type) != 0) 47577c478bd9Sstevel@tonic-gate goto loopend; /* no match */ 47587c478bd9Sstevel@tonic-gate output_fs(fp, &lookup); 4759bbec428eSgjelinek output = B_TRUE; 47607c478bd9Sstevel@tonic-gate loopend: 47617c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(lookup.zone_fs_options); 47627c478bd9Sstevel@tonic-gate } 47637c478bd9Sstevel@tonic-gate (void) zonecfg_endfsent(handle); 47647c478bd9Sstevel@tonic-gate /* 47657c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was 47667c478bd9Sstevel@tonic-gate * nothing to output. 47677c478bd9Sstevel@tonic-gate */ 47687c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0) 47697c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"), 47707c478bd9Sstevel@tonic-gate rt_to_str(RT_FS)); 47717c478bd9Sstevel@tonic-gate } 47727c478bd9Sstevel@tonic-gate 47737c478bd9Sstevel@tonic-gate static void 47747c478bd9Sstevel@tonic-gate info_ipd(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 47757c478bd9Sstevel@tonic-gate { 47767c478bd9Sstevel@tonic-gate struct zone_fstab lookup, user; 4777bbec428eSgjelinek boolean_t output = B_FALSE; 47787c478bd9Sstevel@tonic-gate 47797c478bd9Sstevel@tonic-gate if (zonecfg_setipdent(handle) != Z_OK) 47807c478bd9Sstevel@tonic-gate return; 47817c478bd9Sstevel@tonic-gate while (zonecfg_getipdent(handle, &lookup) == Z_OK) { 47827c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) { 47837c478bd9Sstevel@tonic-gate output_ipd(fp, &lookup); 47847c478bd9Sstevel@tonic-gate continue; 47857c478bd9Sstevel@tonic-gate } 4786bbec428eSgjelinek if (fill_in_ipdtab(cmd, &user, B_TRUE) != Z_OK) 47877c478bd9Sstevel@tonic-gate continue; 47887c478bd9Sstevel@tonic-gate if (strlen(user.zone_fs_dir) > 0 && 47897c478bd9Sstevel@tonic-gate strcmp(user.zone_fs_dir, lookup.zone_fs_dir) != 0) 47907c478bd9Sstevel@tonic-gate continue; /* no match */ 47917c478bd9Sstevel@tonic-gate output_ipd(fp, &lookup); 4792bbec428eSgjelinek output = B_TRUE; 47937c478bd9Sstevel@tonic-gate } 47947c478bd9Sstevel@tonic-gate (void) zonecfg_endipdent(handle); 47957c478bd9Sstevel@tonic-gate /* 47967c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was 47977c478bd9Sstevel@tonic-gate * nothing to output. 47987c478bd9Sstevel@tonic-gate */ 47997c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0) 48007c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"), 48017c478bd9Sstevel@tonic-gate rt_to_str(RT_IPD)); 48027c478bd9Sstevel@tonic-gate } 48037c478bd9Sstevel@tonic-gate 48047c478bd9Sstevel@tonic-gate static void 48057c478bd9Sstevel@tonic-gate output_net(FILE *fp, struct zone_nwiftab *nwiftab) 48067c478bd9Sstevel@tonic-gate { 48077c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n", rt_to_str(RT_NET)); 48087c478bd9Sstevel@tonic-gate output_prop(fp, PT_ADDRESS, nwiftab->zone_nwif_address, B_TRUE); 48097c478bd9Sstevel@tonic-gate output_prop(fp, PT_PHYSICAL, nwiftab->zone_nwif_physical, B_TRUE); 4810de860bd9Sgfaden output_prop(fp, PT_DEFROUTER, nwiftab->zone_nwif_defrouter, B_TRUE); 48117c478bd9Sstevel@tonic-gate } 48127c478bd9Sstevel@tonic-gate 48137c478bd9Sstevel@tonic-gate static void 48147c478bd9Sstevel@tonic-gate info_net(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 48157c478bd9Sstevel@tonic-gate { 48167c478bd9Sstevel@tonic-gate struct zone_nwiftab lookup, user; 4817bbec428eSgjelinek boolean_t output = B_FALSE; 48187c478bd9Sstevel@tonic-gate 48197c478bd9Sstevel@tonic-gate if (zonecfg_setnwifent(handle) != Z_OK) 48207c478bd9Sstevel@tonic-gate return; 48217c478bd9Sstevel@tonic-gate while (zonecfg_getnwifent(handle, &lookup) == Z_OK) { 48227c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) { 48237c478bd9Sstevel@tonic-gate output_net(fp, &lookup); 48247c478bd9Sstevel@tonic-gate continue; 48257c478bd9Sstevel@tonic-gate } 4826bbec428eSgjelinek if (fill_in_nwiftab(cmd, &user, B_TRUE) != Z_OK) 48277c478bd9Sstevel@tonic-gate continue; 48287c478bd9Sstevel@tonic-gate if (strlen(user.zone_nwif_physical) > 0 && 48297c478bd9Sstevel@tonic-gate strcmp(user.zone_nwif_physical, 48307c478bd9Sstevel@tonic-gate lookup.zone_nwif_physical) != 0) 48317c478bd9Sstevel@tonic-gate continue; /* no match */ 4832f4b3ec61Sdh155122 /* If present make sure it matches */ 48337c478bd9Sstevel@tonic-gate if (strlen(user.zone_nwif_address) > 0 && 48347c478bd9Sstevel@tonic-gate !zonecfg_same_net_address(user.zone_nwif_address, 48357c478bd9Sstevel@tonic-gate lookup.zone_nwif_address)) 48367c478bd9Sstevel@tonic-gate continue; /* no match */ 48377c478bd9Sstevel@tonic-gate output_net(fp, &lookup); 4838bbec428eSgjelinek output = B_TRUE; 48397c478bd9Sstevel@tonic-gate } 48407c478bd9Sstevel@tonic-gate (void) zonecfg_endnwifent(handle); 48417c478bd9Sstevel@tonic-gate /* 48427c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was 48437c478bd9Sstevel@tonic-gate * nothing to output. 48447c478bd9Sstevel@tonic-gate */ 48457c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0) 48467c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"), 48477c478bd9Sstevel@tonic-gate rt_to_str(RT_NET)); 48487c478bd9Sstevel@tonic-gate } 48497c478bd9Sstevel@tonic-gate 48507c478bd9Sstevel@tonic-gate static void 48517c478bd9Sstevel@tonic-gate output_dev(FILE *fp, struct zone_devtab *devtab) 48527c478bd9Sstevel@tonic-gate { 485327e6fb21Sdp (void) fprintf(fp, "%s:\n", rt_to_str(RT_DEVICE)); 48547c478bd9Sstevel@tonic-gate output_prop(fp, PT_MATCH, devtab->zone_dev_match, B_TRUE); 48557c478bd9Sstevel@tonic-gate } 48567c478bd9Sstevel@tonic-gate 48577c478bd9Sstevel@tonic-gate static void 48587c478bd9Sstevel@tonic-gate info_dev(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 48597c478bd9Sstevel@tonic-gate { 48607c478bd9Sstevel@tonic-gate struct zone_devtab lookup, user; 4861bbec428eSgjelinek boolean_t output = B_FALSE; 48627c478bd9Sstevel@tonic-gate 48637c478bd9Sstevel@tonic-gate if (zonecfg_setdevent(handle) != Z_OK) 48647c478bd9Sstevel@tonic-gate return; 48657c478bd9Sstevel@tonic-gate while (zonecfg_getdevent(handle, &lookup) == Z_OK) { 48667c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) { 48677c478bd9Sstevel@tonic-gate output_dev(fp, &lookup); 48687c478bd9Sstevel@tonic-gate continue; 48697c478bd9Sstevel@tonic-gate } 4870bbec428eSgjelinek if (fill_in_devtab(cmd, &user, B_TRUE) != Z_OK) 48717c478bd9Sstevel@tonic-gate continue; 48727c478bd9Sstevel@tonic-gate if (strlen(user.zone_dev_match) > 0 && 48737c478bd9Sstevel@tonic-gate strcmp(user.zone_dev_match, lookup.zone_dev_match) != 0) 48747c478bd9Sstevel@tonic-gate continue; /* no match */ 48757c478bd9Sstevel@tonic-gate output_dev(fp, &lookup); 4876bbec428eSgjelinek output = B_TRUE; 48777c478bd9Sstevel@tonic-gate } 48787c478bd9Sstevel@tonic-gate (void) zonecfg_enddevent(handle); 48797c478bd9Sstevel@tonic-gate /* 48807c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was 48817c478bd9Sstevel@tonic-gate * nothing to output. 48827c478bd9Sstevel@tonic-gate */ 48837c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0) 48847c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"), 48857c478bd9Sstevel@tonic-gate rt_to_str(RT_DEVICE)); 48867c478bd9Sstevel@tonic-gate } 48877c478bd9Sstevel@tonic-gate 48887c478bd9Sstevel@tonic-gate static void 48897c478bd9Sstevel@tonic-gate output_rctl(FILE *fp, struct zone_rctltab *rctltab) 48907c478bd9Sstevel@tonic-gate { 48917c478bd9Sstevel@tonic-gate struct zone_rctlvaltab *valptr; 48927c478bd9Sstevel@tonic-gate 48937c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n", rt_to_str(RT_RCTL)); 48947c478bd9Sstevel@tonic-gate output_prop(fp, PT_NAME, rctltab->zone_rctl_name, B_TRUE); 48957c478bd9Sstevel@tonic-gate for (valptr = rctltab->zone_rctl_valptr; valptr != NULL; 48967c478bd9Sstevel@tonic-gate valptr = valptr->zone_rctlval_next) { 48977c478bd9Sstevel@tonic-gate fprintf(fp, "\t%s: (%s=%s,%s=%s,%s=%s)\n", 48987c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE), 48997c478bd9Sstevel@tonic-gate pt_to_str(PT_PRIV), valptr->zone_rctlval_priv, 49007c478bd9Sstevel@tonic-gate pt_to_str(PT_LIMIT), valptr->zone_rctlval_limit, 49017c478bd9Sstevel@tonic-gate pt_to_str(PT_ACTION), valptr->zone_rctlval_action); 49027c478bd9Sstevel@tonic-gate } 49037c478bd9Sstevel@tonic-gate } 49047c478bd9Sstevel@tonic-gate 49057c478bd9Sstevel@tonic-gate static void 49067c478bd9Sstevel@tonic-gate info_rctl(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 49077c478bd9Sstevel@tonic-gate { 49087c478bd9Sstevel@tonic-gate struct zone_rctltab lookup, user; 4909bbec428eSgjelinek boolean_t output = B_FALSE; 49107c478bd9Sstevel@tonic-gate 49117c478bd9Sstevel@tonic-gate if (zonecfg_setrctlent(handle) != Z_OK) 49127c478bd9Sstevel@tonic-gate return; 49137c478bd9Sstevel@tonic-gate while (zonecfg_getrctlent(handle, &lookup) == Z_OK) { 49147c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) { 49157c478bd9Sstevel@tonic-gate output_rctl(fp, &lookup); 4916bbec428eSgjelinek } else if (fill_in_rctltab(cmd, &user, B_TRUE) == Z_OK && 49177c478bd9Sstevel@tonic-gate (strlen(user.zone_rctl_name) == 0 || 49187c478bd9Sstevel@tonic-gate strcmp(user.zone_rctl_name, lookup.zone_rctl_name) == 0)) { 49197c478bd9Sstevel@tonic-gate output_rctl(fp, &lookup); 4920bbec428eSgjelinek output = B_TRUE; 49217c478bd9Sstevel@tonic-gate } 49227c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(lookup.zone_rctl_valptr); 49237c478bd9Sstevel@tonic-gate } 49247c478bd9Sstevel@tonic-gate (void) zonecfg_endrctlent(handle); 49257c478bd9Sstevel@tonic-gate /* 49267c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was 49277c478bd9Sstevel@tonic-gate * nothing to output. 49287c478bd9Sstevel@tonic-gate */ 49297c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0) 49307c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"), 49317c478bd9Sstevel@tonic-gate rt_to_str(RT_RCTL)); 49327c478bd9Sstevel@tonic-gate } 49337c478bd9Sstevel@tonic-gate 49347c478bd9Sstevel@tonic-gate static void 49357c478bd9Sstevel@tonic-gate output_attr(FILE *fp, struct zone_attrtab *attrtab) 49367c478bd9Sstevel@tonic-gate { 49377c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n", rt_to_str(RT_ATTR)); 49387c478bd9Sstevel@tonic-gate output_prop(fp, PT_NAME, attrtab->zone_attr_name, B_TRUE); 49397c478bd9Sstevel@tonic-gate output_prop(fp, PT_TYPE, attrtab->zone_attr_type, B_TRUE); 49407c478bd9Sstevel@tonic-gate output_prop(fp, PT_VALUE, attrtab->zone_attr_value, B_TRUE); 49417c478bd9Sstevel@tonic-gate } 49427c478bd9Sstevel@tonic-gate 49437c478bd9Sstevel@tonic-gate static void 49447c478bd9Sstevel@tonic-gate info_attr(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 49457c478bd9Sstevel@tonic-gate { 49467c478bd9Sstevel@tonic-gate struct zone_attrtab lookup, user; 4947bbec428eSgjelinek boolean_t output = B_FALSE; 49487c478bd9Sstevel@tonic-gate 49497c478bd9Sstevel@tonic-gate if (zonecfg_setattrent(handle) != Z_OK) 49507c478bd9Sstevel@tonic-gate return; 49517c478bd9Sstevel@tonic-gate while (zonecfg_getattrent(handle, &lookup) == Z_OK) { 49527c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) { 49537c478bd9Sstevel@tonic-gate output_attr(fp, &lookup); 49547c478bd9Sstevel@tonic-gate continue; 49557c478bd9Sstevel@tonic-gate } 4956bbec428eSgjelinek if (fill_in_attrtab(cmd, &user, B_TRUE) != Z_OK) 49577c478bd9Sstevel@tonic-gate continue; 49587c478bd9Sstevel@tonic-gate if (strlen(user.zone_attr_name) > 0 && 49597c478bd9Sstevel@tonic-gate strcmp(user.zone_attr_name, lookup.zone_attr_name) != 0) 49607c478bd9Sstevel@tonic-gate continue; /* no match */ 49617c478bd9Sstevel@tonic-gate if (strlen(user.zone_attr_type) > 0 && 49627c478bd9Sstevel@tonic-gate strcmp(user.zone_attr_type, lookup.zone_attr_type) != 0) 49637c478bd9Sstevel@tonic-gate continue; /* no match */ 49647c478bd9Sstevel@tonic-gate if (strlen(user.zone_attr_value) > 0 && 49657c478bd9Sstevel@tonic-gate strcmp(user.zone_attr_value, lookup.zone_attr_value) != 0) 49667c478bd9Sstevel@tonic-gate continue; /* no match */ 49677c478bd9Sstevel@tonic-gate output_attr(fp, &lookup); 4968bbec428eSgjelinek output = B_TRUE; 49697c478bd9Sstevel@tonic-gate } 49707c478bd9Sstevel@tonic-gate (void) zonecfg_endattrent(handle); 49717c478bd9Sstevel@tonic-gate /* 49727c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was 49737c478bd9Sstevel@tonic-gate * nothing to output. 49747c478bd9Sstevel@tonic-gate */ 49757c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0) 49767c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"), 49777c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR)); 49787c478bd9Sstevel@tonic-gate } 49797c478bd9Sstevel@tonic-gate 4980fa9e4066Sahrens static void 4981fa9e4066Sahrens output_ds(FILE *fp, struct zone_dstab *dstab) 4982fa9e4066Sahrens { 4983fa9e4066Sahrens (void) fprintf(fp, "%s:\n", rt_to_str(RT_DATASET)); 4984fa9e4066Sahrens output_prop(fp, PT_NAME, dstab->zone_dataset_name, B_TRUE); 4985fa9e4066Sahrens } 4986fa9e4066Sahrens 4987fa9e4066Sahrens static void 4988fa9e4066Sahrens info_ds(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 4989fa9e4066Sahrens { 4990fa9e4066Sahrens struct zone_dstab lookup, user; 4991bbec428eSgjelinek boolean_t output = B_FALSE; 4992fa9e4066Sahrens 49930209230bSgjelinek if (zonecfg_setdsent(handle) != Z_OK) 4994fa9e4066Sahrens return; 4995fa9e4066Sahrens while (zonecfg_getdsent(handle, &lookup) == Z_OK) { 4996fa9e4066Sahrens if (cmd->cmd_prop_nv_pairs == 0) { 4997fa9e4066Sahrens output_ds(fp, &lookup); 4998fa9e4066Sahrens continue; 4999fa9e4066Sahrens } 5000bbec428eSgjelinek if (fill_in_dstab(cmd, &user, B_TRUE) != Z_OK) 5001fa9e4066Sahrens continue; 5002fa9e4066Sahrens if (strlen(user.zone_dataset_name) > 0 && 5003fa9e4066Sahrens strcmp(user.zone_dataset_name, 5004fa9e4066Sahrens lookup.zone_dataset_name) != 0) 5005fa9e4066Sahrens continue; /* no match */ 5006fa9e4066Sahrens output_ds(fp, &lookup); 5007bbec428eSgjelinek output = B_TRUE; 5008fa9e4066Sahrens } 5009fa9e4066Sahrens (void) zonecfg_enddsent(handle); 5010fa9e4066Sahrens /* 5011fa9e4066Sahrens * If a property n/v pair was specified, warn the user if there was 5012fa9e4066Sahrens * nothing to output. 5013fa9e4066Sahrens */ 5014fa9e4066Sahrens if (!output && cmd->cmd_prop_nv_pairs > 0) 5015fa9e4066Sahrens (void) printf(gettext("No such %s resource.\n"), 5016fa9e4066Sahrens rt_to_str(RT_DATASET)); 5017fa9e4066Sahrens } 5018fa9e4066Sahrens 50190209230bSgjelinek static void 50200209230bSgjelinek output_pset(FILE *fp, struct zone_psettab *psettab) 50210209230bSgjelinek { 50220209230bSgjelinek (void) fprintf(fp, "%s:\n", rt_to_str(RT_DCPU)); 50230209230bSgjelinek if (strcmp(psettab->zone_ncpu_min, psettab->zone_ncpu_max) == 0) 50240209230bSgjelinek (void) fprintf(fp, "\t%s: %s\n", pt_to_str(PT_NCPUS), 50250209230bSgjelinek psettab->zone_ncpu_max); 50260209230bSgjelinek else 50270209230bSgjelinek (void) fprintf(fp, "\t%s: %s-%s\n", pt_to_str(PT_NCPUS), 50280209230bSgjelinek psettab->zone_ncpu_min, psettab->zone_ncpu_max); 50290209230bSgjelinek if (psettab->zone_importance[0] != '\0') 50300209230bSgjelinek (void) fprintf(fp, "\t%s: %s\n", pt_to_str(PT_IMPORTANCE), 50310209230bSgjelinek psettab->zone_importance); 50320209230bSgjelinek } 50330209230bSgjelinek 50340209230bSgjelinek static void 50350209230bSgjelinek info_pset(zone_dochandle_t handle, FILE *fp) 50360209230bSgjelinek { 50370209230bSgjelinek struct zone_psettab lookup; 50380209230bSgjelinek 50390209230bSgjelinek if (zonecfg_getpsetent(handle, &lookup) == Z_OK) 50400209230bSgjelinek output_pset(fp, &lookup); 50410209230bSgjelinek } 50420209230bSgjelinek 50430209230bSgjelinek static void 5044c97ad5cdSakolb output_pcap(FILE *fp) 5045c97ad5cdSakolb { 5046c97ad5cdSakolb uint64_t cap; 5047c97ad5cdSakolb 5048c97ad5cdSakolb if (zonecfg_get_aliased_rctl(handle, ALIAS_CPUCAP, &cap) == Z_OK) { 5049c97ad5cdSakolb float scaled = (float)cap / 100; 5050c97ad5cdSakolb (void) fprintf(fp, "%s:\n", rt_to_str(RT_PCAP)); 5051c97ad5cdSakolb (void) fprintf(fp, "\t[%s: %.2f]\n", pt_to_str(PT_NCPUS), 5052c97ad5cdSakolb scaled); 5053c97ad5cdSakolb } 5054c97ad5cdSakolb } 5055c97ad5cdSakolb 5056c97ad5cdSakolb static void 5057c97ad5cdSakolb info_pcap(FILE *fp) 5058c97ad5cdSakolb { 5059c97ad5cdSakolb output_pcap(fp); 5060c97ad5cdSakolb } 5061c97ad5cdSakolb 5062c97ad5cdSakolb 5063c97ad5cdSakolb static void 50640209230bSgjelinek info_aliased_rctl(zone_dochandle_t handle, FILE *fp, char *alias) 50650209230bSgjelinek { 50660209230bSgjelinek uint64_t limit; 50670209230bSgjelinek 50680209230bSgjelinek if (zonecfg_get_aliased_rctl(handle, alias, &limit) == Z_OK) { 50690209230bSgjelinek /* convert memory based properties */ 50700209230bSgjelinek if (strcmp(alias, ALIAS_MAXSHMMEM) == 0) { 50710209230bSgjelinek char buf[128]; 50720209230bSgjelinek 50730209230bSgjelinek (void) snprintf(buf, sizeof (buf), "%llu", limit); 50740209230bSgjelinek bytes_to_units(buf, buf, sizeof (buf)); 50750209230bSgjelinek (void) fprintf(fp, "[%s: %s]\n", alias, buf); 50760209230bSgjelinek return; 50770209230bSgjelinek } 50780209230bSgjelinek 50790209230bSgjelinek (void) fprintf(fp, "[%s: %llu]\n", alias, limit); 50800209230bSgjelinek } 50810209230bSgjelinek } 50820209230bSgjelinek 50830209230bSgjelinek static void 50840209230bSgjelinek bytes_to_units(char *str, char *buf, int bufsize) 50850209230bSgjelinek { 50860209230bSgjelinek unsigned long long num; 50870209230bSgjelinek unsigned long long save = 0; 50880209230bSgjelinek char *units = "BKMGT"; 50890209230bSgjelinek char *up = units; 50900209230bSgjelinek 50910209230bSgjelinek num = strtoll(str, NULL, 10); 50920209230bSgjelinek 50930209230bSgjelinek if (num < 1024) { 50940209230bSgjelinek (void) snprintf(buf, bufsize, "%llu", num); 50950209230bSgjelinek return; 50960209230bSgjelinek } 50970209230bSgjelinek 50980209230bSgjelinek while ((num >= 1024) && (*up != 'T')) { 50990209230bSgjelinek up++; /* next unit of measurement */ 51000209230bSgjelinek save = num; 51010209230bSgjelinek num = (num + 512) >> 10; 51020209230bSgjelinek } 51030209230bSgjelinek 51040209230bSgjelinek /* check if we should output a fraction. snprintf will round for us */ 51050209230bSgjelinek if (save % 1024 != 0 && ((save >> 10) < 10)) 51060209230bSgjelinek (void) snprintf(buf, bufsize, "%2.1f%c", ((float)save / 1024), 51070209230bSgjelinek *up); 51080209230bSgjelinek else 51090209230bSgjelinek (void) snprintf(buf, bufsize, "%llu%c", num, *up); 51100209230bSgjelinek } 51110209230bSgjelinek 51120209230bSgjelinek static void 51130209230bSgjelinek output_mcap(FILE *fp, struct zone_mcaptab *mcaptab, int showswap, 51140209230bSgjelinek uint64_t maxswap, int showlocked, uint64_t maxlocked) 51150209230bSgjelinek { 51160209230bSgjelinek char buf[128]; 51170209230bSgjelinek 51180209230bSgjelinek (void) fprintf(fp, "%s:\n", rt_to_str(RT_MCAP)); 51190209230bSgjelinek if (mcaptab->zone_physmem_cap[0] != '\0') { 51200209230bSgjelinek bytes_to_units(mcaptab->zone_physmem_cap, buf, sizeof (buf)); 51210209230bSgjelinek output_prop(fp, PT_PHYSICAL, buf, B_TRUE); 51220209230bSgjelinek } 51230209230bSgjelinek 51240209230bSgjelinek if (showswap == Z_OK) { 51250209230bSgjelinek (void) snprintf(buf, sizeof (buf), "%llu", maxswap); 51260209230bSgjelinek bytes_to_units(buf, buf, sizeof (buf)); 51270209230bSgjelinek output_prop(fp, PT_SWAP, buf, B_TRUE); 51280209230bSgjelinek } 51290209230bSgjelinek 51300209230bSgjelinek if (showlocked == Z_OK) { 51310209230bSgjelinek (void) snprintf(buf, sizeof (buf), "%llu", maxlocked); 51320209230bSgjelinek bytes_to_units(buf, buf, sizeof (buf)); 51330209230bSgjelinek output_prop(fp, PT_LOCKED, buf, B_TRUE); 51340209230bSgjelinek } 51350209230bSgjelinek } 51360209230bSgjelinek 51370209230bSgjelinek static void 51380209230bSgjelinek info_mcap(zone_dochandle_t handle, FILE *fp) 51390209230bSgjelinek { 51400209230bSgjelinek int res1, res2, res3; 51410209230bSgjelinek uint64_t swap_limit; 51420209230bSgjelinek uint64_t locked_limit; 51430209230bSgjelinek struct zone_mcaptab lookup; 51440209230bSgjelinek 51450209230bSgjelinek bzero(&lookup, sizeof (lookup)); 51460209230bSgjelinek res1 = zonecfg_getmcapent(handle, &lookup); 51470209230bSgjelinek res2 = zonecfg_get_aliased_rctl(handle, ALIAS_MAXSWAP, &swap_limit); 51480209230bSgjelinek res3 = zonecfg_get_aliased_rctl(handle, ALIAS_MAXLOCKEDMEM, 51490209230bSgjelinek &locked_limit); 51500209230bSgjelinek 51510209230bSgjelinek if (res1 == Z_OK || res2 == Z_OK || res3 == Z_OK) 51520209230bSgjelinek output_mcap(fp, &lookup, res2, swap_limit, res3, locked_limit); 51530209230bSgjelinek } 51540209230bSgjelinek 51557c478bd9Sstevel@tonic-gate void 51567c478bd9Sstevel@tonic-gate info_func(cmd_t *cmd) 51577c478bd9Sstevel@tonic-gate { 51587c478bd9Sstevel@tonic-gate FILE *fp = stdout; 5159bbec428eSgjelinek boolean_t need_to_close = B_FALSE; 51607c478bd9Sstevel@tonic-gate char *pager; 51610209230bSgjelinek int type; 51620209230bSgjelinek int res1, res2; 51630209230bSgjelinek uint64_t swap_limit; 51640209230bSgjelinek uint64_t locked_limit; 51657c478bd9Sstevel@tonic-gate 51667c478bd9Sstevel@tonic-gate assert(cmd != NULL); 51677c478bd9Sstevel@tonic-gate 5168bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 51697c478bd9Sstevel@tonic-gate return; 51707c478bd9Sstevel@tonic-gate 51717c478bd9Sstevel@tonic-gate /* don't page error output */ 51727c478bd9Sstevel@tonic-gate if (interactive_mode) { 51737c478bd9Sstevel@tonic-gate if ((pager = getenv("PAGER")) == NULL) 51747c478bd9Sstevel@tonic-gate pager = PAGER; 51757c478bd9Sstevel@tonic-gate if ((fp = popen(pager, "w")) != NULL) 5176bbec428eSgjelinek need_to_close = B_TRUE; 51777c478bd9Sstevel@tonic-gate setbuf(fp, NULL); 51787c478bd9Sstevel@tonic-gate } 51797c478bd9Sstevel@tonic-gate 51807c478bd9Sstevel@tonic-gate if (!global_scope) { 51817c478bd9Sstevel@tonic-gate switch (resource_scope) { 51827c478bd9Sstevel@tonic-gate case RT_FS: 51837c478bd9Sstevel@tonic-gate output_fs(fp, &in_progress_fstab); 51847c478bd9Sstevel@tonic-gate break; 51857c478bd9Sstevel@tonic-gate case RT_IPD: 51867c478bd9Sstevel@tonic-gate output_ipd(fp, &in_progress_ipdtab); 51877c478bd9Sstevel@tonic-gate break; 51887c478bd9Sstevel@tonic-gate case RT_NET: 51897c478bd9Sstevel@tonic-gate output_net(fp, &in_progress_nwiftab); 51907c478bd9Sstevel@tonic-gate break; 51917c478bd9Sstevel@tonic-gate case RT_DEVICE: 51927c478bd9Sstevel@tonic-gate output_dev(fp, &in_progress_devtab); 51937c478bd9Sstevel@tonic-gate break; 51947c478bd9Sstevel@tonic-gate case RT_RCTL: 51957c478bd9Sstevel@tonic-gate output_rctl(fp, &in_progress_rctltab); 51967c478bd9Sstevel@tonic-gate break; 51977c478bd9Sstevel@tonic-gate case RT_ATTR: 51987c478bd9Sstevel@tonic-gate output_attr(fp, &in_progress_attrtab); 51997c478bd9Sstevel@tonic-gate break; 5200fa9e4066Sahrens case RT_DATASET: 5201fa9e4066Sahrens output_ds(fp, &in_progress_dstab); 5202fa9e4066Sahrens break; 52030209230bSgjelinek case RT_DCPU: 52040209230bSgjelinek output_pset(fp, &in_progress_psettab); 52050209230bSgjelinek break; 5206c97ad5cdSakolb case RT_PCAP: 5207c97ad5cdSakolb output_pcap(fp); 5208c97ad5cdSakolb break; 52090209230bSgjelinek case RT_MCAP: 52100209230bSgjelinek res1 = zonecfg_get_aliased_rctl(handle, ALIAS_MAXSWAP, 52110209230bSgjelinek &swap_limit); 52120209230bSgjelinek res2 = zonecfg_get_aliased_rctl(handle, 52130209230bSgjelinek ALIAS_MAXLOCKEDMEM, &locked_limit); 52140209230bSgjelinek output_mcap(fp, &in_progress_mcaptab, res1, swap_limit, 52150209230bSgjelinek res2, locked_limit); 52160209230bSgjelinek break; 52177c478bd9Sstevel@tonic-gate } 52187c478bd9Sstevel@tonic-gate goto cleanup; 52197c478bd9Sstevel@tonic-gate } 52207c478bd9Sstevel@tonic-gate 52210209230bSgjelinek type = cmd->cmd_res_type; 52220209230bSgjelinek 52230209230bSgjelinek if (gz_invalid_rt_property(type)) { 52240209230bSgjelinek zerr(gettext("%s is not a valid property for the global zone."), 52250209230bSgjelinek rt_to_str(type)); 52260209230bSgjelinek goto cleanup; 52270209230bSgjelinek } 52280209230bSgjelinek 52290209230bSgjelinek if (gz_invalid_resource(type)) { 52300209230bSgjelinek zerr(gettext("%s is not a valid resource for the global zone."), 52310209230bSgjelinek rt_to_str(type)); 52320209230bSgjelinek goto cleanup; 52330209230bSgjelinek } 52340209230bSgjelinek 52357c478bd9Sstevel@tonic-gate switch (cmd->cmd_res_type) { 52367c478bd9Sstevel@tonic-gate case RT_UNKNOWN: 5237087719fdSdp info_zonename(handle, fp); 52380209230bSgjelinek if (!global_zone) { 52397c478bd9Sstevel@tonic-gate info_zonepath(handle, fp); 52409acbbeafSnn35248 info_brand(handle, fp); 52417c478bd9Sstevel@tonic-gate info_autoboot(handle, fp); 52423f2f09c1Sdp info_bootargs(handle, fp); 52430209230bSgjelinek } 52447c478bd9Sstevel@tonic-gate info_pool(handle, fp); 52450209230bSgjelinek if (!global_zone) { 5246ffbafc53Scomay info_limitpriv(handle, fp); 52470209230bSgjelinek info_sched(handle, fp); 5248f4b3ec61Sdh155122 info_iptype(handle, fp); 52495679c89fSjv227347 info_hostid(handle, fp); 52500209230bSgjelinek } 52510209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXLWPS); 52520209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXSHMMEM); 52530209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXSHMIDS); 52540209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXMSGIDS); 52550209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXSEMIDS); 52560209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_SHARES); 52570209230bSgjelinek if (!global_zone) { 52587c478bd9Sstevel@tonic-gate info_ipd(handle, fp, cmd); 52597c478bd9Sstevel@tonic-gate info_fs(handle, fp, cmd); 52607c478bd9Sstevel@tonic-gate info_net(handle, fp, cmd); 52617c478bd9Sstevel@tonic-gate info_dev(handle, fp, cmd); 52620209230bSgjelinek } 52630209230bSgjelinek info_pset(handle, fp); 5264c97ad5cdSakolb info_pcap(fp); 52650209230bSgjelinek info_mcap(handle, fp); 52660209230bSgjelinek if (!global_zone) { 52677c478bd9Sstevel@tonic-gate info_attr(handle, fp, cmd); 5268fa9e4066Sahrens info_ds(handle, fp, cmd); 52690209230bSgjelinek } 52700209230bSgjelinek info_rctl(handle, fp, cmd); 52717c478bd9Sstevel@tonic-gate break; 5272087719fdSdp case RT_ZONENAME: 5273087719fdSdp info_zonename(handle, fp); 5274087719fdSdp break; 52757c478bd9Sstevel@tonic-gate case RT_ZONEPATH: 52767c478bd9Sstevel@tonic-gate info_zonepath(handle, fp); 52777c478bd9Sstevel@tonic-gate break; 52789acbbeafSnn35248 case RT_BRAND: 52799acbbeafSnn35248 info_brand(handle, fp); 52809acbbeafSnn35248 break; 52817c478bd9Sstevel@tonic-gate case RT_AUTOBOOT: 52827c478bd9Sstevel@tonic-gate info_autoboot(handle, fp); 52837c478bd9Sstevel@tonic-gate break; 52847c478bd9Sstevel@tonic-gate case RT_POOL: 52857c478bd9Sstevel@tonic-gate info_pool(handle, fp); 52867c478bd9Sstevel@tonic-gate break; 5287ffbafc53Scomay case RT_LIMITPRIV: 5288ffbafc53Scomay info_limitpriv(handle, fp); 5289ffbafc53Scomay break; 52903f2f09c1Sdp case RT_BOOTARGS: 52913f2f09c1Sdp info_bootargs(handle, fp); 52923f2f09c1Sdp break; 52930209230bSgjelinek case RT_SCHED: 52940209230bSgjelinek info_sched(handle, fp); 52950209230bSgjelinek break; 5296f4b3ec61Sdh155122 case RT_IPTYPE: 5297f4b3ec61Sdh155122 info_iptype(handle, fp); 5298f4b3ec61Sdh155122 break; 52990209230bSgjelinek case RT_MAXLWPS: 53000209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXLWPS); 53010209230bSgjelinek break; 53020209230bSgjelinek case RT_MAXSHMMEM: 53030209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXSHMMEM); 53040209230bSgjelinek break; 53050209230bSgjelinek case RT_MAXSHMIDS: 53060209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXSHMIDS); 53070209230bSgjelinek break; 53080209230bSgjelinek case RT_MAXMSGIDS: 53090209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXMSGIDS); 53100209230bSgjelinek break; 53110209230bSgjelinek case RT_MAXSEMIDS: 53120209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXSEMIDS); 53130209230bSgjelinek break; 53140209230bSgjelinek case RT_SHARES: 53150209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_SHARES); 53160209230bSgjelinek break; 53177c478bd9Sstevel@tonic-gate case RT_FS: 53187c478bd9Sstevel@tonic-gate info_fs(handle, fp, cmd); 53197c478bd9Sstevel@tonic-gate break; 53207c478bd9Sstevel@tonic-gate case RT_IPD: 53217c478bd9Sstevel@tonic-gate info_ipd(handle, fp, cmd); 53227c478bd9Sstevel@tonic-gate break; 53237c478bd9Sstevel@tonic-gate case RT_NET: 53247c478bd9Sstevel@tonic-gate info_net(handle, fp, cmd); 53257c478bd9Sstevel@tonic-gate break; 53267c478bd9Sstevel@tonic-gate case RT_DEVICE: 53277c478bd9Sstevel@tonic-gate info_dev(handle, fp, cmd); 53287c478bd9Sstevel@tonic-gate break; 53297c478bd9Sstevel@tonic-gate case RT_RCTL: 53307c478bd9Sstevel@tonic-gate info_rctl(handle, fp, cmd); 53317c478bd9Sstevel@tonic-gate break; 53327c478bd9Sstevel@tonic-gate case RT_ATTR: 53337c478bd9Sstevel@tonic-gate info_attr(handle, fp, cmd); 53347c478bd9Sstevel@tonic-gate break; 5335fa9e4066Sahrens case RT_DATASET: 5336fa9e4066Sahrens info_ds(handle, fp, cmd); 5337fa9e4066Sahrens break; 53380209230bSgjelinek case RT_DCPU: 53390209230bSgjelinek info_pset(handle, fp); 53400209230bSgjelinek break; 5341c97ad5cdSakolb case RT_PCAP: 5342c97ad5cdSakolb info_pcap(fp); 5343c97ad5cdSakolb break; 53440209230bSgjelinek case RT_MCAP: 53450209230bSgjelinek info_mcap(handle, fp); 53460209230bSgjelinek break; 53475679c89fSjv227347 case RT_HOSTID: 53485679c89fSjv227347 info_hostid(handle, fp); 53495679c89fSjv227347 break; 53507c478bd9Sstevel@tonic-gate default: 53517c478bd9Sstevel@tonic-gate zone_perror(rt_to_str(cmd->cmd_res_type), Z_NO_RESOURCE_TYPE, 5352bbec428eSgjelinek B_TRUE); 53537c478bd9Sstevel@tonic-gate } 53547c478bd9Sstevel@tonic-gate 53557c478bd9Sstevel@tonic-gate cleanup: 53567c478bd9Sstevel@tonic-gate if (need_to_close) 53577c478bd9Sstevel@tonic-gate (void) pclose(fp); 53587c478bd9Sstevel@tonic-gate } 53597c478bd9Sstevel@tonic-gate 5360087719fdSdp /* 5361087719fdSdp * Helper function for verify-- checks that a required string property 5362087719fdSdp * exists. 5363087719fdSdp */ 5364087719fdSdp static void 5365087719fdSdp check_reqd_prop(char *attr, int rt, int pt, int *ret_val) 53667c478bd9Sstevel@tonic-gate { 5367087719fdSdp if (strlen(attr) == 0) { 5368087719fdSdp zerr(gettext("%s: %s not specified"), rt_to_str(rt), 5369087719fdSdp pt_to_str(pt)); 5370bbec428eSgjelinek saw_error = B_TRUE; 5371087719fdSdp if (*ret_val == Z_OK) 5372087719fdSdp *ret_val = Z_REQD_PROPERTY_MISSING; 53737c478bd9Sstevel@tonic-gate } 53747c478bd9Sstevel@tonic-gate } 53757c478bd9Sstevel@tonic-gate 53769acbbeafSnn35248 static int 53779acbbeafSnn35248 do_subproc(char *cmdbuf) 53789acbbeafSnn35248 { 53799acbbeafSnn35248 char inbuf[MAX_CMD_LEN]; 53809acbbeafSnn35248 FILE *file; 53819acbbeafSnn35248 int status; 53829acbbeafSnn35248 53839acbbeafSnn35248 file = popen(cmdbuf, "r"); 53849acbbeafSnn35248 if (file == NULL) { 53859acbbeafSnn35248 zerr(gettext("Could not launch: %s"), cmdbuf); 53869acbbeafSnn35248 return (-1); 53879acbbeafSnn35248 } 53889acbbeafSnn35248 53899acbbeafSnn35248 while (fgets(inbuf, sizeof (inbuf), file) != NULL) 53909acbbeafSnn35248 fprintf(stderr, "%s", inbuf); 53919acbbeafSnn35248 status = pclose(file); 53929acbbeafSnn35248 53939acbbeafSnn35248 if (WIFSIGNALED(status)) { 53949acbbeafSnn35248 zerr(gettext("%s unexpectedly terminated due to signal %d"), 53959acbbeafSnn35248 cmdbuf, WTERMSIG(status)); 53969acbbeafSnn35248 return (-1); 53979acbbeafSnn35248 } 53989acbbeafSnn35248 assert(WIFEXITED(status)); 53999acbbeafSnn35248 return (WEXITSTATUS(status)); 54009acbbeafSnn35248 } 54019acbbeafSnn35248 54029acbbeafSnn35248 static int 54039acbbeafSnn35248 brand_verify(zone_dochandle_t handle) 54049acbbeafSnn35248 { 54056e65f9afSnn35248 char xml_file[32]; 54069acbbeafSnn35248 char cmdbuf[MAX_CMD_LEN]; 5407123807fbSedp brand_handle_t bh; 54089acbbeafSnn35248 char brand[MAXNAMELEN]; 54099acbbeafSnn35248 int err; 54109acbbeafSnn35248 54119acbbeafSnn35248 if (zonecfg_get_brand(handle, brand, sizeof (brand)) != Z_OK) { 54129acbbeafSnn35248 zerr("%s: %s\n", zone, gettext("could not get zone brand")); 54139acbbeafSnn35248 return (Z_INVALID_DOCUMENT); 54149acbbeafSnn35248 } 5415123807fbSedp if ((bh = brand_open(brand)) == NULL) { 54169acbbeafSnn35248 zerr("%s: %s\n", zone, gettext("unknown brand.")); 54179acbbeafSnn35248 return (Z_INVALID_DOCUMENT); 54189acbbeafSnn35248 } 54199acbbeafSnn35248 54209acbbeafSnn35248 /* 54219acbbeafSnn35248 * Fetch the verify command, if any, from the brand configuration 54229acbbeafSnn35248 * and build the command line to execute it. 54239acbbeafSnn35248 */ 54249acbbeafSnn35248 strcpy(cmdbuf, EXEC_PREFIX); 5425123807fbSedp err = brand_get_verify_cfg(bh, cmdbuf + EXEC_LEN, 54269acbbeafSnn35248 sizeof (cmdbuf) - (EXEC_LEN + (strlen(xml_file) + 1))); 5427123807fbSedp brand_close(bh); 54289acbbeafSnn35248 if (err != Z_OK) { 54299acbbeafSnn35248 zerr("%s: %s\n", zone, 54309acbbeafSnn35248 gettext("could not get brand verification command")); 54319acbbeafSnn35248 return (Z_INVALID_DOCUMENT); 54329acbbeafSnn35248 } 54339acbbeafSnn35248 54349acbbeafSnn35248 /* 54359acbbeafSnn35248 * If the brand doesn't provide a verification routine, we just 54369acbbeafSnn35248 * return success. 54379acbbeafSnn35248 */ 54389acbbeafSnn35248 if (strlen(cmdbuf) == EXEC_LEN) 54399acbbeafSnn35248 return (Z_OK); 54409acbbeafSnn35248 54419acbbeafSnn35248 /* 54429acbbeafSnn35248 * Dump the current config information for this zone to a file. 54439acbbeafSnn35248 */ 54446e65f9afSnn35248 strcpy(xml_file, "/tmp/zonecfg_verify.XXXXXX"); 54459acbbeafSnn35248 if (mkstemp(xml_file) == NULL) 54469acbbeafSnn35248 return (Z_TEMP_FILE); 54479acbbeafSnn35248 if ((err = zonecfg_verify_save(handle, xml_file)) != Z_OK) { 54489acbbeafSnn35248 (void) unlink(xml_file); 54499acbbeafSnn35248 return (err); 54509acbbeafSnn35248 } 54519acbbeafSnn35248 54529acbbeafSnn35248 /* 54539acbbeafSnn35248 * Execute the verification command. 54549acbbeafSnn35248 */ 54559acbbeafSnn35248 if ((strlcat(cmdbuf, " ", MAX_CMD_LEN) >= MAX_CMD_LEN) || 54569acbbeafSnn35248 (strlcat(cmdbuf, xml_file, MAX_CMD_LEN) >= MAX_CMD_LEN)) { 54579acbbeafSnn35248 err = Z_BRAND_ERROR; 54589acbbeafSnn35248 } else { 54599acbbeafSnn35248 err = do_subproc(cmdbuf); 54609acbbeafSnn35248 } 54619acbbeafSnn35248 54629acbbeafSnn35248 (void) unlink(xml_file); 54639acbbeafSnn35248 return ((err == Z_OK) ? Z_OK : Z_BRAND_ERROR); 54649acbbeafSnn35248 } 54659acbbeafSnn35248 54667c478bd9Sstevel@tonic-gate /* 54677c478bd9Sstevel@tonic-gate * See the DTD for which attributes are required for which resources. 54687c478bd9Sstevel@tonic-gate * 54697c478bd9Sstevel@tonic-gate * This function can be called by commit_func(), which needs to save things, 54707c478bd9Sstevel@tonic-gate * in addition to the general call from parse_and_run(), which doesn't need 54717c478bd9Sstevel@tonic-gate * things saved. Since the parameters are standardized, we distinguish by 54727c478bd9Sstevel@tonic-gate * having commit_func() call here with cmd->cmd_arg set to "save" to indicate 54737c478bd9Sstevel@tonic-gate * that a save is needed. 54747c478bd9Sstevel@tonic-gate */ 54757c478bd9Sstevel@tonic-gate void 54767c478bd9Sstevel@tonic-gate verify_func(cmd_t *cmd) 54777c478bd9Sstevel@tonic-gate { 54787c478bd9Sstevel@tonic-gate struct zone_nwiftab nwiftab; 54797c478bd9Sstevel@tonic-gate struct zone_fstab fstab; 54807c478bd9Sstevel@tonic-gate struct zone_attrtab attrtab; 54817c478bd9Sstevel@tonic-gate struct zone_rctltab rctltab; 5482fa9e4066Sahrens struct zone_dstab dstab; 54830209230bSgjelinek struct zone_psettab psettab; 54847c478bd9Sstevel@tonic-gate char zonepath[MAXPATHLEN]; 54850209230bSgjelinek char sched[MAXNAMELEN]; 54869acbbeafSnn35248 char brand[MAXNAMELEN]; 54875679c89fSjv227347 char hostidp[HW_HOSTID_LEN]; 54887c478bd9Sstevel@tonic-gate int err, ret_val = Z_OK, arg; 5489c97ad5cdSakolb int pset_res; 5490bbec428eSgjelinek boolean_t save = B_FALSE; 5491bbec428eSgjelinek boolean_t arg_err = B_FALSE; 5492f4b3ec61Sdh155122 zone_iptype_t iptype; 54930209230bSgjelinek boolean_t has_cpu_shares = B_FALSE; 5494c97ad5cdSakolb boolean_t has_cpu_cap = B_FALSE; 54957c478bd9Sstevel@tonic-gate 54967c478bd9Sstevel@tonic-gate optind = 0; 54977ec75eb8Sgjelinek while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?")) != EOF) { 54987c478bd9Sstevel@tonic-gate switch (arg) { 54997c478bd9Sstevel@tonic-gate case '?': 55007c478bd9Sstevel@tonic-gate longer_usage(CMD_VERIFY); 5501bbec428eSgjelinek arg_err = B_TRUE; 55027ec75eb8Sgjelinek break; 55037c478bd9Sstevel@tonic-gate default: 55047c478bd9Sstevel@tonic-gate short_usage(CMD_VERIFY); 5505bbec428eSgjelinek arg_err = B_TRUE; 55067ec75eb8Sgjelinek break; 55077ec75eb8Sgjelinek } 55087ec75eb8Sgjelinek } 55097ec75eb8Sgjelinek if (arg_err) 55107c478bd9Sstevel@tonic-gate return; 55117ec75eb8Sgjelinek 55127c478bd9Sstevel@tonic-gate if (optind > cmd->cmd_argc) { 55137c478bd9Sstevel@tonic-gate short_usage(CMD_VERIFY); 55147c478bd9Sstevel@tonic-gate return; 55157c478bd9Sstevel@tonic-gate } 55167c478bd9Sstevel@tonic-gate 55177c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_VERIFY)) 55187c478bd9Sstevel@tonic-gate return; 55197c478bd9Sstevel@tonic-gate 55207c478bd9Sstevel@tonic-gate assert(cmd != NULL); 55217c478bd9Sstevel@tonic-gate 55227c478bd9Sstevel@tonic-gate if (cmd->cmd_argc > 0 && (strcmp(cmd->cmd_argv[0], "save") == 0)) 5523bbec428eSgjelinek save = B_TRUE; 5524bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 55257c478bd9Sstevel@tonic-gate return; 55267c478bd9Sstevel@tonic-gate 55270209230bSgjelinek if (zonecfg_get_zonepath(handle, zonepath, sizeof (zonepath)) != Z_OK && 55280209230bSgjelinek !global_zone) { 5529087719fdSdp zerr(gettext("%s not specified"), pt_to_str(PT_ZONEPATH)); 55307c478bd9Sstevel@tonic-gate ret_val = Z_REQD_RESOURCE_MISSING; 5531bbec428eSgjelinek saw_error = B_TRUE; 55327c478bd9Sstevel@tonic-gate } 55330209230bSgjelinek if (strlen(zonepath) == 0 && !global_zone) { 5534087719fdSdp zerr(gettext("%s cannot be empty."), pt_to_str(PT_ZONEPATH)); 55357c478bd9Sstevel@tonic-gate ret_val = Z_REQD_RESOURCE_MISSING; 5536bbec428eSgjelinek saw_error = B_TRUE; 55377c478bd9Sstevel@tonic-gate } 55387c478bd9Sstevel@tonic-gate 55399acbbeafSnn35248 if ((err = zonecfg_get_brand(handle, brand, sizeof (brand))) != Z_OK) { 5540bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 55419acbbeafSnn35248 return; 55429acbbeafSnn35248 } 55439acbbeafSnn35248 if ((err = brand_verify(handle)) != Z_OK) { 5544bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 55459acbbeafSnn35248 return; 55469acbbeafSnn35248 } 55479acbbeafSnn35248 5548f4b3ec61Sdh155122 if (zonecfg_get_iptype(handle, &iptype) != Z_OK) { 5549f4b3ec61Sdh155122 zerr("%s %s", gettext("cannot get"), pt_to_str(PT_IPTYPE)); 5550f4b3ec61Sdh155122 ret_val = Z_REQD_RESOURCE_MISSING; 5551bbec428eSgjelinek saw_error = B_TRUE; 5552f4b3ec61Sdh155122 } 55537c478bd9Sstevel@tonic-gate if ((err = zonecfg_setipdent(handle)) != Z_OK) { 5554bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 55557c478bd9Sstevel@tonic-gate return; 55567c478bd9Sstevel@tonic-gate } 55577c478bd9Sstevel@tonic-gate while (zonecfg_getipdent(handle, &fstab) == Z_OK) { 5558087719fdSdp check_reqd_prop(fstab.zone_fs_dir, RT_IPD, PT_DIR, &ret_val); 55597c478bd9Sstevel@tonic-gate } 55607c478bd9Sstevel@tonic-gate (void) zonecfg_endipdent(handle); 55617c478bd9Sstevel@tonic-gate 55625679c89fSjv227347 if (zonecfg_get_hostid(handle, hostidp, sizeof (hostidp)) == Z_OK && 55635679c89fSjv227347 (err = zonecfg_valid_hostid(hostidp)) != Z_OK) { 55645679c89fSjv227347 zone_perror(zone, err, B_TRUE); 55655679c89fSjv227347 return; 55665679c89fSjv227347 } 55675679c89fSjv227347 55687c478bd9Sstevel@tonic-gate if ((err = zonecfg_setfsent(handle)) != Z_OK) { 5569bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 55707c478bd9Sstevel@tonic-gate return; 55717c478bd9Sstevel@tonic-gate } 55727c478bd9Sstevel@tonic-gate while (zonecfg_getfsent(handle, &fstab) == Z_OK) { 5573087719fdSdp check_reqd_prop(fstab.zone_fs_dir, RT_FS, PT_DIR, &ret_val); 5574087719fdSdp check_reqd_prop(fstab.zone_fs_special, RT_FS, PT_SPECIAL, 5575087719fdSdp &ret_val); 5576087719fdSdp check_reqd_prop(fstab.zone_fs_type, RT_FS, PT_TYPE, &ret_val); 5577087719fdSdp 55787c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(fstab.zone_fs_options); 55797c478bd9Sstevel@tonic-gate } 55807c478bd9Sstevel@tonic-gate (void) zonecfg_endfsent(handle); 55817c478bd9Sstevel@tonic-gate 55827c478bd9Sstevel@tonic-gate if ((err = zonecfg_setnwifent(handle)) != Z_OK) { 5583bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 55847c478bd9Sstevel@tonic-gate return; 55857c478bd9Sstevel@tonic-gate } 55867c478bd9Sstevel@tonic-gate while (zonecfg_getnwifent(handle, &nwiftab) == Z_OK) { 5587f4b3ec61Sdh155122 /* 5588f4b3ec61Sdh155122 * physical is required in all cases. 5589de860bd9Sgfaden * A shared IP requires an address, 5590de860bd9Sgfaden * and may include a default router, while 5591de860bd9Sgfaden * an exclusive IP must have neither an address 5592de860bd9Sgfaden * nor a default router. 559301b4bc23Sjv227347 * The physical interface name must be valid in all cases. 5594f4b3ec61Sdh155122 */ 5595087719fdSdp check_reqd_prop(nwiftab.zone_nwif_physical, RT_NET, 5596087719fdSdp PT_PHYSICAL, &ret_val); 559701b4bc23Sjv227347 if (validate_net_physical_syntax(nwiftab.zone_nwif_physical) != 559801b4bc23Sjv227347 Z_OK) { 559901b4bc23Sjv227347 saw_error = B_TRUE; 560001b4bc23Sjv227347 if (ret_val == Z_OK) 560101b4bc23Sjv227347 ret_val = Z_INVAL; 560201b4bc23Sjv227347 } 5603f4b3ec61Sdh155122 5604f4b3ec61Sdh155122 switch (iptype) { 5605f4b3ec61Sdh155122 case ZS_SHARED: 5606f4b3ec61Sdh155122 check_reqd_prop(nwiftab.zone_nwif_address, RT_NET, 5607f4b3ec61Sdh155122 PT_ADDRESS, &ret_val); 5608f4b3ec61Sdh155122 break; 5609f4b3ec61Sdh155122 case ZS_EXCLUSIVE: 5610f4b3ec61Sdh155122 if (strlen(nwiftab.zone_nwif_address) > 0) { 5611f4b3ec61Sdh155122 zerr(gettext("%s: %s cannot be specified " 5612f4b3ec61Sdh155122 "for an exclusive IP type"), 5613f4b3ec61Sdh155122 rt_to_str(RT_NET), pt_to_str(PT_ADDRESS)); 5614bbec428eSgjelinek saw_error = B_TRUE; 5615f4b3ec61Sdh155122 if (ret_val == Z_OK) 5616f4b3ec61Sdh155122 ret_val = Z_INVAL; 5617f4b3ec61Sdh155122 } 5618de860bd9Sgfaden if (strlen(nwiftab.zone_nwif_defrouter) > 0) { 5619de860bd9Sgfaden zerr(gettext("%s: %s cannot be specified " 5620de860bd9Sgfaden "for an exclusive IP type"), 5621de860bd9Sgfaden rt_to_str(RT_NET), pt_to_str(PT_DEFROUTER)); 5622bbec428eSgjelinek saw_error = B_TRUE; 5623de860bd9Sgfaden if (ret_val == Z_OK) 5624de860bd9Sgfaden ret_val = Z_INVAL; 5625de860bd9Sgfaden } 5626f4b3ec61Sdh155122 break; 5627f4b3ec61Sdh155122 } 56287c478bd9Sstevel@tonic-gate } 56297c478bd9Sstevel@tonic-gate (void) zonecfg_endnwifent(handle); 56307c478bd9Sstevel@tonic-gate 56317c478bd9Sstevel@tonic-gate if ((err = zonecfg_setrctlent(handle)) != Z_OK) { 5632bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 56337c478bd9Sstevel@tonic-gate return; 56347c478bd9Sstevel@tonic-gate } 56357c478bd9Sstevel@tonic-gate while (zonecfg_getrctlent(handle, &rctltab) == Z_OK) { 5636087719fdSdp check_reqd_prop(rctltab.zone_rctl_name, RT_RCTL, PT_NAME, 5637087719fdSdp &ret_val); 5638087719fdSdp 56390209230bSgjelinek if (strcmp(rctltab.zone_rctl_name, "zone.cpu-shares") == 0) 56400209230bSgjelinek has_cpu_shares = B_TRUE; 56410209230bSgjelinek 5642c97ad5cdSakolb if (strcmp(rctltab.zone_rctl_name, "zone.cpu-cap") == 0) 5643c97ad5cdSakolb has_cpu_cap = B_TRUE; 5644c97ad5cdSakolb 56457c478bd9Sstevel@tonic-gate if (rctltab.zone_rctl_valptr == NULL) { 56467c478bd9Sstevel@tonic-gate zerr(gettext("%s: no %s specified"), 56477c478bd9Sstevel@tonic-gate rt_to_str(RT_RCTL), pt_to_str(PT_VALUE)); 5648bbec428eSgjelinek saw_error = B_TRUE; 56497c478bd9Sstevel@tonic-gate if (ret_val == Z_OK) 56507c478bd9Sstevel@tonic-gate ret_val = Z_REQD_PROPERTY_MISSING; 56517c478bd9Sstevel@tonic-gate } else { 56527c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctltab.zone_rctl_valptr); 56537c478bd9Sstevel@tonic-gate } 56547c478bd9Sstevel@tonic-gate } 56557c478bd9Sstevel@tonic-gate (void) zonecfg_endrctlent(handle); 56567c478bd9Sstevel@tonic-gate 5657c97ad5cdSakolb if ((pset_res = zonecfg_lookup_pset(handle, &psettab)) == Z_OK && 5658c97ad5cdSakolb has_cpu_shares) { 56590209230bSgjelinek zerr(gettext("%s zone.cpu-shares and %s are incompatible."), 56600209230bSgjelinek rt_to_str(RT_RCTL), rt_to_str(RT_DCPU)); 5661bbec428eSgjelinek saw_error = B_TRUE; 56620209230bSgjelinek if (ret_val == Z_OK) 56630209230bSgjelinek ret_val = Z_INCOMPATIBLE; 56640209230bSgjelinek } 56650209230bSgjelinek 56660209230bSgjelinek if (has_cpu_shares && zonecfg_get_sched_class(handle, sched, 56670209230bSgjelinek sizeof (sched)) == Z_OK && strlen(sched) > 0 && 56680209230bSgjelinek strcmp(sched, "FSS") != 0) { 56690209230bSgjelinek zerr(gettext("WARNING: %s zone.cpu-shares and %s=%s are " 56700209230bSgjelinek "incompatible"), 56710209230bSgjelinek rt_to_str(RT_RCTL), rt_to_str(RT_SCHED), sched); 5672bbec428eSgjelinek saw_error = B_TRUE; 56730209230bSgjelinek if (ret_val == Z_OK) 56740209230bSgjelinek ret_val = Z_INCOMPATIBLE; 56750209230bSgjelinek } 56760209230bSgjelinek 5677c97ad5cdSakolb if (pset_res == Z_OK && has_cpu_cap) { 5678c97ad5cdSakolb zerr(gettext("%s zone.cpu-cap and the %s are incompatible."), 5679c97ad5cdSakolb rt_to_str(RT_RCTL), rt_to_str(RT_DCPU)); 5680bbec428eSgjelinek saw_error = B_TRUE; 5681c97ad5cdSakolb if (ret_val == Z_OK) 5682c97ad5cdSakolb ret_val = Z_INCOMPATIBLE; 5683c97ad5cdSakolb } 5684c97ad5cdSakolb 56857c478bd9Sstevel@tonic-gate if ((err = zonecfg_setattrent(handle)) != Z_OK) { 5686bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 56877c478bd9Sstevel@tonic-gate return; 56887c478bd9Sstevel@tonic-gate } 56897c478bd9Sstevel@tonic-gate while (zonecfg_getattrent(handle, &attrtab) == Z_OK) { 5690087719fdSdp check_reqd_prop(attrtab.zone_attr_name, RT_ATTR, PT_NAME, 5691087719fdSdp &ret_val); 5692087719fdSdp check_reqd_prop(attrtab.zone_attr_type, RT_ATTR, PT_TYPE, 5693087719fdSdp &ret_val); 5694087719fdSdp check_reqd_prop(attrtab.zone_attr_value, RT_ATTR, PT_VALUE, 5695087719fdSdp &ret_val); 56967c478bd9Sstevel@tonic-gate } 56977c478bd9Sstevel@tonic-gate (void) zonecfg_endattrent(handle); 56987c478bd9Sstevel@tonic-gate 5699fa9e4066Sahrens if ((err = zonecfg_setdsent(handle)) != Z_OK) { 5700bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 5701fa9e4066Sahrens return; 5702fa9e4066Sahrens } 5703fa9e4066Sahrens while (zonecfg_getdsent(handle, &dstab) == Z_OK) { 5704fa9e4066Sahrens if (strlen(dstab.zone_dataset_name) == 0) { 5705fa9e4066Sahrens zerr("%s: %s %s", rt_to_str(RT_DATASET), 5706fa9e4066Sahrens pt_to_str(PT_NAME), gettext("not specified")); 5707bbec428eSgjelinek saw_error = B_TRUE; 5708fa9e4066Sahrens if (ret_val == Z_OK) 5709fa9e4066Sahrens ret_val = Z_REQD_PROPERTY_MISSING; 5710fa9e4066Sahrens } else if (!zfs_name_valid(dstab.zone_dataset_name, 5711fa9e4066Sahrens ZFS_TYPE_FILESYSTEM)) { 5712fa9e4066Sahrens zerr("%s: %s %s", rt_to_str(RT_DATASET), 5713fa9e4066Sahrens pt_to_str(PT_NAME), gettext("invalid")); 5714bbec428eSgjelinek saw_error = B_TRUE; 5715fa9e4066Sahrens if (ret_val == Z_OK) 5716fa9e4066Sahrens ret_val = Z_BAD_PROPERTY; 5717fa9e4066Sahrens } 5718fa9e4066Sahrens 5719fa9e4066Sahrens } 5720fa9e4066Sahrens (void) zonecfg_enddsent(handle); 5721fa9e4066Sahrens 57227c478bd9Sstevel@tonic-gate if (!global_scope) { 57237c478bd9Sstevel@tonic-gate zerr(gettext("resource specification incomplete")); 5724bbec428eSgjelinek saw_error = B_TRUE; 57257c478bd9Sstevel@tonic-gate if (ret_val == Z_OK) 57267c478bd9Sstevel@tonic-gate ret_val = Z_INSUFFICIENT_SPEC; 57277c478bd9Sstevel@tonic-gate } 57287c478bd9Sstevel@tonic-gate 57297c478bd9Sstevel@tonic-gate if (save) { 5730087719fdSdp if (ret_val == Z_OK) { 5731087719fdSdp if ((ret_val = zonecfg_save(handle)) == Z_OK) { 5732bbec428eSgjelinek need_to_commit = B_FALSE; 5733087719fdSdp (void) strlcpy(revert_zone, zone, 5734087719fdSdp sizeof (revert_zone)); 5735087719fdSdp } 5736087719fdSdp } else { 5737087719fdSdp zerr(gettext("Zone %s failed to verify"), zone); 5738087719fdSdp } 57397c478bd9Sstevel@tonic-gate } 57407c478bd9Sstevel@tonic-gate if (ret_val != Z_OK) 5741bbec428eSgjelinek zone_perror(zone, ret_val, B_TRUE); 57427c478bd9Sstevel@tonic-gate } 57437c478bd9Sstevel@tonic-gate 57447c478bd9Sstevel@tonic-gate void 57457c478bd9Sstevel@tonic-gate cancel_func(cmd_t *cmd) 57467c478bd9Sstevel@tonic-gate { 57477c478bd9Sstevel@tonic-gate int arg; 5748bbec428eSgjelinek boolean_t arg_err = B_FALSE; 57497c478bd9Sstevel@tonic-gate 57507c478bd9Sstevel@tonic-gate assert(cmd != NULL); 57517c478bd9Sstevel@tonic-gate 57527c478bd9Sstevel@tonic-gate optind = 0; 57537ec75eb8Sgjelinek while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?")) != EOF) { 57547c478bd9Sstevel@tonic-gate switch (arg) { 57557c478bd9Sstevel@tonic-gate case '?': 57567c478bd9Sstevel@tonic-gate longer_usage(CMD_CANCEL); 5757bbec428eSgjelinek arg_err = B_TRUE; 57587ec75eb8Sgjelinek break; 57597c478bd9Sstevel@tonic-gate default: 57607c478bd9Sstevel@tonic-gate short_usage(CMD_CANCEL); 5761bbec428eSgjelinek arg_err = B_TRUE; 57627ec75eb8Sgjelinek break; 57637ec75eb8Sgjelinek } 57647ec75eb8Sgjelinek } 57657ec75eb8Sgjelinek if (arg_err) 57667c478bd9Sstevel@tonic-gate return; 57677ec75eb8Sgjelinek 57687c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 57697c478bd9Sstevel@tonic-gate short_usage(CMD_CANCEL); 57707c478bd9Sstevel@tonic-gate return; 57717c478bd9Sstevel@tonic-gate } 57727c478bd9Sstevel@tonic-gate 57737c478bd9Sstevel@tonic-gate if (global_scope) 57747c478bd9Sstevel@tonic-gate scope_usage(CMD_CANCEL); 5775bbec428eSgjelinek global_scope = B_TRUE; 57767c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(in_progress_fstab.zone_fs_options); 57777c478bd9Sstevel@tonic-gate bzero(&in_progress_fstab, sizeof (in_progress_fstab)); 57787c478bd9Sstevel@tonic-gate bzero(&in_progress_nwiftab, sizeof (in_progress_nwiftab)); 5779fa9e4066Sahrens bzero(&in_progress_ipdtab, sizeof (in_progress_ipdtab)); 57807c478bd9Sstevel@tonic-gate bzero(&in_progress_devtab, sizeof (in_progress_devtab)); 57817c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(in_progress_rctltab.zone_rctl_valptr); 57827c478bd9Sstevel@tonic-gate bzero(&in_progress_rctltab, sizeof (in_progress_rctltab)); 57837c478bd9Sstevel@tonic-gate bzero(&in_progress_attrtab, sizeof (in_progress_attrtab)); 5784fa9e4066Sahrens bzero(&in_progress_dstab, sizeof (in_progress_dstab)); 57857c478bd9Sstevel@tonic-gate } 57867c478bd9Sstevel@tonic-gate 57877c478bd9Sstevel@tonic-gate static int 57887c478bd9Sstevel@tonic-gate validate_attr_name(char *name) 57897c478bd9Sstevel@tonic-gate { 57907c478bd9Sstevel@tonic-gate int i; 57917c478bd9Sstevel@tonic-gate 57927c478bd9Sstevel@tonic-gate if (!isalnum(name[0])) { 57937c478bd9Sstevel@tonic-gate zerr(gettext("Invalid %s %s %s: must start with an alpha-" 57947c478bd9Sstevel@tonic-gate "numeric character."), rt_to_str(RT_ATTR), 57957c478bd9Sstevel@tonic-gate pt_to_str(PT_NAME), name); 57967c478bd9Sstevel@tonic-gate return (Z_INVAL); 57977c478bd9Sstevel@tonic-gate } 57987c478bd9Sstevel@tonic-gate for (i = 1; name[i]; i++) 57997c478bd9Sstevel@tonic-gate if (!isalnum(name[i]) && name[i] != '-' && name[i] != '.') { 58007c478bd9Sstevel@tonic-gate zerr(gettext("Invalid %s %s %s: can only contain " 58017c478bd9Sstevel@tonic-gate "alpha-numeric characters, plus '-' and '.'."), 58027c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_NAME), name); 58037c478bd9Sstevel@tonic-gate return (Z_INVAL); 58047c478bd9Sstevel@tonic-gate } 58057c478bd9Sstevel@tonic-gate return (Z_OK); 58067c478bd9Sstevel@tonic-gate } 58077c478bd9Sstevel@tonic-gate 58087c478bd9Sstevel@tonic-gate static int 58097c478bd9Sstevel@tonic-gate validate_attr_type_val(struct zone_attrtab *attrtab) 58107c478bd9Sstevel@tonic-gate { 58117c478bd9Sstevel@tonic-gate boolean_t boolval; 58127c478bd9Sstevel@tonic-gate int64_t intval; 58137c478bd9Sstevel@tonic-gate char strval[MAXNAMELEN]; 58147c478bd9Sstevel@tonic-gate uint64_t uintval; 58157c478bd9Sstevel@tonic-gate 58167c478bd9Sstevel@tonic-gate if (strcmp(attrtab->zone_attr_type, "boolean") == 0) { 58177c478bd9Sstevel@tonic-gate if (zonecfg_get_attr_boolean(attrtab, &boolval) == Z_OK) 58187c478bd9Sstevel@tonic-gate return (Z_OK); 58197c478bd9Sstevel@tonic-gate zerr(gettext("invalid %s value for %s=%s"), 58207c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_TYPE), "boolean"); 58217c478bd9Sstevel@tonic-gate return (Z_ERR); 58227c478bd9Sstevel@tonic-gate } 58237c478bd9Sstevel@tonic-gate 58247c478bd9Sstevel@tonic-gate if (strcmp(attrtab->zone_attr_type, "int") == 0) { 58257c478bd9Sstevel@tonic-gate if (zonecfg_get_attr_int(attrtab, &intval) == Z_OK) 58267c478bd9Sstevel@tonic-gate return (Z_OK); 58277c478bd9Sstevel@tonic-gate zerr(gettext("invalid %s value for %s=%s"), 58287c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_TYPE), "int"); 58297c478bd9Sstevel@tonic-gate return (Z_ERR); 58307c478bd9Sstevel@tonic-gate } 58317c478bd9Sstevel@tonic-gate 58327c478bd9Sstevel@tonic-gate if (strcmp(attrtab->zone_attr_type, "string") == 0) { 58337c478bd9Sstevel@tonic-gate if (zonecfg_get_attr_string(attrtab, strval, 58347c478bd9Sstevel@tonic-gate sizeof (strval)) == Z_OK) 58357c478bd9Sstevel@tonic-gate return (Z_OK); 58367c478bd9Sstevel@tonic-gate zerr(gettext("invalid %s value for %s=%s"), 58377c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_TYPE), "string"); 58387c478bd9Sstevel@tonic-gate return (Z_ERR); 58397c478bd9Sstevel@tonic-gate } 58407c478bd9Sstevel@tonic-gate 58417c478bd9Sstevel@tonic-gate if (strcmp(attrtab->zone_attr_type, "uint") == 0) { 58427c478bd9Sstevel@tonic-gate if (zonecfg_get_attr_uint(attrtab, &uintval) == Z_OK) 58437c478bd9Sstevel@tonic-gate return (Z_OK); 58447c478bd9Sstevel@tonic-gate zerr(gettext("invalid %s value for %s=%s"), 58457c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_TYPE), "uint"); 58467c478bd9Sstevel@tonic-gate return (Z_ERR); 58477c478bd9Sstevel@tonic-gate } 58487c478bd9Sstevel@tonic-gate 58497c478bd9Sstevel@tonic-gate zerr(gettext("invalid %s %s '%s'"), rt_to_str(RT_ATTR), 58507c478bd9Sstevel@tonic-gate pt_to_str(PT_TYPE), attrtab->zone_attr_type); 58517c478bd9Sstevel@tonic-gate return (Z_ERR); 58527c478bd9Sstevel@tonic-gate } 58537c478bd9Sstevel@tonic-gate 5854087719fdSdp /* 5855087719fdSdp * Helper function for end_func-- checks the existence of a given property 5856087719fdSdp * and emits a message if not specified. 5857087719fdSdp */ 5858087719fdSdp static int 5859bbec428eSgjelinek end_check_reqd(char *attr, int pt, boolean_t *validation_failed) 5860087719fdSdp { 5861087719fdSdp if (strlen(attr) == 0) { 5862bbec428eSgjelinek *validation_failed = B_TRUE; 5863087719fdSdp zerr(gettext("%s not specified"), pt_to_str(pt)); 5864087719fdSdp return (Z_ERR); 5865087719fdSdp } 5866087719fdSdp return (Z_OK); 5867087719fdSdp } 5868087719fdSdp 58697c478bd9Sstevel@tonic-gate void 58707c478bd9Sstevel@tonic-gate end_func(cmd_t *cmd) 58717c478bd9Sstevel@tonic-gate { 5872bbec428eSgjelinek boolean_t validation_failed = B_FALSE; 5873bbec428eSgjelinek boolean_t arg_err = B_FALSE; 58747c478bd9Sstevel@tonic-gate struct zone_fstab tmp_fstab; 58757c478bd9Sstevel@tonic-gate struct zone_nwiftab tmp_nwiftab; 58767c478bd9Sstevel@tonic-gate struct zone_devtab tmp_devtab; 58777c478bd9Sstevel@tonic-gate struct zone_rctltab tmp_rctltab; 58787c478bd9Sstevel@tonic-gate struct zone_attrtab tmp_attrtab; 5879fa9e4066Sahrens struct zone_dstab tmp_dstab; 58800209230bSgjelinek int err, arg, res1, res2, res3; 58810209230bSgjelinek uint64_t swap_limit; 58820209230bSgjelinek uint64_t locked_limit; 5883c97ad5cdSakolb uint64_t proc_cap; 58847c478bd9Sstevel@tonic-gate 58857c478bd9Sstevel@tonic-gate assert(cmd != NULL); 58867c478bd9Sstevel@tonic-gate 58877c478bd9Sstevel@tonic-gate optind = 0; 58887ec75eb8Sgjelinek while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?")) != EOF) { 58897c478bd9Sstevel@tonic-gate switch (arg) { 58907c478bd9Sstevel@tonic-gate case '?': 58917c478bd9Sstevel@tonic-gate longer_usage(CMD_END); 5892bbec428eSgjelinek arg_err = B_TRUE; 58937ec75eb8Sgjelinek break; 58947c478bd9Sstevel@tonic-gate default: 58957c478bd9Sstevel@tonic-gate short_usage(CMD_END); 5896bbec428eSgjelinek arg_err = B_TRUE; 58977ec75eb8Sgjelinek break; 58987ec75eb8Sgjelinek } 58997ec75eb8Sgjelinek } 59007ec75eb8Sgjelinek if (arg_err) 59017c478bd9Sstevel@tonic-gate return; 59027ec75eb8Sgjelinek 59037c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 59047c478bd9Sstevel@tonic-gate short_usage(CMD_END); 59057c478bd9Sstevel@tonic-gate return; 59067c478bd9Sstevel@tonic-gate } 59077c478bd9Sstevel@tonic-gate 59087c478bd9Sstevel@tonic-gate if (global_scope) { 59097c478bd9Sstevel@tonic-gate scope_usage(CMD_END); 59107c478bd9Sstevel@tonic-gate return; 59117c478bd9Sstevel@tonic-gate } 59127c478bd9Sstevel@tonic-gate 59137c478bd9Sstevel@tonic-gate assert(end_op == CMD_ADD || end_op == CMD_SELECT); 59147c478bd9Sstevel@tonic-gate 59157c478bd9Sstevel@tonic-gate switch (resource_scope) { 59167c478bd9Sstevel@tonic-gate case RT_FS: 59177c478bd9Sstevel@tonic-gate /* First make sure everything was filled in. */ 5918087719fdSdp if (end_check_reqd(in_progress_fstab.zone_fs_dir, 5919087719fdSdp PT_DIR, &validation_failed) == Z_OK) { 5920087719fdSdp if (in_progress_fstab.zone_fs_dir[0] != '/') { 5921087719fdSdp zerr(gettext("%s %s is not an absolute path."), 5922087719fdSdp pt_to_str(PT_DIR), 5923087719fdSdp in_progress_fstab.zone_fs_dir); 5924bbec428eSgjelinek validation_failed = B_TRUE; 59257c478bd9Sstevel@tonic-gate } 59267c478bd9Sstevel@tonic-gate } 5927087719fdSdp 5928087719fdSdp (void) end_check_reqd(in_progress_fstab.zone_fs_special, 5929087719fdSdp PT_SPECIAL, &validation_failed); 5930087719fdSdp 59317c478bd9Sstevel@tonic-gate if (in_progress_fstab.zone_fs_raw[0] != '\0' && 59327c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_raw[0] != '/') { 5933087719fdSdp zerr(gettext("%s %s is not an absolute path."), 5934087719fdSdp pt_to_str(PT_RAW), 5935087719fdSdp in_progress_fstab.zone_fs_raw); 5936bbec428eSgjelinek validation_failed = B_TRUE; 59377c478bd9Sstevel@tonic-gate } 5938087719fdSdp 5939087719fdSdp (void) end_check_reqd(in_progress_fstab.zone_fs_type, PT_TYPE, 5940087719fdSdp &validation_failed); 5941087719fdSdp 5942087719fdSdp if (validation_failed) { 5943bbec428eSgjelinek saw_error = B_TRUE; 59447c478bd9Sstevel@tonic-gate return; 5945087719fdSdp } 5946087719fdSdp 59477c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) { 59487c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */ 59497c478bd9Sstevel@tonic-gate bzero(&tmp_fstab, sizeof (tmp_fstab)); 59507c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_fstab.zone_fs_dir, 59517c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_dir, 59527c478bd9Sstevel@tonic-gate sizeof (tmp_fstab.zone_fs_dir)); 59537c478bd9Sstevel@tonic-gate err = zonecfg_lookup_filesystem(handle, &tmp_fstab); 59547c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(tmp_fstab.zone_fs_options); 59557c478bd9Sstevel@tonic-gate if (err == Z_OK) { 59567c478bd9Sstevel@tonic-gate zerr(gettext("A %s resource " 59577c478bd9Sstevel@tonic-gate "with the %s '%s' already exists."), 59587c478bd9Sstevel@tonic-gate rt_to_str(RT_FS), pt_to_str(PT_DIR), 59597c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_dir); 5960bbec428eSgjelinek saw_error = B_TRUE; 59617c478bd9Sstevel@tonic-gate return; 59627c478bd9Sstevel@tonic-gate } 59637c478bd9Sstevel@tonic-gate err = zonecfg_add_filesystem(handle, 59647c478bd9Sstevel@tonic-gate &in_progress_fstab); 59657c478bd9Sstevel@tonic-gate } else { 59667c478bd9Sstevel@tonic-gate err = zonecfg_modify_filesystem(handle, &old_fstab, 59677c478bd9Sstevel@tonic-gate &in_progress_fstab); 59687c478bd9Sstevel@tonic-gate } 59697c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(in_progress_fstab.zone_fs_options); 59707c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_options = NULL; 59717c478bd9Sstevel@tonic-gate break; 5972087719fdSdp 59737c478bd9Sstevel@tonic-gate case RT_IPD: 59747c478bd9Sstevel@tonic-gate /* First make sure everything was filled in. */ 5975087719fdSdp if (end_check_reqd(in_progress_ipdtab.zone_fs_dir, PT_DIR, 5976087719fdSdp &validation_failed) == Z_OK) { 5977087719fdSdp if (in_progress_ipdtab.zone_fs_dir[0] != '/') { 5978087719fdSdp zerr(gettext("%s %s is not an absolute path."), 5979087719fdSdp pt_to_str(PT_DIR), 5980087719fdSdp in_progress_ipdtab.zone_fs_dir); 5981bbec428eSgjelinek validation_failed = B_TRUE; 59827c478bd9Sstevel@tonic-gate } 5983087719fdSdp } 5984087719fdSdp if (validation_failed) { 5985bbec428eSgjelinek saw_error = B_TRUE; 59867c478bd9Sstevel@tonic-gate return; 5987087719fdSdp } 5988087719fdSdp 59897c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) { 59907c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */ 59917c478bd9Sstevel@tonic-gate bzero(&tmp_fstab, sizeof (tmp_fstab)); 59927c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_fstab.zone_fs_dir, 59937c478bd9Sstevel@tonic-gate in_progress_ipdtab.zone_fs_dir, 59947c478bd9Sstevel@tonic-gate sizeof (tmp_fstab.zone_fs_dir)); 59957c478bd9Sstevel@tonic-gate err = zonecfg_lookup_ipd(handle, &tmp_fstab); 59967c478bd9Sstevel@tonic-gate if (err == Z_OK) { 59977c478bd9Sstevel@tonic-gate zerr(gettext("An %s resource " 59987c478bd9Sstevel@tonic-gate "with the %s '%s' already exists."), 59997c478bd9Sstevel@tonic-gate rt_to_str(RT_IPD), pt_to_str(PT_DIR), 60007c478bd9Sstevel@tonic-gate in_progress_ipdtab.zone_fs_dir); 6001bbec428eSgjelinek saw_error = B_TRUE; 60027c478bd9Sstevel@tonic-gate return; 60037c478bd9Sstevel@tonic-gate } 60047c478bd9Sstevel@tonic-gate err = zonecfg_add_ipd(handle, &in_progress_ipdtab); 60057c478bd9Sstevel@tonic-gate } else { 60067c478bd9Sstevel@tonic-gate err = zonecfg_modify_ipd(handle, &old_ipdtab, 60077c478bd9Sstevel@tonic-gate &in_progress_ipdtab); 60087c478bd9Sstevel@tonic-gate } 60097c478bd9Sstevel@tonic-gate break; 60107c478bd9Sstevel@tonic-gate case RT_NET: 6011f4b3ec61Sdh155122 /* 6012f4b3ec61Sdh155122 * First make sure everything was filled in. 6013f4b3ec61Sdh155122 * Since we don't know whether IP will be shared 6014f4b3ec61Sdh155122 * or exclusive here, some checks are deferred until 6015f4b3ec61Sdh155122 * the verify command. 6016f4b3ec61Sdh155122 */ 6017087719fdSdp (void) end_check_reqd(in_progress_nwiftab.zone_nwif_physical, 6018087719fdSdp PT_PHYSICAL, &validation_failed); 6019087719fdSdp 6020087719fdSdp if (validation_failed) { 6021bbec428eSgjelinek saw_error = B_TRUE; 60227c478bd9Sstevel@tonic-gate return; 6023087719fdSdp } 60247c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) { 60257c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */ 60267c478bd9Sstevel@tonic-gate bzero(&tmp_nwiftab, sizeof (tmp_nwiftab)); 6027f4b3ec61Sdh155122 (void) strlcpy(tmp_nwiftab.zone_nwif_physical, 6028f4b3ec61Sdh155122 in_progress_nwiftab.zone_nwif_physical, 6029f4b3ec61Sdh155122 sizeof (tmp_nwiftab.zone_nwif_physical)); 60307c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_nwiftab.zone_nwif_address, 60317c478bd9Sstevel@tonic-gate in_progress_nwiftab.zone_nwif_address, 60327c478bd9Sstevel@tonic-gate sizeof (tmp_nwiftab.zone_nwif_address)); 60337c478bd9Sstevel@tonic-gate if (zonecfg_lookup_nwif(handle, &tmp_nwiftab) == Z_OK) { 6034f4b3ec61Sdh155122 zerr(gettext("A %s resource with the %s '%s', " 6035f4b3ec61Sdh155122 "and %s '%s' already exists."), 6036f4b3ec61Sdh155122 rt_to_str(RT_NET), 6037f4b3ec61Sdh155122 pt_to_str(PT_PHYSICAL), 6038f4b3ec61Sdh155122 in_progress_nwiftab.zone_nwif_physical, 6039f4b3ec61Sdh155122 pt_to_str(PT_ADDRESS), 60407c478bd9Sstevel@tonic-gate in_progress_nwiftab.zone_nwif_address); 6041bbec428eSgjelinek saw_error = B_TRUE; 60427c478bd9Sstevel@tonic-gate return; 60437c478bd9Sstevel@tonic-gate } 60447c478bd9Sstevel@tonic-gate err = zonecfg_add_nwif(handle, &in_progress_nwiftab); 60457c478bd9Sstevel@tonic-gate } else { 60467c478bd9Sstevel@tonic-gate err = zonecfg_modify_nwif(handle, &old_nwiftab, 60477c478bd9Sstevel@tonic-gate &in_progress_nwiftab); 60487c478bd9Sstevel@tonic-gate } 60497c478bd9Sstevel@tonic-gate break; 6050087719fdSdp 60517c478bd9Sstevel@tonic-gate case RT_DEVICE: 60527c478bd9Sstevel@tonic-gate /* First make sure everything was filled in. */ 6053087719fdSdp (void) end_check_reqd(in_progress_devtab.zone_dev_match, 6054087719fdSdp PT_MATCH, &validation_failed); 6055087719fdSdp 6056087719fdSdp if (validation_failed) { 6057bbec428eSgjelinek saw_error = B_TRUE; 60587c478bd9Sstevel@tonic-gate return; 6059087719fdSdp } 6060087719fdSdp 60617c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) { 60627c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */ 60637c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_devtab.zone_dev_match, 60647c478bd9Sstevel@tonic-gate in_progress_devtab.zone_dev_match, 60657c478bd9Sstevel@tonic-gate sizeof (tmp_devtab.zone_dev_match)); 60667c478bd9Sstevel@tonic-gate if (zonecfg_lookup_dev(handle, &tmp_devtab) == Z_OK) { 60677c478bd9Sstevel@tonic-gate zerr(gettext("A %s resource with the %s '%s' " 60687c478bd9Sstevel@tonic-gate "already exists."), rt_to_str(RT_DEVICE), 60697c478bd9Sstevel@tonic-gate pt_to_str(PT_MATCH), 60707c478bd9Sstevel@tonic-gate in_progress_devtab.zone_dev_match); 6071bbec428eSgjelinek saw_error = B_TRUE; 60727c478bd9Sstevel@tonic-gate return; 60737c478bd9Sstevel@tonic-gate } 60747c478bd9Sstevel@tonic-gate err = zonecfg_add_dev(handle, &in_progress_devtab); 60757c478bd9Sstevel@tonic-gate } else { 60767c478bd9Sstevel@tonic-gate err = zonecfg_modify_dev(handle, &old_devtab, 60777c478bd9Sstevel@tonic-gate &in_progress_devtab); 60787c478bd9Sstevel@tonic-gate } 60797c478bd9Sstevel@tonic-gate break; 6080087719fdSdp 60817c478bd9Sstevel@tonic-gate case RT_RCTL: 60827c478bd9Sstevel@tonic-gate /* First make sure everything was filled in. */ 6083087719fdSdp (void) end_check_reqd(in_progress_rctltab.zone_rctl_name, 6084087719fdSdp PT_NAME, &validation_failed); 6085087719fdSdp 60867c478bd9Sstevel@tonic-gate if (in_progress_rctltab.zone_rctl_valptr == NULL) { 60877c478bd9Sstevel@tonic-gate zerr(gettext("no %s specified"), pt_to_str(PT_VALUE)); 6088bbec428eSgjelinek validation_failed = B_TRUE; 60897c478bd9Sstevel@tonic-gate } 6090087719fdSdp 6091087719fdSdp if (validation_failed) { 6092bbec428eSgjelinek saw_error = B_TRUE; 60937c478bd9Sstevel@tonic-gate return; 6094087719fdSdp } 6095087719fdSdp 60967c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) { 60977c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */ 60987c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_rctltab.zone_rctl_name, 60997c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_name, 61007c478bd9Sstevel@tonic-gate sizeof (tmp_rctltab.zone_rctl_name)); 61017c478bd9Sstevel@tonic-gate tmp_rctltab.zone_rctl_valptr = NULL; 61027c478bd9Sstevel@tonic-gate err = zonecfg_lookup_rctl(handle, &tmp_rctltab); 61037c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list( 61047c478bd9Sstevel@tonic-gate tmp_rctltab.zone_rctl_valptr); 61057c478bd9Sstevel@tonic-gate if (err == Z_OK) { 61067c478bd9Sstevel@tonic-gate zerr(gettext("A %s resource " 61077c478bd9Sstevel@tonic-gate "with the %s '%s' already exists."), 61087c478bd9Sstevel@tonic-gate rt_to_str(RT_RCTL), pt_to_str(PT_NAME), 61097c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_name); 6110bbec428eSgjelinek saw_error = B_TRUE; 61117c478bd9Sstevel@tonic-gate return; 61127c478bd9Sstevel@tonic-gate } 61137c478bd9Sstevel@tonic-gate err = zonecfg_add_rctl(handle, &in_progress_rctltab); 61147c478bd9Sstevel@tonic-gate } else { 61157c478bd9Sstevel@tonic-gate err = zonecfg_modify_rctl(handle, &old_rctltab, 61167c478bd9Sstevel@tonic-gate &in_progress_rctltab); 61177c478bd9Sstevel@tonic-gate } 61187c478bd9Sstevel@tonic-gate if (err == Z_OK) { 61197c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list( 61207c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_valptr); 61217c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_valptr = NULL; 61227c478bd9Sstevel@tonic-gate } 61237c478bd9Sstevel@tonic-gate break; 6124087719fdSdp 61257c478bd9Sstevel@tonic-gate case RT_ATTR: 61267c478bd9Sstevel@tonic-gate /* First make sure everything was filled in. */ 6127087719fdSdp (void) end_check_reqd(in_progress_attrtab.zone_attr_name, 6128087719fdSdp PT_NAME, &validation_failed); 6129087719fdSdp (void) end_check_reqd(in_progress_attrtab.zone_attr_type, 6130087719fdSdp PT_TYPE, &validation_failed); 6131087719fdSdp (void) end_check_reqd(in_progress_attrtab.zone_attr_value, 6132087719fdSdp PT_VALUE, &validation_failed); 6133087719fdSdp 61347c478bd9Sstevel@tonic-gate if (validate_attr_name(in_progress_attrtab.zone_attr_name) != 6135087719fdSdp Z_OK) 6136bbec428eSgjelinek validation_failed = B_TRUE; 6137087719fdSdp 6138087719fdSdp if (validate_attr_type_val(&in_progress_attrtab) != Z_OK) 6139bbec428eSgjelinek validation_failed = B_TRUE; 6140087719fdSdp 6141087719fdSdp if (validation_failed) { 6142bbec428eSgjelinek saw_error = B_TRUE; 61437c478bd9Sstevel@tonic-gate return; 6144087719fdSdp } 61457c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) { 61467c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */ 61477c478bd9Sstevel@tonic-gate bzero(&tmp_attrtab, sizeof (tmp_attrtab)); 61487c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_attrtab.zone_attr_name, 61497c478bd9Sstevel@tonic-gate in_progress_attrtab.zone_attr_name, 61507c478bd9Sstevel@tonic-gate sizeof (tmp_attrtab.zone_attr_name)); 61517c478bd9Sstevel@tonic-gate if (zonecfg_lookup_attr(handle, &tmp_attrtab) == Z_OK) { 61527c478bd9Sstevel@tonic-gate zerr(gettext("An %s resource " 61537c478bd9Sstevel@tonic-gate "with the %s '%s' already exists."), 61547c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_NAME), 61557c478bd9Sstevel@tonic-gate in_progress_attrtab.zone_attr_name); 6156bbec428eSgjelinek saw_error = B_TRUE; 61577c478bd9Sstevel@tonic-gate return; 61587c478bd9Sstevel@tonic-gate } 61597c478bd9Sstevel@tonic-gate err = zonecfg_add_attr(handle, &in_progress_attrtab); 61607c478bd9Sstevel@tonic-gate } else { 61617c478bd9Sstevel@tonic-gate err = zonecfg_modify_attr(handle, &old_attrtab, 61627c478bd9Sstevel@tonic-gate &in_progress_attrtab); 61637c478bd9Sstevel@tonic-gate } 61647c478bd9Sstevel@tonic-gate break; 6165fa9e4066Sahrens case RT_DATASET: 6166fa9e4066Sahrens /* First make sure everything was filled in. */ 6167fa9e4066Sahrens if (strlen(in_progress_dstab.zone_dataset_name) == 0) { 6168fa9e4066Sahrens zerr("%s %s", pt_to_str(PT_NAME), 6169fa9e4066Sahrens gettext("not specified")); 6170bbec428eSgjelinek saw_error = B_TRUE; 6171bbec428eSgjelinek validation_failed = B_TRUE; 6172fa9e4066Sahrens } 6173fa9e4066Sahrens if (validation_failed) 6174fa9e4066Sahrens return; 6175fa9e4066Sahrens if (end_op == CMD_ADD) { 6176fa9e4066Sahrens /* Make sure there isn't already one like this. */ 6177fa9e4066Sahrens bzero(&tmp_dstab, sizeof (tmp_dstab)); 6178fa9e4066Sahrens (void) strlcpy(tmp_dstab.zone_dataset_name, 6179fa9e4066Sahrens in_progress_dstab.zone_dataset_name, 6180fa9e4066Sahrens sizeof (tmp_dstab.zone_dataset_name)); 6181fa9e4066Sahrens err = zonecfg_lookup_ds(handle, &tmp_dstab); 6182fa9e4066Sahrens if (err == Z_OK) { 6183fa9e4066Sahrens zerr(gettext("A %s resource " 6184fa9e4066Sahrens "with the %s '%s' already exists."), 6185fa9e4066Sahrens rt_to_str(RT_DATASET), pt_to_str(PT_NAME), 6186fa9e4066Sahrens in_progress_dstab.zone_dataset_name); 6187bbec428eSgjelinek saw_error = B_TRUE; 6188fa9e4066Sahrens return; 6189fa9e4066Sahrens } 6190fa9e4066Sahrens err = zonecfg_add_ds(handle, &in_progress_dstab); 6191fa9e4066Sahrens } else { 6192fa9e4066Sahrens err = zonecfg_modify_ds(handle, &old_dstab, 6193fa9e4066Sahrens &in_progress_dstab); 6194fa9e4066Sahrens } 6195fa9e4066Sahrens break; 61960209230bSgjelinek case RT_DCPU: 61970209230bSgjelinek /* Make sure everything was filled in. */ 61980209230bSgjelinek if (end_check_reqd(in_progress_psettab.zone_ncpu_min, 61990209230bSgjelinek PT_NCPUS, &validation_failed) != Z_OK) { 6200bbec428eSgjelinek saw_error = B_TRUE; 62010209230bSgjelinek return; 62020209230bSgjelinek } 62030209230bSgjelinek 62040209230bSgjelinek if (end_op == CMD_ADD) { 62050209230bSgjelinek err = zonecfg_add_pset(handle, &in_progress_psettab); 62060209230bSgjelinek } else { 62070209230bSgjelinek err = zonecfg_modify_pset(handle, &in_progress_psettab); 62080209230bSgjelinek } 62090209230bSgjelinek break; 6210c97ad5cdSakolb case RT_PCAP: 6211c97ad5cdSakolb /* Make sure everything was filled in. */ 6212c97ad5cdSakolb if (zonecfg_get_aliased_rctl(handle, ALIAS_CPUCAP, &proc_cap) 6213c97ad5cdSakolb != Z_OK) { 6214c97ad5cdSakolb zerr(gettext("%s not specified"), pt_to_str(PT_NCPUS)); 6215bbec428eSgjelinek saw_error = B_TRUE; 6216bbec428eSgjelinek validation_failed = B_TRUE; 6217c97ad5cdSakolb return; 6218c97ad5cdSakolb } 6219c97ad5cdSakolb err = Z_OK; 6220c97ad5cdSakolb break; 62210209230bSgjelinek case RT_MCAP: 62220209230bSgjelinek /* Make sure everything was filled in. */ 62230209230bSgjelinek res1 = strlen(in_progress_mcaptab.zone_physmem_cap) == 0 ? 62240209230bSgjelinek Z_ERR : Z_OK; 62250209230bSgjelinek res2 = zonecfg_get_aliased_rctl(handle, ALIAS_MAXSWAP, 62260209230bSgjelinek &swap_limit); 62270209230bSgjelinek res3 = zonecfg_get_aliased_rctl(handle, ALIAS_MAXLOCKEDMEM, 62280209230bSgjelinek &locked_limit); 62290209230bSgjelinek 62300209230bSgjelinek if (res1 != Z_OK && res2 != Z_OK && res3 != Z_OK) { 62310209230bSgjelinek zerr(gettext("No property was specified. One of %s, " 62320209230bSgjelinek "%s or %s is required."), pt_to_str(PT_PHYSICAL), 62330209230bSgjelinek pt_to_str(PT_SWAP), pt_to_str(PT_LOCKED)); 6234bbec428eSgjelinek saw_error = B_TRUE; 62350209230bSgjelinek return; 62360209230bSgjelinek } 62370209230bSgjelinek 62380209230bSgjelinek /* if phys & locked are both set, verify locked <= phys */ 62390209230bSgjelinek if (res1 == Z_OK && res3 == Z_OK) { 62400209230bSgjelinek uint64_t phys_limit; 62410209230bSgjelinek char *endp; 62420209230bSgjelinek 62430209230bSgjelinek phys_limit = strtoull( 62440209230bSgjelinek in_progress_mcaptab.zone_physmem_cap, &endp, 10); 62450209230bSgjelinek if (phys_limit < locked_limit) { 62460209230bSgjelinek zerr(gettext("The %s cap must be less than or " 62470209230bSgjelinek "equal to the %s cap."), 62480209230bSgjelinek pt_to_str(PT_LOCKED), 62490209230bSgjelinek pt_to_str(PT_PHYSICAL)); 6250bbec428eSgjelinek saw_error = B_TRUE; 62510209230bSgjelinek return; 62520209230bSgjelinek } 62530209230bSgjelinek } 62540209230bSgjelinek 62550209230bSgjelinek err = Z_OK; 62560209230bSgjelinek if (res1 == Z_OK) { 62570209230bSgjelinek /* 62580209230bSgjelinek * We could be ending from either an add operation 62590209230bSgjelinek * or a select operation. Since all of the properties 62600209230bSgjelinek * within this resource are optional, we always use 62610209230bSgjelinek * modify on the mcap entry. zonecfg_modify_mcap() 62620209230bSgjelinek * will handle both adding and modifying a memory cap. 62630209230bSgjelinek */ 62640209230bSgjelinek err = zonecfg_modify_mcap(handle, &in_progress_mcaptab); 62650209230bSgjelinek } else if (end_op == CMD_SELECT) { 62660209230bSgjelinek /* 62670209230bSgjelinek * If we're ending from a select and the physical 62680209230bSgjelinek * memory cap is empty then the user could have cleared 62690209230bSgjelinek * the physical cap value, so try to delete the entry. 62700209230bSgjelinek */ 62710209230bSgjelinek (void) zonecfg_delete_mcap(handle); 62720209230bSgjelinek } 62730209230bSgjelinek break; 62747c478bd9Sstevel@tonic-gate default: 62757c478bd9Sstevel@tonic-gate zone_perror(rt_to_str(resource_scope), Z_NO_RESOURCE_TYPE, 6276bbec428eSgjelinek B_TRUE); 6277bbec428eSgjelinek saw_error = B_TRUE; 62787c478bd9Sstevel@tonic-gate return; 62797c478bd9Sstevel@tonic-gate } 62807c478bd9Sstevel@tonic-gate 62817c478bd9Sstevel@tonic-gate if (err != Z_OK) { 6282bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 62837c478bd9Sstevel@tonic-gate } else { 6284bbec428eSgjelinek need_to_commit = B_TRUE; 6285bbec428eSgjelinek global_scope = B_TRUE; 62867c478bd9Sstevel@tonic-gate end_op = -1; 62877c478bd9Sstevel@tonic-gate } 62887c478bd9Sstevel@tonic-gate } 62897c478bd9Sstevel@tonic-gate 62907c478bd9Sstevel@tonic-gate void 62917c478bd9Sstevel@tonic-gate commit_func(cmd_t *cmd) 62927c478bd9Sstevel@tonic-gate { 62937c478bd9Sstevel@tonic-gate int arg; 6294bbec428eSgjelinek boolean_t arg_err = B_FALSE; 62957c478bd9Sstevel@tonic-gate 62967c478bd9Sstevel@tonic-gate optind = 0; 62977ec75eb8Sgjelinek while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?")) != EOF) { 62987c478bd9Sstevel@tonic-gate switch (arg) { 62997c478bd9Sstevel@tonic-gate case '?': 63007c478bd9Sstevel@tonic-gate longer_usage(CMD_COMMIT); 6301bbec428eSgjelinek arg_err = B_TRUE; 63027ec75eb8Sgjelinek break; 63037c478bd9Sstevel@tonic-gate default: 63047c478bd9Sstevel@tonic-gate short_usage(CMD_COMMIT); 6305bbec428eSgjelinek arg_err = B_TRUE; 63067ec75eb8Sgjelinek break; 63077ec75eb8Sgjelinek } 63087ec75eb8Sgjelinek } 63097ec75eb8Sgjelinek if (arg_err) 63107c478bd9Sstevel@tonic-gate return; 63117ec75eb8Sgjelinek 63127c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 63137c478bd9Sstevel@tonic-gate short_usage(CMD_COMMIT); 63147c478bd9Sstevel@tonic-gate return; 63157c478bd9Sstevel@tonic-gate } 63167c478bd9Sstevel@tonic-gate 63177c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_COMMIT)) 63187c478bd9Sstevel@tonic-gate return; 63197c478bd9Sstevel@tonic-gate 63207c478bd9Sstevel@tonic-gate assert(cmd != NULL); 63217c478bd9Sstevel@tonic-gate 63227c478bd9Sstevel@tonic-gate cmd->cmd_argc = 1; 63237c478bd9Sstevel@tonic-gate /* 63247c478bd9Sstevel@tonic-gate * cmd_arg normally comes from a strdup() in the lexer, and the 63257c478bd9Sstevel@tonic-gate * whole cmd structure and its (char *) attributes are freed at 63267c478bd9Sstevel@tonic-gate * the completion of each command, so the strdup() below is needed 63277c478bd9Sstevel@tonic-gate * to match this and prevent a core dump from trying to free() 63287c478bd9Sstevel@tonic-gate * something that can't be. 63297c478bd9Sstevel@tonic-gate */ 63307c478bd9Sstevel@tonic-gate if ((cmd->cmd_argv[0] = strdup("save")) == NULL) { 6331bbec428eSgjelinek zone_perror(zone, Z_NOMEM, B_TRUE); 63327c478bd9Sstevel@tonic-gate exit(Z_ERR); 63337c478bd9Sstevel@tonic-gate } 63347c478bd9Sstevel@tonic-gate cmd->cmd_argv[1] = NULL; 63357c478bd9Sstevel@tonic-gate verify_func(cmd); 63367c478bd9Sstevel@tonic-gate } 63377c478bd9Sstevel@tonic-gate 63387c478bd9Sstevel@tonic-gate void 63397c478bd9Sstevel@tonic-gate revert_func(cmd_t *cmd) 63407c478bd9Sstevel@tonic-gate { 63417c478bd9Sstevel@tonic-gate char line[128]; /* enough to ask a question */ 6342bbec428eSgjelinek boolean_t force = B_FALSE; 6343bbec428eSgjelinek boolean_t arg_err = B_FALSE; 63447c478bd9Sstevel@tonic-gate int err, arg, answer; 63457c478bd9Sstevel@tonic-gate 63467c478bd9Sstevel@tonic-gate optind = 0; 63477c478bd9Sstevel@tonic-gate while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?F")) != EOF) { 63487c478bd9Sstevel@tonic-gate switch (arg) { 63497c478bd9Sstevel@tonic-gate case '?': 63507c478bd9Sstevel@tonic-gate longer_usage(CMD_REVERT); 6351bbec428eSgjelinek arg_err = B_TRUE; 63527ec75eb8Sgjelinek break; 63537c478bd9Sstevel@tonic-gate case 'F': 6354bbec428eSgjelinek force = B_TRUE; 63557c478bd9Sstevel@tonic-gate break; 63567c478bd9Sstevel@tonic-gate default: 63577c478bd9Sstevel@tonic-gate short_usage(CMD_REVERT); 6358bbec428eSgjelinek arg_err = B_TRUE; 63597ec75eb8Sgjelinek break; 63607ec75eb8Sgjelinek } 63617ec75eb8Sgjelinek } 63627ec75eb8Sgjelinek if (arg_err) 63637c478bd9Sstevel@tonic-gate return; 63647ec75eb8Sgjelinek 63657c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 63667c478bd9Sstevel@tonic-gate short_usage(CMD_REVERT); 63677c478bd9Sstevel@tonic-gate return; 63687c478bd9Sstevel@tonic-gate } 63697c478bd9Sstevel@tonic-gate 63707c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_REVERT)) 63717c478bd9Sstevel@tonic-gate return; 63727c478bd9Sstevel@tonic-gate 63735b418297Sjv227347 if (!global_scope) { 63745b418297Sjv227347 zerr(gettext("You can only use %s in the global scope.\nUse" 63755b418297Sjv227347 " '%s' to cancel changes to a resource specification."), 63765b418297Sjv227347 cmd_to_str(CMD_REVERT), cmd_to_str(CMD_CANCEL)); 63775b418297Sjv227347 saw_error = B_TRUE; 63785b418297Sjv227347 return; 63795b418297Sjv227347 } 63805b418297Sjv227347 63817c478bd9Sstevel@tonic-gate if (zonecfg_check_handle(handle) != Z_OK) { 63827c478bd9Sstevel@tonic-gate zerr(gettext("No changes to revert.")); 6383bbec428eSgjelinek saw_error = B_TRUE; 63847c478bd9Sstevel@tonic-gate return; 63857c478bd9Sstevel@tonic-gate } 63867c478bd9Sstevel@tonic-gate 63877c478bd9Sstevel@tonic-gate if (!force) { 63887c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), 63897c478bd9Sstevel@tonic-gate gettext("Are you sure you want to revert")); 6390bbec428eSgjelinek if ((answer = ask_yesno(B_FALSE, line)) == -1) { 63917c478bd9Sstevel@tonic-gate zerr(gettext("Input not from terminal and -F not " 63927c478bd9Sstevel@tonic-gate "specified:\n%s command ignored, exiting."), 63937c478bd9Sstevel@tonic-gate cmd_to_str(CMD_REVERT)); 63947c478bd9Sstevel@tonic-gate exit(Z_ERR); 63957c478bd9Sstevel@tonic-gate } 63967c478bd9Sstevel@tonic-gate if (answer != 1) 63977c478bd9Sstevel@tonic-gate return; 63987c478bd9Sstevel@tonic-gate } 63997c478bd9Sstevel@tonic-gate 64007c478bd9Sstevel@tonic-gate /* 64017c478bd9Sstevel@tonic-gate * Time for a new handle: finish the old one off first 64027c478bd9Sstevel@tonic-gate * then get a new one properly to avoid leaks. 64037c478bd9Sstevel@tonic-gate */ 64047c478bd9Sstevel@tonic-gate zonecfg_fini_handle(handle); 64057c478bd9Sstevel@tonic-gate if ((handle = zonecfg_init_handle()) == NULL) { 6406bbec428eSgjelinek zone_perror(execname, Z_NOMEM, B_TRUE); 64077c478bd9Sstevel@tonic-gate exit(Z_ERR); 64087c478bd9Sstevel@tonic-gate } 6409087719fdSdp if ((err = zonecfg_get_handle(revert_zone, handle)) != Z_OK) { 6410bbec428eSgjelinek saw_error = B_TRUE; 6411bbec428eSgjelinek got_handle = B_FALSE; 64127c478bd9Sstevel@tonic-gate if (err == Z_NO_ZONE) 64137c478bd9Sstevel@tonic-gate zerr(gettext("%s: no such saved zone to revert to."), 6414087719fdSdp revert_zone); 64157c478bd9Sstevel@tonic-gate else 6416bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 64177c478bd9Sstevel@tonic-gate } 6418087719fdSdp (void) strlcpy(zone, revert_zone, sizeof (zone)); 64197c478bd9Sstevel@tonic-gate } 64207c478bd9Sstevel@tonic-gate 64217c478bd9Sstevel@tonic-gate void 64227c478bd9Sstevel@tonic-gate help_func(cmd_t *cmd) 64237c478bd9Sstevel@tonic-gate { 64247c478bd9Sstevel@tonic-gate int i; 64257c478bd9Sstevel@tonic-gate 64267c478bd9Sstevel@tonic-gate assert(cmd != NULL); 64277c478bd9Sstevel@tonic-gate 64287c478bd9Sstevel@tonic-gate if (cmd->cmd_argc == 0) { 6429bbec428eSgjelinek usage(B_TRUE, global_scope ? HELP_SUBCMDS : HELP_RES_SCOPE); 64307c478bd9Sstevel@tonic-gate return; 64317c478bd9Sstevel@tonic-gate } 64327c478bd9Sstevel@tonic-gate if (strcmp(cmd->cmd_argv[0], "usage") == 0) { 6433bbec428eSgjelinek usage(B_TRUE, HELP_USAGE); 64347c478bd9Sstevel@tonic-gate return; 64357c478bd9Sstevel@tonic-gate } 64367c478bd9Sstevel@tonic-gate if (strcmp(cmd->cmd_argv[0], "commands") == 0) { 6437bbec428eSgjelinek usage(B_TRUE, HELP_SUBCMDS); 64387c478bd9Sstevel@tonic-gate return; 64397c478bd9Sstevel@tonic-gate } 64407c478bd9Sstevel@tonic-gate if (strcmp(cmd->cmd_argv[0], "syntax") == 0) { 6441bbec428eSgjelinek usage(B_TRUE, HELP_SYNTAX | HELP_RES_PROPS); 64427c478bd9Sstevel@tonic-gate return; 64437c478bd9Sstevel@tonic-gate } 64447c478bd9Sstevel@tonic-gate if (strcmp(cmd->cmd_argv[0], "-?") == 0) { 64457c478bd9Sstevel@tonic-gate longer_usage(CMD_HELP); 64467c478bd9Sstevel@tonic-gate return; 64477c478bd9Sstevel@tonic-gate } 64487c478bd9Sstevel@tonic-gate 64497c478bd9Sstevel@tonic-gate for (i = 0; i <= CMD_MAX; i++) { 64507c478bd9Sstevel@tonic-gate if (strcmp(cmd->cmd_argv[0], cmd_to_str(i)) == 0) { 64517c478bd9Sstevel@tonic-gate longer_usage(i); 64527c478bd9Sstevel@tonic-gate return; 64537c478bd9Sstevel@tonic-gate } 64547c478bd9Sstevel@tonic-gate } 64557c478bd9Sstevel@tonic-gate /* We do not use zerr() here because we do not want its extra \n. */ 64567c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("Unknown help subject %s. "), 64577c478bd9Sstevel@tonic-gate cmd->cmd_argv[0]); 6458bbec428eSgjelinek usage(B_FALSE, HELP_META); 64597c478bd9Sstevel@tonic-gate } 64607c478bd9Sstevel@tonic-gate 64617c478bd9Sstevel@tonic-gate static int 64627c478bd9Sstevel@tonic-gate string_to_yyin(char *string) 64637c478bd9Sstevel@tonic-gate { 64647c478bd9Sstevel@tonic-gate if ((yyin = tmpfile()) == NULL) { 6465bbec428eSgjelinek zone_perror(execname, Z_TEMP_FILE, B_TRUE); 64667c478bd9Sstevel@tonic-gate return (Z_ERR); 64677c478bd9Sstevel@tonic-gate } 64687c478bd9Sstevel@tonic-gate if (fwrite(string, strlen(string), 1, yyin) != 1) { 6469bbec428eSgjelinek zone_perror(execname, Z_TEMP_FILE, B_TRUE); 64707c478bd9Sstevel@tonic-gate return (Z_ERR); 64717c478bd9Sstevel@tonic-gate } 64727c478bd9Sstevel@tonic-gate if (fseek(yyin, 0, SEEK_SET) != 0) { 6473bbec428eSgjelinek zone_perror(execname, Z_TEMP_FILE, B_TRUE); 64747c478bd9Sstevel@tonic-gate return (Z_ERR); 64757c478bd9Sstevel@tonic-gate } 64767c478bd9Sstevel@tonic-gate return (Z_OK); 64777c478bd9Sstevel@tonic-gate } 64787c478bd9Sstevel@tonic-gate 64797c478bd9Sstevel@tonic-gate /* This is the back-end helper function for read_input() below. */ 64807c478bd9Sstevel@tonic-gate 64817c478bd9Sstevel@tonic-gate static int 64827c478bd9Sstevel@tonic-gate cleanup() 64837c478bd9Sstevel@tonic-gate { 64847c478bd9Sstevel@tonic-gate int answer; 64857c478bd9Sstevel@tonic-gate cmd_t *cmd; 64867c478bd9Sstevel@tonic-gate 64877c478bd9Sstevel@tonic-gate if (!interactive_mode && !cmd_file_mode) { 64887c478bd9Sstevel@tonic-gate /* 64897c478bd9Sstevel@tonic-gate * If we're not in interactive mode, and we're not in command 64907c478bd9Sstevel@tonic-gate * file mode, then we must be in commands-from-the-command-line 64917c478bd9Sstevel@tonic-gate * mode. As such, we can't loop back and ask for more input. 64927c478bd9Sstevel@tonic-gate * It was OK to prompt for such things as whether or not to 64937c478bd9Sstevel@tonic-gate * really delete a zone in the command handler called from 64947c478bd9Sstevel@tonic-gate * yyparse() above, but "really quit?" makes no sense in this 64957c478bd9Sstevel@tonic-gate * context. So disable prompting. 64967c478bd9Sstevel@tonic-gate */ 6497bbec428eSgjelinek ok_to_prompt = B_FALSE; 64987c478bd9Sstevel@tonic-gate } 64997c478bd9Sstevel@tonic-gate if (!global_scope) { 65007c478bd9Sstevel@tonic-gate if (!time_to_exit) { 65017c478bd9Sstevel@tonic-gate /* 65027c478bd9Sstevel@tonic-gate * Just print a simple error message in the -1 case, 65037c478bd9Sstevel@tonic-gate * since exit_func() already handles that case, and 65047c478bd9Sstevel@tonic-gate * EOF means we are finished anyway. 65057c478bd9Sstevel@tonic-gate */ 6506bbec428eSgjelinek answer = ask_yesno(B_FALSE, 65077c478bd9Sstevel@tonic-gate gettext("Resource incomplete; really quit")); 65087c478bd9Sstevel@tonic-gate if (answer == -1) { 65097c478bd9Sstevel@tonic-gate zerr(gettext("Resource incomplete.")); 65107c478bd9Sstevel@tonic-gate return (Z_ERR); 65117c478bd9Sstevel@tonic-gate } 65127c478bd9Sstevel@tonic-gate if (answer != 1) { 65137c478bd9Sstevel@tonic-gate yyin = stdin; 65147c478bd9Sstevel@tonic-gate return (Z_REPEAT); 65157c478bd9Sstevel@tonic-gate } 65167c478bd9Sstevel@tonic-gate } else { 6517bbec428eSgjelinek saw_error = B_TRUE; 65187c478bd9Sstevel@tonic-gate } 65197c478bd9Sstevel@tonic-gate } 65207c478bd9Sstevel@tonic-gate /* 65217c478bd9Sstevel@tonic-gate * Make sure we tried something and that the handle checks 65227c478bd9Sstevel@tonic-gate * out, or we would get a false error trying to commit. 65237c478bd9Sstevel@tonic-gate */ 65247c478bd9Sstevel@tonic-gate if (need_to_commit && zonecfg_check_handle(handle) == Z_OK) { 65257c478bd9Sstevel@tonic-gate if ((cmd = alloc_cmd()) == NULL) { 6526bbec428eSgjelinek zone_perror(zone, Z_NOMEM, B_TRUE); 65277c478bd9Sstevel@tonic-gate return (Z_ERR); 65287c478bd9Sstevel@tonic-gate } 65297c478bd9Sstevel@tonic-gate cmd->cmd_argc = 0; 65307c478bd9Sstevel@tonic-gate cmd->cmd_argv[0] = NULL; 65317c478bd9Sstevel@tonic-gate commit_func(cmd); 65327c478bd9Sstevel@tonic-gate free_cmd(cmd); 65337c478bd9Sstevel@tonic-gate /* 65347c478bd9Sstevel@tonic-gate * need_to_commit will get set back to FALSE if the 65357c478bd9Sstevel@tonic-gate * configuration is saved successfully. 65367c478bd9Sstevel@tonic-gate */ 65377c478bd9Sstevel@tonic-gate if (need_to_commit) { 65387c478bd9Sstevel@tonic-gate if (force_exit) { 65397c478bd9Sstevel@tonic-gate zerr(gettext("Configuration not saved.")); 65407c478bd9Sstevel@tonic-gate return (Z_ERR); 65417c478bd9Sstevel@tonic-gate } 6542bbec428eSgjelinek answer = ask_yesno(B_FALSE, 65437c478bd9Sstevel@tonic-gate gettext("Configuration not saved; really quit")); 65447c478bd9Sstevel@tonic-gate if (answer == -1) { 65457c478bd9Sstevel@tonic-gate zerr(gettext("Configuration not saved.")); 65467c478bd9Sstevel@tonic-gate return (Z_ERR); 65477c478bd9Sstevel@tonic-gate } 65487c478bd9Sstevel@tonic-gate if (answer != 1) { 6549bbec428eSgjelinek time_to_exit = B_FALSE; 65507c478bd9Sstevel@tonic-gate yyin = stdin; 65517c478bd9Sstevel@tonic-gate return (Z_REPEAT); 65527c478bd9Sstevel@tonic-gate } 65537c478bd9Sstevel@tonic-gate } 65547c478bd9Sstevel@tonic-gate } 65557c478bd9Sstevel@tonic-gate return ((need_to_commit || saw_error) ? Z_ERR : Z_OK); 65567c478bd9Sstevel@tonic-gate } 65577c478bd9Sstevel@tonic-gate 65587c478bd9Sstevel@tonic-gate /* 65597c478bd9Sstevel@tonic-gate * read_input() is the driver of this program. It is a wrapper around 65607c478bd9Sstevel@tonic-gate * yyparse(), printing appropriate prompts when needed, checking for 65617c478bd9Sstevel@tonic-gate * exit conditions and reacting appropriately [the latter in its cleanup() 65627c478bd9Sstevel@tonic-gate * helper function]. 65637c478bd9Sstevel@tonic-gate * 65647c478bd9Sstevel@tonic-gate * Like most zonecfg functions, it returns Z_OK or Z_ERR, *or* Z_REPEAT 65657c478bd9Sstevel@tonic-gate * so do_interactive() knows that we are not really done (i.e, we asked 65667c478bd9Sstevel@tonic-gate * the user if we should really quit and the user said no). 65677c478bd9Sstevel@tonic-gate */ 65687c478bd9Sstevel@tonic-gate static int 65697c478bd9Sstevel@tonic-gate read_input() 65707c478bd9Sstevel@tonic-gate { 6571bbec428eSgjelinek boolean_t yyin_is_a_tty = isatty(fileno(yyin)); 65727c478bd9Sstevel@tonic-gate /* 65737c478bd9Sstevel@tonic-gate * The prompt is "e:z> " or "e:z:r> " where e is execname, z is zone 65747c478bd9Sstevel@tonic-gate * and r is resource_scope: 5 is for the two ":"s + "> " + terminator. 65757c478bd9Sstevel@tonic-gate */ 65767c478bd9Sstevel@tonic-gate char prompt[MAXPATHLEN + ZONENAME_MAX + MAX_RT_STRLEN + 5], *line; 65777c478bd9Sstevel@tonic-gate 65787c478bd9Sstevel@tonic-gate /* yyin should have been set to the appropriate (FILE *) if not stdin */ 6579bbec428eSgjelinek newline_terminated = B_TRUE; 65807c478bd9Sstevel@tonic-gate for (;;) { 65817c478bd9Sstevel@tonic-gate if (yyin_is_a_tty) { 65827c478bd9Sstevel@tonic-gate if (newline_terminated) { 65837c478bd9Sstevel@tonic-gate if (global_scope) 65847c478bd9Sstevel@tonic-gate (void) snprintf(prompt, sizeof (prompt), 65857c478bd9Sstevel@tonic-gate "%s:%s> ", execname, zone); 65867c478bd9Sstevel@tonic-gate else 65877c478bd9Sstevel@tonic-gate (void) snprintf(prompt, sizeof (prompt), 65887c478bd9Sstevel@tonic-gate "%s:%s:%s> ", execname, zone, 65897c478bd9Sstevel@tonic-gate rt_to_str(resource_scope)); 65907c478bd9Sstevel@tonic-gate } 65917c478bd9Sstevel@tonic-gate /* 65927c478bd9Sstevel@tonic-gate * If the user hits ^C then we want to catch it and 65937c478bd9Sstevel@tonic-gate * start over. If the user hits EOF then we want to 65947c478bd9Sstevel@tonic-gate * bail out. 65957c478bd9Sstevel@tonic-gate */ 65967c478bd9Sstevel@tonic-gate line = gl_get_line(gl, prompt, NULL, -1); 65977c478bd9Sstevel@tonic-gate if (gl_return_status(gl) == GLR_SIGNAL) { 65987c478bd9Sstevel@tonic-gate gl_abandon_line(gl); 65997c478bd9Sstevel@tonic-gate continue; 66007c478bd9Sstevel@tonic-gate } 66017c478bd9Sstevel@tonic-gate if (line == NULL) 66027c478bd9Sstevel@tonic-gate break; 66037c478bd9Sstevel@tonic-gate (void) string_to_yyin(line); 66047c478bd9Sstevel@tonic-gate while (!feof(yyin)) 66057c478bd9Sstevel@tonic-gate yyparse(); 66067c478bd9Sstevel@tonic-gate } else { 66077c478bd9Sstevel@tonic-gate yyparse(); 66087c478bd9Sstevel@tonic-gate } 66097c478bd9Sstevel@tonic-gate /* Bail out on an error in command file mode. */ 66107c478bd9Sstevel@tonic-gate if (saw_error && cmd_file_mode && !interactive_mode) 6611bbec428eSgjelinek time_to_exit = B_TRUE; 66127c478bd9Sstevel@tonic-gate if (time_to_exit || (!yyin_is_a_tty && feof(yyin))) 66137c478bd9Sstevel@tonic-gate break; 66147c478bd9Sstevel@tonic-gate } 66157c478bd9Sstevel@tonic-gate return (cleanup()); 66167c478bd9Sstevel@tonic-gate } 66177c478bd9Sstevel@tonic-gate 66187c478bd9Sstevel@tonic-gate /* 66197c478bd9Sstevel@tonic-gate * This function is used in the zonecfg-interactive-mode scenario: it just 66207c478bd9Sstevel@tonic-gate * calls read_input() until we are done. 66217c478bd9Sstevel@tonic-gate */ 66227c478bd9Sstevel@tonic-gate 66237c478bd9Sstevel@tonic-gate static int 66247c478bd9Sstevel@tonic-gate do_interactive(void) 66257c478bd9Sstevel@tonic-gate { 66267c478bd9Sstevel@tonic-gate int err; 66277c478bd9Sstevel@tonic-gate 6628bbec428eSgjelinek interactive_mode = B_TRUE; 66297c478bd9Sstevel@tonic-gate if (!read_only_mode) { 66307c478bd9Sstevel@tonic-gate /* 66317c478bd9Sstevel@tonic-gate * Try to set things up proactively in interactive mode, so 66327c478bd9Sstevel@tonic-gate * that if the zone in question does not exist yet, we can 66337c478bd9Sstevel@tonic-gate * provide the user with a clue. 66347c478bd9Sstevel@tonic-gate */ 6635bbec428eSgjelinek (void) initialize(B_FALSE); 66367c478bd9Sstevel@tonic-gate } 6637087719fdSdp do { 66387c478bd9Sstevel@tonic-gate err = read_input(); 6639087719fdSdp } while (err == Z_REPEAT); 66407c478bd9Sstevel@tonic-gate return (err); 66417c478bd9Sstevel@tonic-gate } 66427c478bd9Sstevel@tonic-gate 66437c478bd9Sstevel@tonic-gate /* 66447c478bd9Sstevel@tonic-gate * cmd_file is slightly more complicated, as it has to open the command file 66457c478bd9Sstevel@tonic-gate * and set yyin appropriately. Once that is done, though, it just calls 66467c478bd9Sstevel@tonic-gate * read_input(), and only once, since prompting is not possible. 66477c478bd9Sstevel@tonic-gate */ 66487c478bd9Sstevel@tonic-gate 66497c478bd9Sstevel@tonic-gate static int 66507c478bd9Sstevel@tonic-gate cmd_file(char *file) 66517c478bd9Sstevel@tonic-gate { 66527c478bd9Sstevel@tonic-gate FILE *infile; 66537c478bd9Sstevel@tonic-gate int err; 66547c478bd9Sstevel@tonic-gate struct stat statbuf; 6655bbec428eSgjelinek boolean_t using_real_file = (strcmp(file, "-") != 0); 66567c478bd9Sstevel@tonic-gate 66577c478bd9Sstevel@tonic-gate if (using_real_file) { 66587c478bd9Sstevel@tonic-gate /* 66597c478bd9Sstevel@tonic-gate * zerr() prints a line number in cmd_file_mode, which we do 66607c478bd9Sstevel@tonic-gate * not want here, so temporarily unset it. 66617c478bd9Sstevel@tonic-gate */ 6662bbec428eSgjelinek cmd_file_mode = B_FALSE; 66637c478bd9Sstevel@tonic-gate if ((infile = fopen(file, "r")) == NULL) { 66647c478bd9Sstevel@tonic-gate zerr(gettext("could not open file %s: %s"), 66657c478bd9Sstevel@tonic-gate file, strerror(errno)); 66667c478bd9Sstevel@tonic-gate return (Z_ERR); 66677c478bd9Sstevel@tonic-gate } 66687c478bd9Sstevel@tonic-gate if ((err = fstat(fileno(infile), &statbuf)) != 0) { 66697c478bd9Sstevel@tonic-gate zerr(gettext("could not stat file %s: %s"), 66707c478bd9Sstevel@tonic-gate file, strerror(errno)); 66717c478bd9Sstevel@tonic-gate err = Z_ERR; 66727c478bd9Sstevel@tonic-gate goto done; 66737c478bd9Sstevel@tonic-gate } 66747c478bd9Sstevel@tonic-gate if (!S_ISREG(statbuf.st_mode)) { 66757c478bd9Sstevel@tonic-gate zerr(gettext("%s is not a regular file."), file); 66767c478bd9Sstevel@tonic-gate err = Z_ERR; 66777c478bd9Sstevel@tonic-gate goto done; 66787c478bd9Sstevel@tonic-gate } 66797c478bd9Sstevel@tonic-gate yyin = infile; 6680bbec428eSgjelinek cmd_file_mode = B_TRUE; 6681bbec428eSgjelinek ok_to_prompt = B_FALSE; 66827c478bd9Sstevel@tonic-gate } else { 66837c478bd9Sstevel@tonic-gate /* 66847c478bd9Sstevel@tonic-gate * "-f -" is essentially the same as interactive mode, 66857c478bd9Sstevel@tonic-gate * so treat it that way. 66867c478bd9Sstevel@tonic-gate */ 6687bbec428eSgjelinek interactive_mode = B_TRUE; 66887c478bd9Sstevel@tonic-gate } 66897c478bd9Sstevel@tonic-gate /* Z_REPEAT is for interactive mode; treat it like Z_ERR here. */ 66907c478bd9Sstevel@tonic-gate if ((err = read_input()) == Z_REPEAT) 66917c478bd9Sstevel@tonic-gate err = Z_ERR; 66927c478bd9Sstevel@tonic-gate done: 66937c478bd9Sstevel@tonic-gate if (using_real_file) 66947c478bd9Sstevel@tonic-gate (void) fclose(infile); 66957c478bd9Sstevel@tonic-gate return (err); 66967c478bd9Sstevel@tonic-gate } 66977c478bd9Sstevel@tonic-gate 66987c478bd9Sstevel@tonic-gate /* 66997c478bd9Sstevel@tonic-gate * Since yacc is based on reading from a (FILE *) whereas what we get from 67007c478bd9Sstevel@tonic-gate * the command line is in argv format, we need to convert when the user 67017c478bd9Sstevel@tonic-gate * gives us commands directly from the command line. That is done here by 67027c478bd9Sstevel@tonic-gate * concatenating the argv list into a space-separated string, writing it 67037c478bd9Sstevel@tonic-gate * to a temp file, and rewinding the file so yyin can be set to it. Then 67047c478bd9Sstevel@tonic-gate * we call read_input(), and only once, since prompting about whether to 67057c478bd9Sstevel@tonic-gate * continue or quit would make no sense in this context. 67067c478bd9Sstevel@tonic-gate */ 67077c478bd9Sstevel@tonic-gate 67087c478bd9Sstevel@tonic-gate static int 67097c478bd9Sstevel@tonic-gate one_command_at_a_time(int argc, char *argv[]) 67107c478bd9Sstevel@tonic-gate { 67117c478bd9Sstevel@tonic-gate char *command; 67127c478bd9Sstevel@tonic-gate size_t len = 2; /* terminal \n\0 */ 67137c478bd9Sstevel@tonic-gate int i, err; 67147c478bd9Sstevel@tonic-gate 67157c478bd9Sstevel@tonic-gate for (i = 0; i < argc; i++) 67167c478bd9Sstevel@tonic-gate len += strlen(argv[i]) + 1; 67177c478bd9Sstevel@tonic-gate if ((command = malloc(len)) == NULL) { 6718bbec428eSgjelinek zone_perror(execname, Z_NOMEM, B_TRUE); 67197c478bd9Sstevel@tonic-gate return (Z_ERR); 67207c478bd9Sstevel@tonic-gate } 67217c478bd9Sstevel@tonic-gate (void) strlcpy(command, argv[0], len); 67227c478bd9Sstevel@tonic-gate for (i = 1; i < argc; i++) { 67237c478bd9Sstevel@tonic-gate (void) strlcat(command, " ", len); 67247c478bd9Sstevel@tonic-gate (void) strlcat(command, argv[i], len); 67257c478bd9Sstevel@tonic-gate } 67267c478bd9Sstevel@tonic-gate (void) strlcat(command, "\n", len); 67277c478bd9Sstevel@tonic-gate err = string_to_yyin(command); 67287c478bd9Sstevel@tonic-gate free(command); 67297c478bd9Sstevel@tonic-gate if (err != Z_OK) 67307c478bd9Sstevel@tonic-gate return (err); 67317c478bd9Sstevel@tonic-gate while (!feof(yyin)) 67327c478bd9Sstevel@tonic-gate yyparse(); 67337c478bd9Sstevel@tonic-gate return (cleanup()); 67347c478bd9Sstevel@tonic-gate } 67357c478bd9Sstevel@tonic-gate 67367c478bd9Sstevel@tonic-gate static char * 67377c478bd9Sstevel@tonic-gate get_execbasename(char *execfullname) 67387c478bd9Sstevel@tonic-gate { 67397c478bd9Sstevel@tonic-gate char *last_slash, *execbasename; 67407c478bd9Sstevel@tonic-gate 67417c478bd9Sstevel@tonic-gate /* guard against '/' at end of command invocation */ 67427c478bd9Sstevel@tonic-gate for (;;) { 67437c478bd9Sstevel@tonic-gate last_slash = strrchr(execfullname, '/'); 67447c478bd9Sstevel@tonic-gate if (last_slash == NULL) { 67457c478bd9Sstevel@tonic-gate execbasename = execfullname; 67467c478bd9Sstevel@tonic-gate break; 67477c478bd9Sstevel@tonic-gate } else { 67487c478bd9Sstevel@tonic-gate execbasename = last_slash + 1; 67497c478bd9Sstevel@tonic-gate if (*execbasename == '\0') { 67507c478bd9Sstevel@tonic-gate *last_slash = '\0'; 67517c478bd9Sstevel@tonic-gate continue; 67527c478bd9Sstevel@tonic-gate } 67537c478bd9Sstevel@tonic-gate break; 67547c478bd9Sstevel@tonic-gate } 67557c478bd9Sstevel@tonic-gate } 67567c478bd9Sstevel@tonic-gate return (execbasename); 67577c478bd9Sstevel@tonic-gate } 67587c478bd9Sstevel@tonic-gate 67597c478bd9Sstevel@tonic-gate int 67607c478bd9Sstevel@tonic-gate main(int argc, char *argv[]) 67617c478bd9Sstevel@tonic-gate { 67627c478bd9Sstevel@tonic-gate int err, arg; 6763555afedfScarlsonj struct stat st; 67647c478bd9Sstevel@tonic-gate 67657c478bd9Sstevel@tonic-gate /* This must be before anything goes to stdout. */ 67667c478bd9Sstevel@tonic-gate setbuf(stdout, NULL); 67677c478bd9Sstevel@tonic-gate 6768bbec428eSgjelinek saw_error = B_FALSE; 6769bbec428eSgjelinek cmd_file_mode = B_FALSE; 67707c478bd9Sstevel@tonic-gate execname = get_execbasename(argv[0]); 67717c478bd9Sstevel@tonic-gate 67727c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 67737c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 67747c478bd9Sstevel@tonic-gate 67757c478bd9Sstevel@tonic-gate if (getzoneid() != GLOBAL_ZONEID) { 67767c478bd9Sstevel@tonic-gate zerr(gettext("%s can only be run from the global zone."), 67777c478bd9Sstevel@tonic-gate execname); 67787c478bd9Sstevel@tonic-gate exit(Z_ERR); 67797c478bd9Sstevel@tonic-gate } 67807c478bd9Sstevel@tonic-gate 67817c478bd9Sstevel@tonic-gate if (argc < 2) { 6782bbec428eSgjelinek usage(B_FALSE, HELP_USAGE | HELP_SUBCMDS); 67837c478bd9Sstevel@tonic-gate exit(Z_USAGE); 67847c478bd9Sstevel@tonic-gate } 67857c478bd9Sstevel@tonic-gate if (strcmp(argv[1], cmd_to_str(CMD_HELP)) == 0) { 67867c478bd9Sstevel@tonic-gate (void) one_command_at_a_time(argc - 1, &(argv[1])); 67877c478bd9Sstevel@tonic-gate exit(Z_OK); 67887c478bd9Sstevel@tonic-gate } 67897c478bd9Sstevel@tonic-gate 6790555afedfScarlsonj while ((arg = getopt(argc, argv, "?f:R:z:")) != EOF) { 67917c478bd9Sstevel@tonic-gate switch (arg) { 67927c478bd9Sstevel@tonic-gate case '?': 67937c478bd9Sstevel@tonic-gate if (optopt == '?') 6794bbec428eSgjelinek usage(B_TRUE, HELP_USAGE | HELP_SUBCMDS); 67957c478bd9Sstevel@tonic-gate else 6796bbec428eSgjelinek usage(B_FALSE, HELP_USAGE); 67977c478bd9Sstevel@tonic-gate exit(Z_USAGE); 67987c478bd9Sstevel@tonic-gate /* NOTREACHED */ 67997c478bd9Sstevel@tonic-gate case 'f': 68007c478bd9Sstevel@tonic-gate cmd_file_name = optarg; 6801bbec428eSgjelinek cmd_file_mode = B_TRUE; 68027c478bd9Sstevel@tonic-gate break; 6803555afedfScarlsonj case 'R': 6804555afedfScarlsonj if (*optarg != '/') { 6805555afedfScarlsonj zerr(gettext("root path must be absolute: %s"), 6806555afedfScarlsonj optarg); 6807555afedfScarlsonj exit(Z_USAGE); 6808555afedfScarlsonj } 6809555afedfScarlsonj if (stat(optarg, &st) == -1 || !S_ISDIR(st.st_mode)) { 6810555afedfScarlsonj zerr(gettext( 6811555afedfScarlsonj "root path must be a directory: %s"), 6812555afedfScarlsonj optarg); 6813555afedfScarlsonj exit(Z_USAGE); 6814555afedfScarlsonj } 6815555afedfScarlsonj zonecfg_set_root(optarg); 6816555afedfScarlsonj break; 68177c478bd9Sstevel@tonic-gate case 'z': 68180209230bSgjelinek if (strcmp(optarg, GLOBAL_ZONENAME) == 0) { 6819bbec428eSgjelinek global_zone = B_TRUE; 68200209230bSgjelinek } else if (zonecfg_validate_zonename(optarg) != Z_OK) { 6821bbec428eSgjelinek zone_perror(optarg, Z_BOGUS_ZONE_NAME, B_TRUE); 6822bbec428eSgjelinek usage(B_FALSE, HELP_SYNTAX); 6823087719fdSdp exit(Z_USAGE); 6824087719fdSdp } 6825087719fdSdp (void) strlcpy(zone, optarg, sizeof (zone)); 6826087719fdSdp (void) strlcpy(revert_zone, optarg, sizeof (zone)); 68277c478bd9Sstevel@tonic-gate break; 68287c478bd9Sstevel@tonic-gate default: 6829bbec428eSgjelinek usage(B_FALSE, HELP_USAGE); 68307c478bd9Sstevel@tonic-gate exit(Z_USAGE); 68317c478bd9Sstevel@tonic-gate } 68327c478bd9Sstevel@tonic-gate } 68337c478bd9Sstevel@tonic-gate 6834087719fdSdp if (optind > argc || strcmp(zone, "") == 0) { 6835bbec428eSgjelinek usage(B_FALSE, HELP_USAGE); 68367c478bd9Sstevel@tonic-gate exit(Z_USAGE); 68377c478bd9Sstevel@tonic-gate } 68387c478bd9Sstevel@tonic-gate 6839087719fdSdp if ((err = zonecfg_access(zone, W_OK)) == Z_OK) { 6840bbec428eSgjelinek read_only_mode = B_FALSE; 6841087719fdSdp } else if (err == Z_ACCES) { 6842bbec428eSgjelinek read_only_mode = B_TRUE; 68437c478bd9Sstevel@tonic-gate /* skip this message in one-off from command line mode */ 68447c478bd9Sstevel@tonic-gate if (optind == argc) 68457c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("WARNING: you do not " 68467c478bd9Sstevel@tonic-gate "have write access to this zone's configuration " 68477c478bd9Sstevel@tonic-gate "file;\ngoing into read-only mode.\n")); 6848087719fdSdp } else { 6849087719fdSdp fprintf(stderr, "%s: Could not access zone configuration " 6850087719fdSdp "store: %s\n", execname, zonecfg_strerror(err)); 6851087719fdSdp exit(Z_ERR); 68527c478bd9Sstevel@tonic-gate } 68537c478bd9Sstevel@tonic-gate 68547c478bd9Sstevel@tonic-gate if ((handle = zonecfg_init_handle()) == NULL) { 6855bbec428eSgjelinek zone_perror(execname, Z_NOMEM, B_TRUE); 68567c478bd9Sstevel@tonic-gate exit(Z_ERR); 68577c478bd9Sstevel@tonic-gate } 68587c478bd9Sstevel@tonic-gate 68597c478bd9Sstevel@tonic-gate /* 68607c478bd9Sstevel@tonic-gate * This may get set back to FALSE again in cmd_file() if cmd_file_name 68617c478bd9Sstevel@tonic-gate * is a "real" file as opposed to "-" (i.e. meaning use stdin). 68627c478bd9Sstevel@tonic-gate */ 68637c478bd9Sstevel@tonic-gate if (isatty(STDIN_FILENO)) 6864bbec428eSgjelinek ok_to_prompt = B_TRUE; 68657c478bd9Sstevel@tonic-gate if ((gl = new_GetLine(MAX_LINE_LEN, MAX_CMD_HIST)) == NULL) 68667c478bd9Sstevel@tonic-gate exit(Z_ERR); 68677c478bd9Sstevel@tonic-gate if (gl_customize_completion(gl, NULL, cmd_cpl_fn) != 0) 68687c478bd9Sstevel@tonic-gate exit(Z_ERR); 68697c478bd9Sstevel@tonic-gate (void) sigset(SIGINT, SIG_IGN); 68707c478bd9Sstevel@tonic-gate if (optind == argc) { 68717c478bd9Sstevel@tonic-gate if (!cmd_file_mode) 68727c478bd9Sstevel@tonic-gate err = do_interactive(); 68737c478bd9Sstevel@tonic-gate else 68747c478bd9Sstevel@tonic-gate err = cmd_file(cmd_file_name); 68757c478bd9Sstevel@tonic-gate } else { 68767c478bd9Sstevel@tonic-gate err = one_command_at_a_time(argc - optind, &(argv[optind])); 68777c478bd9Sstevel@tonic-gate } 68787c478bd9Sstevel@tonic-gate zonecfg_fini_handle(handle); 68799acbbeafSnn35248 if (brand != NULL) 68809acbbeafSnn35248 brand_close(brand); 68817c478bd9Sstevel@tonic-gate (void) del_GetLine(gl); 68827c478bd9Sstevel@tonic-gate return (err); 68837c478bd9Sstevel@tonic-gate } 6884