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 /* 23*6d4d1c0dSbatschul * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /* 277c478bd9Sstevel@tonic-gate * zonecfg is a lex/yacc based command interpreter used to manage zone 287c478bd9Sstevel@tonic-gate * configurations. The lexer (see zonecfg_lex.l) builds up tokens, which 297c478bd9Sstevel@tonic-gate * the grammar (see zonecfg_grammar.y) builds up into commands, some of 307c478bd9Sstevel@tonic-gate * which takes resources and/or properties as arguments. See the block 317c478bd9Sstevel@tonic-gate * comments near the end of zonecfg_grammar.y for how the data structures 327c478bd9Sstevel@tonic-gate * which keep track of these resources and properties are built up. 337c478bd9Sstevel@tonic-gate * 347c478bd9Sstevel@tonic-gate * The resource/property data structures are inserted into a command 357c478bd9Sstevel@tonic-gate * structure (see zonecfg.h), which also keeps track of command names, 367c478bd9Sstevel@tonic-gate * miscellaneous arguments, and function handlers. The grammar selects 377c478bd9Sstevel@tonic-gate * the appropriate function handler, each of which takes a pointer to a 387c478bd9Sstevel@tonic-gate * command structure as its sole argument, and invokes it. The grammar 397c478bd9Sstevel@tonic-gate * itself is "entered" (a la the Matrix) by yyparse(), which is called 407c478bd9Sstevel@tonic-gate * from read_input(), our main driving function. That in turn is called 417c478bd9Sstevel@tonic-gate * by one of do_interactive(), cmd_file() or one_command_at_a_time(), each 427c478bd9Sstevel@tonic-gate * of which is called from main() depending on how the program was invoked. 437c478bd9Sstevel@tonic-gate * 447c478bd9Sstevel@tonic-gate * The rest of this module consists of the various function handlers and 457c478bd9Sstevel@tonic-gate * their helper functions. Some of these functions, particularly the 467c478bd9Sstevel@tonic-gate * X_to_str() functions, which maps command, resource and property numbers 477c478bd9Sstevel@tonic-gate * to strings, are used quite liberally, as doing so results in a better 487c478bd9Sstevel@tonic-gate * program w/rt I18N, reducing the need for translation notes. 497c478bd9Sstevel@tonic-gate */ 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate #include <sys/mntent.h> 527c478bd9Sstevel@tonic-gate #include <sys/varargs.h> 537c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate #include <errno.h> 569acbbeafSnn #include <fcntl.h> 577c478bd9Sstevel@tonic-gate #include <strings.h> 587c478bd9Sstevel@tonic-gate #include <unistd.h> 597c478bd9Sstevel@tonic-gate #include <ctype.h> 607c478bd9Sstevel@tonic-gate #include <stdlib.h> 617c478bd9Sstevel@tonic-gate #include <assert.h> 627c478bd9Sstevel@tonic-gate #include <sys/stat.h> 637c478bd9Sstevel@tonic-gate #include <zone.h> 647c478bd9Sstevel@tonic-gate #include <arpa/inet.h> 657c478bd9Sstevel@tonic-gate #include <netdb.h> 667c478bd9Sstevel@tonic-gate #include <locale.h> 677c478bd9Sstevel@tonic-gate #include <libintl.h> 687c478bd9Sstevel@tonic-gate #include <alloca.h> 697c478bd9Sstevel@tonic-gate #include <signal.h> 709acbbeafSnn #include <wait.h> 717c478bd9Sstevel@tonic-gate #include <libtecla.h> 72fa9e4066Sahrens #include <libzfs.h> 739acbbeafSnn #include <sys/brand.h> 749acbbeafSnn #include <libbrand.h> 755679c89fSjv #include <sys/systeminfo.h> 76c9f134eaSjv #include <libdladm.h> 77c9f134eaSjv #include <libinetutil.h> 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate #include <libzonecfg.h> 807c478bd9Sstevel@tonic-gate #include "zonecfg.h" 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) /* should be defined by cc -D */ 837c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it wasn't */ 847c478bd9Sstevel@tonic-gate #endif 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate #define PAGER "/usr/bin/more" 879acbbeafSnn #define EXEC_PREFIX "exec " 889acbbeafSnn #define EXEC_LEN (strlen(EXEC_PREFIX)) 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate struct help { 917c478bd9Sstevel@tonic-gate uint_t cmd_num; 927c478bd9Sstevel@tonic-gate char *cmd_name; 937c478bd9Sstevel@tonic-gate uint_t flags; 947c478bd9Sstevel@tonic-gate char *short_usage; 957c478bd9Sstevel@tonic-gate }; 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate extern int yyparse(void); 987c478bd9Sstevel@tonic-gate extern int lex_lineno; 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate #define MAX_LINE_LEN 1024 1017c478bd9Sstevel@tonic-gate #define MAX_CMD_HIST 1024 1029acbbeafSnn #define MAX_CMD_LEN 1024 1037c478bd9Sstevel@tonic-gate 1040209230bSgjelinek #define ONE_MB 1048576 1050209230bSgjelinek 1067c478bd9Sstevel@tonic-gate /* 1077c478bd9Sstevel@tonic-gate * Each SHELP_ should be a simple string. 1087c478bd9Sstevel@tonic-gate */ 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate #define SHELP_ADD "add <resource-type>\n\t(global scope)\n" \ 1117c478bd9Sstevel@tonic-gate "add <property-name> <property-value>\n\t(resource scope)" 1127c478bd9Sstevel@tonic-gate #define SHELP_CANCEL "cancel" 1130209230bSgjelinek #define SHELP_CLEAR "clear <property-name>" 1147c478bd9Sstevel@tonic-gate #define SHELP_COMMIT "commit" 115ee519a1fSgjelinek #define SHELP_CREATE "create [-F] [ -a <path> | -b | -t <template> ]" 1167c478bd9Sstevel@tonic-gate #define SHELP_DELETE "delete [-F]" 1177c478bd9Sstevel@tonic-gate #define SHELP_END "end" 1187c478bd9Sstevel@tonic-gate #define SHELP_EXIT "exit [-F]" 1197c478bd9Sstevel@tonic-gate #define SHELP_EXPORT "export [-f output-file]" 1207c478bd9Sstevel@tonic-gate #define SHELP_HELP "help [commands] [syntax] [usage] [<command-name>]" 1217c478bd9Sstevel@tonic-gate #define SHELP_INFO "info [<resource-type> [property-name=property-value]*]" 1220209230bSgjelinek #define SHELP_REMOVE "remove [-F] <resource-type> " \ 1230209230bSgjelinek "[ <property-name>=<property-value> ]*\n" \ 1240209230bSgjelinek "\t(global scope)\n" \ 1250209230bSgjelinek "remove <property-name> <property-value>\n" \ 1260209230bSgjelinek "\t(resource scope)" 1277c478bd9Sstevel@tonic-gate #define SHELP_REVERT "revert [-F]" 1287c478bd9Sstevel@tonic-gate #define SHELP_SELECT "select <resource-type> { <property-name>=" \ 1297c478bd9Sstevel@tonic-gate "<property-value> }" 1307c478bd9Sstevel@tonic-gate #define SHELP_SET "set <property-name>=<property-value>" 1317c478bd9Sstevel@tonic-gate #define SHELP_VERIFY "verify" 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate static struct help helptab[] = { 1347c478bd9Sstevel@tonic-gate { CMD_ADD, "add", HELP_RES_PROPS, SHELP_ADD, }, 1357c478bd9Sstevel@tonic-gate { CMD_CANCEL, "cancel", 0, SHELP_CANCEL, }, 1360209230bSgjelinek { CMD_CLEAR, "clear", HELP_PROPS, SHELP_CLEAR, }, 1377c478bd9Sstevel@tonic-gate { CMD_COMMIT, "commit", 0, SHELP_COMMIT, }, 1387c478bd9Sstevel@tonic-gate { CMD_CREATE, "create", 0, SHELP_CREATE, }, 1397c478bd9Sstevel@tonic-gate { CMD_DELETE, "delete", 0, SHELP_DELETE, }, 1407c478bd9Sstevel@tonic-gate { CMD_END, "end", 0, SHELP_END, }, 1417c478bd9Sstevel@tonic-gate { CMD_EXIT, "exit", 0, SHELP_EXIT, }, 1427c478bd9Sstevel@tonic-gate { CMD_EXPORT, "export", 0, SHELP_EXPORT, }, 1437c478bd9Sstevel@tonic-gate { CMD_HELP, "help", 0, SHELP_HELP }, 1447c478bd9Sstevel@tonic-gate { CMD_INFO, "info", HELP_RES_PROPS, SHELP_INFO, }, 1457c478bd9Sstevel@tonic-gate { CMD_REMOVE, "remove", HELP_RES_PROPS, SHELP_REMOVE, }, 1467c478bd9Sstevel@tonic-gate { CMD_REVERT, "revert", 0, SHELP_REVERT, }, 1477c478bd9Sstevel@tonic-gate { CMD_SELECT, "select", HELP_RES_PROPS, SHELP_SELECT, }, 1487c478bd9Sstevel@tonic-gate { CMD_SET, "set", HELP_PROPS, SHELP_SET, }, 1497c478bd9Sstevel@tonic-gate { CMD_VERIFY, "verify", 0, SHELP_VERIFY, }, 1507c478bd9Sstevel@tonic-gate { 0 }, 1517c478bd9Sstevel@tonic-gate }; 1527c478bd9Sstevel@tonic-gate 1537c478bd9Sstevel@tonic-gate #define MAX_RT_STRLEN 16 1547c478bd9Sstevel@tonic-gate 1557c478bd9Sstevel@tonic-gate /* These *must* match the order of the RT_ define's from zonecfg.h */ 156c94c1ef0Sjv char *res_types[] = { 1577c478bd9Sstevel@tonic-gate "unknown", 158087719fdSdp "zonename", 1597c478bd9Sstevel@tonic-gate "zonepath", 1607c478bd9Sstevel@tonic-gate "autoboot", 1617c478bd9Sstevel@tonic-gate "pool", 1627c478bd9Sstevel@tonic-gate "fs", 1637c478bd9Sstevel@tonic-gate "inherit-pkg-dir", 1647c478bd9Sstevel@tonic-gate "net", 1657c478bd9Sstevel@tonic-gate "device", 1667c478bd9Sstevel@tonic-gate "rctl", 1677c478bd9Sstevel@tonic-gate "attr", 168fa9e4066Sahrens "dataset", 169ffbafc53Scomay "limitpriv", 1703f2f09c1Sdp "bootargs", 1719acbbeafSnn "brand", 1720209230bSgjelinek "dedicated-cpu", 1730209230bSgjelinek "capped-memory", 1740209230bSgjelinek ALIAS_MAXLWPS, 1750209230bSgjelinek ALIAS_MAXSHMMEM, 1760209230bSgjelinek ALIAS_MAXSHMIDS, 1770209230bSgjelinek ALIAS_MAXMSGIDS, 1780209230bSgjelinek ALIAS_MAXSEMIDS, 1790209230bSgjelinek ALIAS_SHARES, 1800209230bSgjelinek "scheduling-class", 181f4b3ec61Sdh "ip-type", 182c97ad5cdSakolb "capped-cpu", 1835679c89fSjv "hostid", 1847c478bd9Sstevel@tonic-gate NULL 1857c478bd9Sstevel@tonic-gate }; 1867c478bd9Sstevel@tonic-gate 1877c478bd9Sstevel@tonic-gate /* These *must* match the order of the PT_ define's from zonecfg.h */ 188c94c1ef0Sjv char *prop_types[] = { 1897c478bd9Sstevel@tonic-gate "unknown", 190087719fdSdp "zonename", 1917c478bd9Sstevel@tonic-gate "zonepath", 1927c478bd9Sstevel@tonic-gate "autoboot", 1937c478bd9Sstevel@tonic-gate "pool", 1947c478bd9Sstevel@tonic-gate "dir", 1957c478bd9Sstevel@tonic-gate "special", 1967c478bd9Sstevel@tonic-gate "type", 1977c478bd9Sstevel@tonic-gate "options", 1987c478bd9Sstevel@tonic-gate "address", 1997c478bd9Sstevel@tonic-gate "physical", 2007c478bd9Sstevel@tonic-gate "name", 2017c478bd9Sstevel@tonic-gate "value", 2027c478bd9Sstevel@tonic-gate "match", 2037c478bd9Sstevel@tonic-gate "priv", 2047c478bd9Sstevel@tonic-gate "limit", 2057c478bd9Sstevel@tonic-gate "action", 2067c478bd9Sstevel@tonic-gate "raw", 207ffbafc53Scomay "limitpriv", 2083f2f09c1Sdp "bootargs", 2099acbbeafSnn "brand", 2100209230bSgjelinek "ncpus", 2110209230bSgjelinek "importance", 2120209230bSgjelinek "swap", 2130209230bSgjelinek "locked", 2140209230bSgjelinek ALIAS_SHARES, 2150209230bSgjelinek ALIAS_MAXLWPS, 2160209230bSgjelinek ALIAS_MAXSHMMEM, 2170209230bSgjelinek ALIAS_MAXSHMIDS, 2180209230bSgjelinek ALIAS_MAXMSGIDS, 2190209230bSgjelinek ALIAS_MAXSEMIDS, 2200209230bSgjelinek ALIAS_MAXLOCKEDMEM, 2210209230bSgjelinek ALIAS_MAXSWAP, 2220209230bSgjelinek "scheduling-class", 223f4b3ec61Sdh "ip-type", 224de860bd9Sgfaden "defrouter", 2255679c89fSjv "hostid", 2267c478bd9Sstevel@tonic-gate NULL 2277c478bd9Sstevel@tonic-gate }; 2287c478bd9Sstevel@tonic-gate 229ffbafc53Scomay /* These *must* match the order of the PROP_VAL_ define's from zonecfg.h */ 2307c478bd9Sstevel@tonic-gate static char *prop_val_types[] = { 2317c478bd9Sstevel@tonic-gate "simple", 2327c478bd9Sstevel@tonic-gate "complex", 2337c478bd9Sstevel@tonic-gate "list", 2347c478bd9Sstevel@tonic-gate }; 2357c478bd9Sstevel@tonic-gate 2367c478bd9Sstevel@tonic-gate /* 2377c478bd9Sstevel@tonic-gate * The various _cmds[] lists below are for command tab-completion. 2387c478bd9Sstevel@tonic-gate */ 2397c478bd9Sstevel@tonic-gate 2407c478bd9Sstevel@tonic-gate /* 2417c478bd9Sstevel@tonic-gate * remove has a space afterwards because it has qualifiers; the other commands 2420209230bSgjelinek * that have qualifiers (add, select, etc.) don't need a space here because 2437c478bd9Sstevel@tonic-gate * they have their own _cmds[] lists below. 2447c478bd9Sstevel@tonic-gate */ 2457c478bd9Sstevel@tonic-gate static const char *global_scope_cmds[] = { 2467c478bd9Sstevel@tonic-gate "add", 2470209230bSgjelinek "clear", 2487c478bd9Sstevel@tonic-gate "commit", 2497c478bd9Sstevel@tonic-gate "create", 2507c478bd9Sstevel@tonic-gate "delete", 2517c478bd9Sstevel@tonic-gate "exit", 2527c478bd9Sstevel@tonic-gate "export", 2537c478bd9Sstevel@tonic-gate "help", 2547c478bd9Sstevel@tonic-gate "info", 2557c478bd9Sstevel@tonic-gate "remove ", 2567c478bd9Sstevel@tonic-gate "revert", 2577c478bd9Sstevel@tonic-gate "select", 2587c478bd9Sstevel@tonic-gate "set", 2597c478bd9Sstevel@tonic-gate "verify", 2607c478bd9Sstevel@tonic-gate NULL 2617c478bd9Sstevel@tonic-gate }; 2627c478bd9Sstevel@tonic-gate 2637c478bd9Sstevel@tonic-gate static const char *add_cmds[] = { 2647c478bd9Sstevel@tonic-gate "add fs", 2657c478bd9Sstevel@tonic-gate "add inherit-pkg-dir", 2667c478bd9Sstevel@tonic-gate "add net", 2677c478bd9Sstevel@tonic-gate "add device", 2687c478bd9Sstevel@tonic-gate "add rctl", 2697c478bd9Sstevel@tonic-gate "add attr", 270fa9e4066Sahrens "add dataset", 2710209230bSgjelinek "add dedicated-cpu", 272c97ad5cdSakolb "add capped-cpu", 2730209230bSgjelinek "add capped-memory", 2740209230bSgjelinek NULL 2750209230bSgjelinek }; 2760209230bSgjelinek 2770209230bSgjelinek static const char *clear_cmds[] = { 2780209230bSgjelinek "clear autoboot", 2790209230bSgjelinek "clear pool", 2800209230bSgjelinek "clear limitpriv", 2810209230bSgjelinek "clear bootargs", 2820209230bSgjelinek "clear scheduling-class", 283f4b3ec61Sdh "clear ip-type", 2840209230bSgjelinek "clear " ALIAS_MAXLWPS, 2850209230bSgjelinek "clear " ALIAS_MAXSHMMEM, 2860209230bSgjelinek "clear " ALIAS_MAXSHMIDS, 2870209230bSgjelinek "clear " ALIAS_MAXMSGIDS, 2880209230bSgjelinek "clear " ALIAS_MAXSEMIDS, 2890209230bSgjelinek "clear " ALIAS_SHARES, 2907c478bd9Sstevel@tonic-gate NULL 2917c478bd9Sstevel@tonic-gate }; 2927c478bd9Sstevel@tonic-gate 2939e7542f4Sdp static const char *remove_cmds[] = { 2949e7542f4Sdp "remove fs ", 2959e7542f4Sdp "remove inherit-pkg-dir ", 2969e7542f4Sdp "remove net ", 2979e7542f4Sdp "remove device ", 2989e7542f4Sdp "remove rctl ", 2999e7542f4Sdp "remove attr ", 3009e7542f4Sdp "remove dataset ", 3010209230bSgjelinek "remove dedicated-cpu ", 302c97ad5cdSakolb "remove capped-cpu ", 3030209230bSgjelinek "remove capped-memory ", 3049e7542f4Sdp NULL 3059e7542f4Sdp }; 3069e7542f4Sdp 3077c478bd9Sstevel@tonic-gate static const char *select_cmds[] = { 308087719fdSdp "select fs ", 309087719fdSdp "select inherit-pkg-dir ", 310087719fdSdp "select net ", 311087719fdSdp "select device ", 312087719fdSdp "select rctl ", 313087719fdSdp "select attr ", 314fa9e4066Sahrens "select dataset ", 3150209230bSgjelinek "select dedicated-cpu", 316c97ad5cdSakolb "select capped-cpu", 3170209230bSgjelinek "select capped-memory", 3187c478bd9Sstevel@tonic-gate NULL 3197c478bd9Sstevel@tonic-gate }; 3207c478bd9Sstevel@tonic-gate 3217c478bd9Sstevel@tonic-gate static const char *set_cmds[] = { 322087719fdSdp "set zonename=", 323087719fdSdp "set zonepath=", 3249acbbeafSnn "set brand=", 325087719fdSdp "set autoboot=", 326087719fdSdp "set pool=", 327ffbafc53Scomay "set limitpriv=", 3283f2f09c1Sdp "set bootargs=", 3290209230bSgjelinek "set scheduling-class=", 330f4b3ec61Sdh "set ip-type=", 3310209230bSgjelinek "set " ALIAS_MAXLWPS "=", 3320209230bSgjelinek "set " ALIAS_MAXSHMMEM "=", 3330209230bSgjelinek "set " ALIAS_MAXSHMIDS "=", 3340209230bSgjelinek "set " ALIAS_MAXMSGIDS "=", 3350209230bSgjelinek "set " ALIAS_MAXSEMIDS "=", 3360209230bSgjelinek "set " ALIAS_SHARES "=", 3375679c89fSjv "set hostid=", 3387c478bd9Sstevel@tonic-gate NULL 3397c478bd9Sstevel@tonic-gate }; 3407c478bd9Sstevel@tonic-gate 3419e7542f4Sdp static const char *info_cmds[] = { 3429e7542f4Sdp "info fs ", 3439e7542f4Sdp "info inherit-pkg-dir ", 3449e7542f4Sdp "info net ", 3459e7542f4Sdp "info device ", 3469e7542f4Sdp "info rctl ", 3479e7542f4Sdp "info attr ", 3489e7542f4Sdp "info dataset ", 3490209230bSgjelinek "info capped-memory", 3500209230bSgjelinek "info dedicated-cpu", 351c97ad5cdSakolb "info capped-cpu", 3529e7542f4Sdp "info zonename", 3539e7542f4Sdp "info zonepath", 3549e7542f4Sdp "info autoboot", 3559e7542f4Sdp "info pool", 3569e7542f4Sdp "info limitpriv", 3579e7542f4Sdp "info bootargs", 3580209230bSgjelinek "info brand", 3590209230bSgjelinek "info scheduling-class", 360f4b3ec61Sdh "info ip-type", 3610209230bSgjelinek "info max-lwps", 3620209230bSgjelinek "info max-shm-memory", 3630209230bSgjelinek "info max-shm-ids", 3640209230bSgjelinek "info max-msg-ids", 3650209230bSgjelinek "info max-sem-ids", 3660209230bSgjelinek "info cpu-shares", 3675679c89fSjv "info hostid", 3689e7542f4Sdp NULL 3699e7542f4Sdp }; 3709e7542f4Sdp 3717c478bd9Sstevel@tonic-gate static const char *fs_res_scope_cmds[] = { 3727c478bd9Sstevel@tonic-gate "add options ", 3737c478bd9Sstevel@tonic-gate "cancel", 3747c478bd9Sstevel@tonic-gate "end", 3757c478bd9Sstevel@tonic-gate "exit", 3767c478bd9Sstevel@tonic-gate "help", 3777c478bd9Sstevel@tonic-gate "info", 378ffbafc53Scomay "remove options ", 3797c478bd9Sstevel@tonic-gate "set dir=", 3807c478bd9Sstevel@tonic-gate "set raw=", 3817c478bd9Sstevel@tonic-gate "set special=", 3827c478bd9Sstevel@tonic-gate "set type=", 3830209230bSgjelinek "clear raw", 3847c478bd9Sstevel@tonic-gate NULL 3857c478bd9Sstevel@tonic-gate }; 3867c478bd9Sstevel@tonic-gate 3877c478bd9Sstevel@tonic-gate static const char *net_res_scope_cmds[] = { 3887c478bd9Sstevel@tonic-gate "cancel", 3897c478bd9Sstevel@tonic-gate "end", 3907c478bd9Sstevel@tonic-gate "exit", 3917c478bd9Sstevel@tonic-gate "help", 3927c478bd9Sstevel@tonic-gate "info", 3937c478bd9Sstevel@tonic-gate "set address=", 3947c478bd9Sstevel@tonic-gate "set physical=", 3957c478bd9Sstevel@tonic-gate NULL 3967c478bd9Sstevel@tonic-gate }; 3977c478bd9Sstevel@tonic-gate 3987c478bd9Sstevel@tonic-gate static const char *ipd_res_scope_cmds[] = { 3997c478bd9Sstevel@tonic-gate "cancel", 4007c478bd9Sstevel@tonic-gate "end", 4017c478bd9Sstevel@tonic-gate "exit", 4027c478bd9Sstevel@tonic-gate "help", 4037c478bd9Sstevel@tonic-gate "info", 4047c478bd9Sstevel@tonic-gate "set dir=", 4057c478bd9Sstevel@tonic-gate NULL 4067c478bd9Sstevel@tonic-gate }; 4077c478bd9Sstevel@tonic-gate 4087c478bd9Sstevel@tonic-gate static const char *device_res_scope_cmds[] = { 4097c478bd9Sstevel@tonic-gate "cancel", 4107c478bd9Sstevel@tonic-gate "end", 4117c478bd9Sstevel@tonic-gate "exit", 4127c478bd9Sstevel@tonic-gate "help", 4137c478bd9Sstevel@tonic-gate "info", 4147c478bd9Sstevel@tonic-gate "set match=", 4157c478bd9Sstevel@tonic-gate NULL 4167c478bd9Sstevel@tonic-gate }; 4177c478bd9Sstevel@tonic-gate 4187c478bd9Sstevel@tonic-gate static const char *attr_res_scope_cmds[] = { 4197c478bd9Sstevel@tonic-gate "cancel", 4207c478bd9Sstevel@tonic-gate "end", 4217c478bd9Sstevel@tonic-gate "exit", 4227c478bd9Sstevel@tonic-gate "help", 4237c478bd9Sstevel@tonic-gate "info", 4247c478bd9Sstevel@tonic-gate "set name=", 4257c478bd9Sstevel@tonic-gate "set type=", 4267c478bd9Sstevel@tonic-gate "set value=", 4277c478bd9Sstevel@tonic-gate NULL 4287c478bd9Sstevel@tonic-gate }; 4297c478bd9Sstevel@tonic-gate 4307c478bd9Sstevel@tonic-gate static const char *rctl_res_scope_cmds[] = { 4317c478bd9Sstevel@tonic-gate "add value ", 4327c478bd9Sstevel@tonic-gate "cancel", 4337c478bd9Sstevel@tonic-gate "end", 4347c478bd9Sstevel@tonic-gate "exit", 4357c478bd9Sstevel@tonic-gate "help", 4367c478bd9Sstevel@tonic-gate "info", 437ffbafc53Scomay "remove value ", 4387c478bd9Sstevel@tonic-gate "set name=", 4397c478bd9Sstevel@tonic-gate NULL 4407c478bd9Sstevel@tonic-gate }; 4417c478bd9Sstevel@tonic-gate 442fa9e4066Sahrens static const char *dataset_res_scope_cmds[] = { 443fa9e4066Sahrens "cancel", 444fa9e4066Sahrens "end", 445fa9e4066Sahrens "exit", 446fa9e4066Sahrens "help", 447fa9e4066Sahrens "info", 448fa9e4066Sahrens "set name=", 449fa9e4066Sahrens NULL 450fa9e4066Sahrens }; 451fa9e4066Sahrens 4520209230bSgjelinek static const char *pset_res_scope_cmds[] = { 4530209230bSgjelinek "cancel", 4540209230bSgjelinek "end", 4550209230bSgjelinek "exit", 4560209230bSgjelinek "help", 4570209230bSgjelinek "info", 4580209230bSgjelinek "set ncpus=", 4590209230bSgjelinek "set importance=", 4600209230bSgjelinek "clear importance", 4610209230bSgjelinek NULL 4620209230bSgjelinek }; 4630209230bSgjelinek 464c97ad5cdSakolb static const char *pcap_res_scope_cmds[] = { 465c97ad5cdSakolb "cancel", 466c97ad5cdSakolb "end", 467c97ad5cdSakolb "exit", 468c97ad5cdSakolb "help", 469c97ad5cdSakolb "info", 470c97ad5cdSakolb "set ncpus=", 471c97ad5cdSakolb NULL 472c97ad5cdSakolb }; 473c97ad5cdSakolb 4740209230bSgjelinek static const char *mcap_res_scope_cmds[] = { 4750209230bSgjelinek "cancel", 4760209230bSgjelinek "end", 4770209230bSgjelinek "exit", 4780209230bSgjelinek "help", 4790209230bSgjelinek "info", 4800209230bSgjelinek "set physical=", 4810209230bSgjelinek "set swap=", 4820209230bSgjelinek "set locked=", 4830209230bSgjelinek "clear physical", 4840209230bSgjelinek "clear swap", 4850209230bSgjelinek "clear locked", 4860209230bSgjelinek NULL 4870209230bSgjelinek }; 4880209230bSgjelinek 4897c478bd9Sstevel@tonic-gate /* Global variables */ 4907c478bd9Sstevel@tonic-gate 4917c478bd9Sstevel@tonic-gate /* set early in main(), never modified thereafter, used all over the place */ 4927c478bd9Sstevel@tonic-gate static char *execname; 4937c478bd9Sstevel@tonic-gate 4947c478bd9Sstevel@tonic-gate /* set in main(), used all over the place */ 4957c478bd9Sstevel@tonic-gate static zone_dochandle_t handle; 4967c478bd9Sstevel@tonic-gate 4977c478bd9Sstevel@tonic-gate /* used all over the place */ 498087719fdSdp static char zone[ZONENAME_MAX]; 499087719fdSdp static char revert_zone[ZONENAME_MAX]; 5007c478bd9Sstevel@tonic-gate 5019acbbeafSnn /* global brand operations */ 502123807fbSedp static brand_handle_t brand; 5039acbbeafSnn 5047c478bd9Sstevel@tonic-gate /* set in modifying functions, checked in read_input() */ 505bbec428eSgjelinek static boolean_t need_to_commit = B_FALSE; 506bbec428eSgjelinek boolean_t saw_error; 5077c478bd9Sstevel@tonic-gate 5087c478bd9Sstevel@tonic-gate /* set in yacc parser, checked in read_input() */ 509bbec428eSgjelinek boolean_t newline_terminated; 5107c478bd9Sstevel@tonic-gate 5117c478bd9Sstevel@tonic-gate /* set in main(), checked in lex error handler */ 512bbec428eSgjelinek boolean_t cmd_file_mode; 5137c478bd9Sstevel@tonic-gate 5147c478bd9Sstevel@tonic-gate /* set in exit_func(), checked in read_input() */ 515bbec428eSgjelinek static boolean_t time_to_exit = B_FALSE, force_exit = B_FALSE; 5167c478bd9Sstevel@tonic-gate 5177c478bd9Sstevel@tonic-gate /* used in short_usage() and zerr() */ 5187c478bd9Sstevel@tonic-gate static char *cmd_file_name = NULL; 5197c478bd9Sstevel@tonic-gate 5207c478bd9Sstevel@tonic-gate /* checked in read_input() and other places */ 521bbec428eSgjelinek static boolean_t ok_to_prompt = B_FALSE; 5227c478bd9Sstevel@tonic-gate 5237c478bd9Sstevel@tonic-gate /* set and checked in initialize() */ 524bbec428eSgjelinek static boolean_t got_handle = B_FALSE; 5257c478bd9Sstevel@tonic-gate 5267c478bd9Sstevel@tonic-gate /* initialized in do_interactive(), checked in initialize() */ 527bbec428eSgjelinek static boolean_t interactive_mode; 5287c478bd9Sstevel@tonic-gate 5290209230bSgjelinek /* set if configuring the global zone */ 530bbec428eSgjelinek static boolean_t global_zone = B_FALSE; 5310209230bSgjelinek 5327c478bd9Sstevel@tonic-gate /* set in main(), checked in multiple places */ 533bbec428eSgjelinek static boolean_t read_only_mode; 5347c478bd9Sstevel@tonic-gate 535bbec428eSgjelinek /* scope is outer/global or inner/resource */ 536bbec428eSgjelinek static boolean_t global_scope = B_TRUE; 5377c478bd9Sstevel@tonic-gate static int resource_scope; /* should be in the RT_ list from zonecfg.h */ 5387c478bd9Sstevel@tonic-gate static int end_op = -1; /* operation on end is either add or modify */ 5397c478bd9Sstevel@tonic-gate 5407c478bd9Sstevel@tonic-gate int num_prop_vals; /* for grammar */ 5417c478bd9Sstevel@tonic-gate 5427c478bd9Sstevel@tonic-gate /* 5437c478bd9Sstevel@tonic-gate * These are for keeping track of resources as they are specified as part of 5447c478bd9Sstevel@tonic-gate * the multi-step process. They should be initialized by add_resource() or 5457c478bd9Sstevel@tonic-gate * select_func() and filled in by add_property() or set_func(). 5467c478bd9Sstevel@tonic-gate */ 5477c478bd9Sstevel@tonic-gate static struct zone_fstab old_fstab, in_progress_fstab; 5487c478bd9Sstevel@tonic-gate static struct zone_fstab old_ipdtab, in_progress_ipdtab; 5497c478bd9Sstevel@tonic-gate static struct zone_nwiftab old_nwiftab, in_progress_nwiftab; 5507c478bd9Sstevel@tonic-gate static struct zone_devtab old_devtab, in_progress_devtab; 5517c478bd9Sstevel@tonic-gate static struct zone_rctltab old_rctltab, in_progress_rctltab; 5527c478bd9Sstevel@tonic-gate static struct zone_attrtab old_attrtab, in_progress_attrtab; 553fa9e4066Sahrens static struct zone_dstab old_dstab, in_progress_dstab; 5540209230bSgjelinek static struct zone_psettab old_psettab, in_progress_psettab; 5550209230bSgjelinek static struct zone_mcaptab old_mcaptab, in_progress_mcaptab; 5567c478bd9Sstevel@tonic-gate 5577c478bd9Sstevel@tonic-gate static GetLine *gl; /* The gl_get_line() resource object */ 5587c478bd9Sstevel@tonic-gate 5590209230bSgjelinek static void bytes_to_units(char *str, char *buf, int bufsize); 5600209230bSgjelinek 5617c478bd9Sstevel@tonic-gate /* Functions begin here */ 5627c478bd9Sstevel@tonic-gate 563bbec428eSgjelinek static boolean_t 5647c478bd9Sstevel@tonic-gate initial_match(const char *line1, const char *line2, int word_end) 5657c478bd9Sstevel@tonic-gate { 5667c478bd9Sstevel@tonic-gate if (word_end <= 0) 567bbec428eSgjelinek return (B_TRUE); 5687c478bd9Sstevel@tonic-gate return (strncmp(line1, line2, word_end) == 0); 5697c478bd9Sstevel@tonic-gate } 5707c478bd9Sstevel@tonic-gate 5717c478bd9Sstevel@tonic-gate static int 5727c478bd9Sstevel@tonic-gate add_stuff(WordCompletion *cpl, const char *line1, const char **list, 5737c478bd9Sstevel@tonic-gate int word_end) 5747c478bd9Sstevel@tonic-gate { 5757c478bd9Sstevel@tonic-gate int i, err; 5767c478bd9Sstevel@tonic-gate 5777c478bd9Sstevel@tonic-gate for (i = 0; list[i] != NULL; i++) { 5787c478bd9Sstevel@tonic-gate if (initial_match(line1, list[i], word_end)) { 5797c478bd9Sstevel@tonic-gate err = cpl_add_completion(cpl, line1, 0, word_end, 5807c478bd9Sstevel@tonic-gate list[i] + word_end, "", ""); 5817c478bd9Sstevel@tonic-gate if (err != 0) 5827c478bd9Sstevel@tonic-gate return (err); 5837c478bd9Sstevel@tonic-gate } 5847c478bd9Sstevel@tonic-gate } 5857c478bd9Sstevel@tonic-gate return (0); 5867c478bd9Sstevel@tonic-gate } 5877c478bd9Sstevel@tonic-gate 5887c478bd9Sstevel@tonic-gate static 5897c478bd9Sstevel@tonic-gate /* ARGSUSED */ 5907c478bd9Sstevel@tonic-gate CPL_MATCH_FN(cmd_cpl_fn) 5917c478bd9Sstevel@tonic-gate { 5927c478bd9Sstevel@tonic-gate if (global_scope) { 5937c478bd9Sstevel@tonic-gate /* 5947c478bd9Sstevel@tonic-gate * The MAX/MIN tests below are to make sure we have at least 5957c478bd9Sstevel@tonic-gate * enough characters to distinguish from other prefixes (MAX) 5967c478bd9Sstevel@tonic-gate * but only check MIN(what we have, what we're checking). 5977c478bd9Sstevel@tonic-gate */ 5987c478bd9Sstevel@tonic-gate if (strncmp(line, "add ", MAX(MIN(word_end, 4), 1)) == 0) 5997c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, add_cmds, word_end)); 6000209230bSgjelinek if (strncmp(line, "clear ", MAX(MIN(word_end, 6), 2)) == 0) 6010209230bSgjelinek return (add_stuff(cpl, line, clear_cmds, word_end)); 6027c478bd9Sstevel@tonic-gate if (strncmp(line, "select ", MAX(MIN(word_end, 7), 3)) == 0) 6037c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, select_cmds, word_end)); 6047c478bd9Sstevel@tonic-gate if (strncmp(line, "set ", MAX(MIN(word_end, 4), 3)) == 0) 6057c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, set_cmds, word_end)); 6069e7542f4Sdp if (strncmp(line, "remove ", MAX(MIN(word_end, 7), 1)) == 0) 6079e7542f4Sdp return (add_stuff(cpl, line, remove_cmds, word_end)); 6089e7542f4Sdp if (strncmp(line, "info ", MAX(MIN(word_end, 5), 1)) == 0) 6099e7542f4Sdp return (add_stuff(cpl, line, info_cmds, word_end)); 6107c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, global_scope_cmds, word_end)); 6117c478bd9Sstevel@tonic-gate } 6127c478bd9Sstevel@tonic-gate switch (resource_scope) { 6137c478bd9Sstevel@tonic-gate case RT_FS: 6147c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, fs_res_scope_cmds, word_end)); 6157c478bd9Sstevel@tonic-gate case RT_IPD: 6167c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, ipd_res_scope_cmds, word_end)); 6177c478bd9Sstevel@tonic-gate case RT_NET: 6187c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, net_res_scope_cmds, word_end)); 6197c478bd9Sstevel@tonic-gate case RT_DEVICE: 6207c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, device_res_scope_cmds, word_end)); 6217c478bd9Sstevel@tonic-gate case RT_RCTL: 6227c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, rctl_res_scope_cmds, word_end)); 6237c478bd9Sstevel@tonic-gate case RT_ATTR: 6247c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, attr_res_scope_cmds, word_end)); 625fa9e4066Sahrens case RT_DATASET: 626fa9e4066Sahrens return (add_stuff(cpl, line, dataset_res_scope_cmds, word_end)); 6270209230bSgjelinek case RT_DCPU: 6280209230bSgjelinek return (add_stuff(cpl, line, pset_res_scope_cmds, word_end)); 629c97ad5cdSakolb case RT_PCAP: 630c97ad5cdSakolb return (add_stuff(cpl, line, pcap_res_scope_cmds, word_end)); 6310209230bSgjelinek case RT_MCAP: 6320209230bSgjelinek return (add_stuff(cpl, line, mcap_res_scope_cmds, word_end)); 6337c478bd9Sstevel@tonic-gate } 6347c478bd9Sstevel@tonic-gate return (0); 6357c478bd9Sstevel@tonic-gate } 6367c478bd9Sstevel@tonic-gate 6377c478bd9Sstevel@tonic-gate /* 6387c478bd9Sstevel@tonic-gate * For the main CMD_func() functions below, several of them call getopt() 6397c478bd9Sstevel@tonic-gate * then check optind against argc to make sure an extra parameter was not 6407c478bd9Sstevel@tonic-gate * passed in. The reason this is not caught in the grammar is that the 6417c478bd9Sstevel@tonic-gate * grammar just checks for a miscellaneous TOKEN, which is *expected* to 6427c478bd9Sstevel@tonic-gate * be "-F" (for example), but could be anything. So (for example) this 6437c478bd9Sstevel@tonic-gate * check will prevent "create bogus". 6447c478bd9Sstevel@tonic-gate */ 6457c478bd9Sstevel@tonic-gate 6467c478bd9Sstevel@tonic-gate cmd_t * 6477c478bd9Sstevel@tonic-gate alloc_cmd(void) 6487c478bd9Sstevel@tonic-gate { 6497c478bd9Sstevel@tonic-gate return (calloc(1, sizeof (cmd_t))); 6507c478bd9Sstevel@tonic-gate } 6517c478bd9Sstevel@tonic-gate 6527c478bd9Sstevel@tonic-gate void 6537c478bd9Sstevel@tonic-gate free_cmd(cmd_t *cmd) 6547c478bd9Sstevel@tonic-gate { 6557c478bd9Sstevel@tonic-gate int i; 6567c478bd9Sstevel@tonic-gate 6577c478bd9Sstevel@tonic-gate for (i = 0; i < MAX_EQ_PROP_PAIRS; i++) 6587c478bd9Sstevel@tonic-gate if (cmd->cmd_property_ptr[i] != NULL) { 6597c478bd9Sstevel@tonic-gate property_value_ptr_t pp = cmd->cmd_property_ptr[i]; 6607c478bd9Sstevel@tonic-gate 6617c478bd9Sstevel@tonic-gate switch (pp->pv_type) { 6627c478bd9Sstevel@tonic-gate case PROP_VAL_SIMPLE: 6637c478bd9Sstevel@tonic-gate free(pp->pv_simple); 6647c478bd9Sstevel@tonic-gate break; 6657c478bd9Sstevel@tonic-gate case PROP_VAL_COMPLEX: 6667c478bd9Sstevel@tonic-gate free_complex(pp->pv_complex); 6677c478bd9Sstevel@tonic-gate break; 6687c478bd9Sstevel@tonic-gate case PROP_VAL_LIST: 6697c478bd9Sstevel@tonic-gate free_list(pp->pv_list); 6707c478bd9Sstevel@tonic-gate break; 6717c478bd9Sstevel@tonic-gate } 6727c478bd9Sstevel@tonic-gate } 6737c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_argc; i++) 6747c478bd9Sstevel@tonic-gate free(cmd->cmd_argv[i]); 6757c478bd9Sstevel@tonic-gate free(cmd); 6767c478bd9Sstevel@tonic-gate } 6777c478bd9Sstevel@tonic-gate 6787c478bd9Sstevel@tonic-gate complex_property_ptr_t 6797c478bd9Sstevel@tonic-gate alloc_complex(void) 6807c478bd9Sstevel@tonic-gate { 6817c478bd9Sstevel@tonic-gate return (calloc(1, sizeof (complex_property_t))); 6827c478bd9Sstevel@tonic-gate } 6837c478bd9Sstevel@tonic-gate 6847c478bd9Sstevel@tonic-gate void 6857c478bd9Sstevel@tonic-gate free_complex(complex_property_ptr_t complex) 6867c478bd9Sstevel@tonic-gate { 6877c478bd9Sstevel@tonic-gate if (complex == NULL) 6887c478bd9Sstevel@tonic-gate return; 6897c478bd9Sstevel@tonic-gate free_complex(complex->cp_next); 6907c478bd9Sstevel@tonic-gate if (complex->cp_value != NULL) 6917c478bd9Sstevel@tonic-gate free(complex->cp_value); 6927c478bd9Sstevel@tonic-gate free(complex); 6937c478bd9Sstevel@tonic-gate } 6947c478bd9Sstevel@tonic-gate 6957c478bd9Sstevel@tonic-gate list_property_ptr_t 6967c478bd9Sstevel@tonic-gate alloc_list(void) 6977c478bd9Sstevel@tonic-gate { 6987c478bd9Sstevel@tonic-gate return (calloc(1, sizeof (list_property_t))); 6997c478bd9Sstevel@tonic-gate } 7007c478bd9Sstevel@tonic-gate 7017c478bd9Sstevel@tonic-gate void 7027c478bd9Sstevel@tonic-gate free_list(list_property_ptr_t list) 7037c478bd9Sstevel@tonic-gate { 7047c478bd9Sstevel@tonic-gate if (list == NULL) 7057c478bd9Sstevel@tonic-gate return; 7067c478bd9Sstevel@tonic-gate if (list->lp_simple != NULL) 7077c478bd9Sstevel@tonic-gate free(list->lp_simple); 7087c478bd9Sstevel@tonic-gate free_complex(list->lp_complex); 7097c478bd9Sstevel@tonic-gate free_list(list->lp_next); 7107c478bd9Sstevel@tonic-gate free(list); 7117c478bd9Sstevel@tonic-gate } 7127c478bd9Sstevel@tonic-gate 7137c478bd9Sstevel@tonic-gate void 7147c478bd9Sstevel@tonic-gate free_outer_list(list_property_ptr_t list) 7157c478bd9Sstevel@tonic-gate { 7167c478bd9Sstevel@tonic-gate if (list == NULL) 7177c478bd9Sstevel@tonic-gate return; 7187c478bd9Sstevel@tonic-gate free_outer_list(list->lp_next); 7197c478bd9Sstevel@tonic-gate free(list); 7207c478bd9Sstevel@tonic-gate } 7217c478bd9Sstevel@tonic-gate 7227c478bd9Sstevel@tonic-gate static struct zone_rctlvaltab * 7237c478bd9Sstevel@tonic-gate alloc_rctlvaltab(void) 7247c478bd9Sstevel@tonic-gate { 7257c478bd9Sstevel@tonic-gate return (calloc(1, sizeof (struct zone_rctlvaltab))); 7267c478bd9Sstevel@tonic-gate } 7277c478bd9Sstevel@tonic-gate 7287c478bd9Sstevel@tonic-gate static char * 7297c478bd9Sstevel@tonic-gate rt_to_str(int res_type) 7307c478bd9Sstevel@tonic-gate { 7317c478bd9Sstevel@tonic-gate assert(res_type >= RT_MIN && res_type <= RT_MAX); 7327c478bd9Sstevel@tonic-gate return (res_types[res_type]); 7337c478bd9Sstevel@tonic-gate } 7347c478bd9Sstevel@tonic-gate 7357c478bd9Sstevel@tonic-gate static char * 7367c478bd9Sstevel@tonic-gate pt_to_str(int prop_type) 7377c478bd9Sstevel@tonic-gate { 7387c478bd9Sstevel@tonic-gate assert(prop_type >= PT_MIN && prop_type <= PT_MAX); 7397c478bd9Sstevel@tonic-gate return (prop_types[prop_type]); 7407c478bd9Sstevel@tonic-gate } 7417c478bd9Sstevel@tonic-gate 7427c478bd9Sstevel@tonic-gate static char * 7437c478bd9Sstevel@tonic-gate pvt_to_str(int pv_type) 7447c478bd9Sstevel@tonic-gate { 7457c478bd9Sstevel@tonic-gate assert(pv_type >= PROP_VAL_MIN && pv_type <= PROP_VAL_MAX); 7467c478bd9Sstevel@tonic-gate return (prop_val_types[pv_type]); 7477c478bd9Sstevel@tonic-gate } 7487c478bd9Sstevel@tonic-gate 7497c478bd9Sstevel@tonic-gate static char * 7507c478bd9Sstevel@tonic-gate cmd_to_str(int cmd_num) 7517c478bd9Sstevel@tonic-gate { 7527c478bd9Sstevel@tonic-gate assert(cmd_num >= CMD_MIN && cmd_num <= CMD_MAX); 7537c478bd9Sstevel@tonic-gate return (helptab[cmd_num].cmd_name); 7547c478bd9Sstevel@tonic-gate } 7557c478bd9Sstevel@tonic-gate 7563042b8b5Sbatschul /* PRINTFLIKE1 */ 7573042b8b5Sbatschul static void 7583042b8b5Sbatschul zerr(const char *fmt, ...) 7593042b8b5Sbatschul { 7603042b8b5Sbatschul va_list alist; 7613042b8b5Sbatschul static int last_lineno; 7623042b8b5Sbatschul 7633042b8b5Sbatschul /* lex_lineno has already been incremented in the lexer; compensate */ 7643042b8b5Sbatschul if (cmd_file_mode && lex_lineno > last_lineno) { 7653042b8b5Sbatschul if (strcmp(cmd_file_name, "-") == 0) 7663042b8b5Sbatschul (void) fprintf(stderr, gettext("On line %d:\n"), 7673042b8b5Sbatschul lex_lineno - 1); 7683042b8b5Sbatschul else 7693042b8b5Sbatschul (void) fprintf(stderr, gettext("On line %d of %s:\n"), 7703042b8b5Sbatschul lex_lineno - 1, cmd_file_name); 7713042b8b5Sbatschul last_lineno = lex_lineno; 7723042b8b5Sbatschul } 7733042b8b5Sbatschul va_start(alist, fmt); 7743042b8b5Sbatschul (void) vfprintf(stderr, fmt, alist); 7753042b8b5Sbatschul (void) fprintf(stderr, "\n"); 7763042b8b5Sbatschul va_end(alist); 7773042b8b5Sbatschul } 7783042b8b5Sbatschul 7797c478bd9Sstevel@tonic-gate /* 7807c478bd9Sstevel@tonic-gate * This is a separate function rather than a set of define's because of the 7817c478bd9Sstevel@tonic-gate * gettext() wrapping. 7827c478bd9Sstevel@tonic-gate */ 7837c478bd9Sstevel@tonic-gate 7847c478bd9Sstevel@tonic-gate /* 7857c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE 7867c478bd9Sstevel@tonic-gate * Each string below should have \t follow \n whenever needed; the 7877c478bd9Sstevel@tonic-gate * initial \t and the terminal \n will be provided by the calling function. 7887c478bd9Sstevel@tonic-gate */ 7897c478bd9Sstevel@tonic-gate 7907c478bd9Sstevel@tonic-gate static char * 7917c478bd9Sstevel@tonic-gate long_help(int cmd_num) 7927c478bd9Sstevel@tonic-gate { 7937c478bd9Sstevel@tonic-gate static char line[1024]; /* arbitrary large amount */ 7947c478bd9Sstevel@tonic-gate 7957c478bd9Sstevel@tonic-gate assert(cmd_num >= CMD_MIN && cmd_num <= CMD_MAX); 7967c478bd9Sstevel@tonic-gate switch (cmd_num) { 7977c478bd9Sstevel@tonic-gate case CMD_HELP: 7987c478bd9Sstevel@tonic-gate return (gettext("Prints help message.")); 7997c478bd9Sstevel@tonic-gate case CMD_CREATE: 8007c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), 8017c478bd9Sstevel@tonic-gate gettext("Creates a configuration for the " 8027c478bd9Sstevel@tonic-gate "specified zone. %s should be\n\tused to " 8037c478bd9Sstevel@tonic-gate "begin configuring a new zone. If overwriting an " 8047c478bd9Sstevel@tonic-gate "existing\n\tconfiguration, the -F flag can be " 8057c478bd9Sstevel@tonic-gate "used to force the action. If\n\t-t template is " 8067c478bd9Sstevel@tonic-gate "given, creates a configuration identical to the\n" 8077c478bd9Sstevel@tonic-gate "\tspecified template, except that the zone name " 8089e518655Sgjelinek "is changed from\n\ttemplate to zonename. '%s -a' " 8099e518655Sgjelinek "creates a configuration from a\n\tdetached " 8109e518655Sgjelinek "zonepath. '%s -b' results in a blank " 8119e518655Sgjelinek "configuration.\n\t'%s' with no arguments applies " 8129e518655Sgjelinek "the Sun default settings."), 8137c478bd9Sstevel@tonic-gate cmd_to_str(CMD_CREATE), cmd_to_str(CMD_CREATE), 8149e518655Sgjelinek cmd_to_str(CMD_CREATE), cmd_to_str(CMD_CREATE)); 8157c478bd9Sstevel@tonic-gate return (line); 8167c478bd9Sstevel@tonic-gate case CMD_EXIT: 8177c478bd9Sstevel@tonic-gate return (gettext("Exits the program. The -F flag can " 8187c478bd9Sstevel@tonic-gate "be used to force the action.")); 8197c478bd9Sstevel@tonic-gate case CMD_EXPORT: 8207c478bd9Sstevel@tonic-gate return (gettext("Prints configuration to standard " 8217c478bd9Sstevel@tonic-gate "output, or to output-file if\n\tspecified, in " 8227c478bd9Sstevel@tonic-gate "a form suitable for use in a command-file.")); 8237c478bd9Sstevel@tonic-gate case CMD_ADD: 8247c478bd9Sstevel@tonic-gate return (gettext("Add specified resource to " 8257c478bd9Sstevel@tonic-gate "configuration.")); 8267c478bd9Sstevel@tonic-gate case CMD_DELETE: 8277c478bd9Sstevel@tonic-gate return (gettext("Deletes the specified zone. The -F " 8287c478bd9Sstevel@tonic-gate "flag can be used to force the\n\taction.")); 8297c478bd9Sstevel@tonic-gate case CMD_REMOVE: 8307c478bd9Sstevel@tonic-gate return (gettext("Remove specified resource from " 8310209230bSgjelinek "configuration. The -F flag can be used\n\tto " 8320209230bSgjelinek "force the action.")); 8337c478bd9Sstevel@tonic-gate case CMD_SELECT: 8347c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), 8357c478bd9Sstevel@tonic-gate gettext("Selects a resource to modify. " 8367c478bd9Sstevel@tonic-gate "Resource modification is completed\n\twith the " 8377c478bd9Sstevel@tonic-gate "command \"%s\". The property name/value pairs " 8387c478bd9Sstevel@tonic-gate "must uniquely\n\tidentify a resource. Note that " 8397c478bd9Sstevel@tonic-gate "the curly braces ('{', '}') mean one\n\tor more " 8407c478bd9Sstevel@tonic-gate "of whatever is between them."), 8417c478bd9Sstevel@tonic-gate cmd_to_str(CMD_END)); 8427c478bd9Sstevel@tonic-gate return (line); 8437c478bd9Sstevel@tonic-gate case CMD_SET: 8447c478bd9Sstevel@tonic-gate return (gettext("Sets property values.")); 8450209230bSgjelinek case CMD_CLEAR: 8460209230bSgjelinek return (gettext("Clears property values.")); 8477c478bd9Sstevel@tonic-gate case CMD_INFO: 8487c478bd9Sstevel@tonic-gate return (gettext("Displays information about the " 8497c478bd9Sstevel@tonic-gate "current configuration. If resource\n\ttype is " 8507c478bd9Sstevel@tonic-gate "specified, displays only information about " 8517c478bd9Sstevel@tonic-gate "resources of\n\tthe relevant type. If resource " 8527c478bd9Sstevel@tonic-gate "id is specified, displays only\n\tinformation " 8537c478bd9Sstevel@tonic-gate "about that resource.")); 8547c478bd9Sstevel@tonic-gate case CMD_VERIFY: 8557c478bd9Sstevel@tonic-gate return (gettext("Verifies current configuration " 8567c478bd9Sstevel@tonic-gate "for correctness (some resource types\n\thave " 8577c478bd9Sstevel@tonic-gate "required properties).")); 8587c478bd9Sstevel@tonic-gate case CMD_COMMIT: 8597c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), 8607c478bd9Sstevel@tonic-gate gettext("Commits current configuration. " 8617c478bd9Sstevel@tonic-gate "Configuration must be committed to\n\tbe used by " 8627c478bd9Sstevel@tonic-gate "%s. Until the configuration is committed, " 8637c478bd9Sstevel@tonic-gate "changes \n\tcan be removed with the %s " 8647c478bd9Sstevel@tonic-gate "command. This operation is\n\tattempted " 8657c478bd9Sstevel@tonic-gate "automatically upon completion of a %s " 8667c478bd9Sstevel@tonic-gate "session."), "zoneadm", cmd_to_str(CMD_REVERT), 8677c478bd9Sstevel@tonic-gate "zonecfg"); 8687c478bd9Sstevel@tonic-gate return (line); 8697c478bd9Sstevel@tonic-gate case CMD_REVERT: 8707c478bd9Sstevel@tonic-gate return (gettext("Reverts configuration back to the " 8717c478bd9Sstevel@tonic-gate "last committed state. The -F flag\n\tcan be " 8727c478bd9Sstevel@tonic-gate "used to force the action.")); 8737c478bd9Sstevel@tonic-gate case CMD_CANCEL: 8747c478bd9Sstevel@tonic-gate return (gettext("Cancels resource/property " 8757c478bd9Sstevel@tonic-gate "specification.")); 8767c478bd9Sstevel@tonic-gate case CMD_END: 8777c478bd9Sstevel@tonic-gate return (gettext("Ends resource/property " 8787c478bd9Sstevel@tonic-gate "specification.")); 8797c478bd9Sstevel@tonic-gate } 8807c478bd9Sstevel@tonic-gate /* NOTREACHED */ 8817e362f58Scomay return (NULL); 8827c478bd9Sstevel@tonic-gate } 8837c478bd9Sstevel@tonic-gate 8847c478bd9Sstevel@tonic-gate /* 8857c478bd9Sstevel@tonic-gate * Called with verbose TRUE when help is explicitly requested, FALSE for 8867c478bd9Sstevel@tonic-gate * unexpected errors. 8877c478bd9Sstevel@tonic-gate */ 8887c478bd9Sstevel@tonic-gate 8897c478bd9Sstevel@tonic-gate void 890bbec428eSgjelinek usage(boolean_t verbose, uint_t flags) 8917c478bd9Sstevel@tonic-gate { 8923042b8b5Sbatschul FILE *fp = verbose ? stdout : stderr; 8933042b8b5Sbatschul FILE *newfp; 894bbec428eSgjelinek boolean_t need_to_close = B_FALSE; 8957c478bd9Sstevel@tonic-gate char *pager; 8967c478bd9Sstevel@tonic-gate int i; 8973042b8b5Sbatschul struct stat statbuf; 8987c478bd9Sstevel@tonic-gate 8997c478bd9Sstevel@tonic-gate /* don't page error output */ 9007c478bd9Sstevel@tonic-gate if (verbose && interactive_mode) { 9017c478bd9Sstevel@tonic-gate if ((pager = getenv("PAGER")) == NULL) 9027c478bd9Sstevel@tonic-gate pager = PAGER; 9033042b8b5Sbatschul 9043042b8b5Sbatschul if (stat(pager, &statbuf) == 0) { 9053042b8b5Sbatschul if ((newfp = popen(pager, "w")) != NULL) { 9063042b8b5Sbatschul need_to_close = B_TRUE; 9073042b8b5Sbatschul fp = newfp; 9083042b8b5Sbatschul } 9093042b8b5Sbatschul } else { 9103042b8b5Sbatschul zerr(gettext("PAGER %s does not exist (%s)."), 9113042b8b5Sbatschul pager, strerror(errno)); 9127c478bd9Sstevel@tonic-gate } 9137c478bd9Sstevel@tonic-gate } 9143042b8b5Sbatschul 9157c478bd9Sstevel@tonic-gate if (flags & HELP_META) { 9167c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("More help is available for the " 9177c478bd9Sstevel@tonic-gate "following:\n")); 9187c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\n\tcommands ('%s commands')\n", 9197c478bd9Sstevel@tonic-gate cmd_to_str(CMD_HELP)); 9207c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\tsyntax ('%s syntax')\n", 9217c478bd9Sstevel@tonic-gate cmd_to_str(CMD_HELP)); 9227c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\tusage ('%s usage')\n\n", 9237c478bd9Sstevel@tonic-gate cmd_to_str(CMD_HELP)); 9247c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("You may also obtain help on any " 9257c478bd9Sstevel@tonic-gate "command by typing '%s <command-name>.'\n"), 9267c478bd9Sstevel@tonic-gate cmd_to_str(CMD_HELP)); 9277c478bd9Sstevel@tonic-gate } 9287c478bd9Sstevel@tonic-gate if (flags & HELP_RES_SCOPE) { 9297c478bd9Sstevel@tonic-gate switch (resource_scope) { 9307c478bd9Sstevel@tonic-gate case RT_FS: 9317c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is " 9327c478bd9Sstevel@tonic-gate "used to configure a file-system.\n"), 9337c478bd9Sstevel@tonic-gate rt_to_str(resource_scope)); 9347c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n")); 9357c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 9367c478bd9Sstevel@tonic-gate pt_to_str(PT_DIR), gettext("<path>")); 9377c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 9387c478bd9Sstevel@tonic-gate pt_to_str(PT_SPECIAL), gettext("<path>")); 9397c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 9407c478bd9Sstevel@tonic-gate pt_to_str(PT_RAW), gettext("<raw-device>")); 9417c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 9427c478bd9Sstevel@tonic-gate pt_to_str(PT_TYPE), gettext("<file-system type>")); 9437c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s %s\n", cmd_to_str(CMD_ADD), 9447c478bd9Sstevel@tonic-gate pt_to_str(PT_OPTIONS), 9457c478bd9Sstevel@tonic-gate gettext("<file-system options>")); 946ffbafc53Scomay (void) fprintf(fp, "\t%s %s %s\n", 947ffbafc53Scomay cmd_to_str(CMD_REMOVE), pt_to_str(PT_OPTIONS), 948ffbafc53Scomay gettext("<file-system options>")); 9497c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Consult the file-system " 9507c478bd9Sstevel@tonic-gate "specific manual page, such as mount_ufs(1M), " 9517c478bd9Sstevel@tonic-gate "for\ndetails about file-system options. Note " 9527c478bd9Sstevel@tonic-gate "that any file-system options with an\nembedded " 9537c478bd9Sstevel@tonic-gate "'=' character must be enclosed in double quotes, " 9547c478bd9Sstevel@tonic-gate /*CSTYLED*/ 9557c478bd9Sstevel@tonic-gate "such as \"%s=5\".\n"), MNTOPT_RETRY); 9567c478bd9Sstevel@tonic-gate break; 9577c478bd9Sstevel@tonic-gate case RT_IPD: 9587c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is " 9597c478bd9Sstevel@tonic-gate "used to configure a directory\ninherited from the " 9607c478bd9Sstevel@tonic-gate "global zone into a non-global zone in read-only " 9617c478bd9Sstevel@tonic-gate "mode.\n"), rt_to_str(resource_scope)); 9627c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n")); 9637c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 9647c478bd9Sstevel@tonic-gate pt_to_str(PT_DIR), gettext("<path>")); 9657c478bd9Sstevel@tonic-gate break; 9667c478bd9Sstevel@tonic-gate case RT_NET: 9677c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is " 9687c478bd9Sstevel@tonic-gate "used to configure a network interface.\n"), 9697c478bd9Sstevel@tonic-gate rt_to_str(resource_scope)); 9707c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n")); 9717c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 9727c478bd9Sstevel@tonic-gate pt_to_str(PT_ADDRESS), gettext("<IP-address>")); 9737c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 9747c478bd9Sstevel@tonic-gate pt_to_str(PT_PHYSICAL), gettext("<interface>")); 9757c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("See ifconfig(1M) for " 9767c478bd9Sstevel@tonic-gate "details of the <interface> string.\n")); 977de860bd9Sgfaden (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 978de860bd9Sgfaden pt_to_str(PT_DEFROUTER), gettext("<IP-address>")); 979de860bd9Sgfaden (void) fprintf(fp, gettext("%s %s and %s %s are valid " 980de860bd9Sgfaden "if the %s property is set to %s, otherwise they " 981de860bd9Sgfaden "must not be set.\n"), 982f4b3ec61Sdh cmd_to_str(CMD_SET), pt_to_str(PT_ADDRESS), 983de860bd9Sgfaden cmd_to_str(CMD_SET), pt_to_str(PT_DEFROUTER), 984f4b3ec61Sdh pt_to_str(PT_IPTYPE), "shared"); 9857c478bd9Sstevel@tonic-gate break; 9867c478bd9Sstevel@tonic-gate case RT_DEVICE: 9877c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is " 9887c478bd9Sstevel@tonic-gate "used to configure a device node.\n"), 9897c478bd9Sstevel@tonic-gate rt_to_str(resource_scope)); 9907c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n")); 9917c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 9927c478bd9Sstevel@tonic-gate pt_to_str(PT_MATCH), gettext("<device-path>")); 9937c478bd9Sstevel@tonic-gate break; 9947c478bd9Sstevel@tonic-gate case RT_RCTL: 9957c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is " 9967c478bd9Sstevel@tonic-gate "used to configure a resource control.\n"), 9977c478bd9Sstevel@tonic-gate rt_to_str(resource_scope)); 9987c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n")); 9997c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 10007c478bd9Sstevel@tonic-gate pt_to_str(PT_NAME), gettext("<string>")); 10017c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s (%s=%s,%s=%s,%s=%s)\n", 10027c478bd9Sstevel@tonic-gate cmd_to_str(CMD_ADD), pt_to_str(PT_VALUE), 10037c478bd9Sstevel@tonic-gate pt_to_str(PT_PRIV), gettext("<priv-value>"), 10047c478bd9Sstevel@tonic-gate pt_to_str(PT_LIMIT), gettext("<number>"), 10057c478bd9Sstevel@tonic-gate pt_to_str(PT_ACTION), gettext("<action-value>")); 1006ffbafc53Scomay (void) fprintf(fp, "\t%s %s (%s=%s,%s=%s,%s=%s)\n", 1007ffbafc53Scomay cmd_to_str(CMD_REMOVE), pt_to_str(PT_VALUE), 1008ffbafc53Scomay pt_to_str(PT_PRIV), gettext("<priv-value>"), 1009ffbafc53Scomay pt_to_str(PT_LIMIT), gettext("<number>"), 1010ffbafc53Scomay pt_to_str(PT_ACTION), gettext("<action-value>")); 10117c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s\n\t%s := privileged\n" 10127c478bd9Sstevel@tonic-gate "\t%s := none | deny\n", gettext("Where"), 10137c478bd9Sstevel@tonic-gate gettext("<priv-value>"), gettext("<action-value>")); 10147c478bd9Sstevel@tonic-gate break; 10157c478bd9Sstevel@tonic-gate case RT_ATTR: 10167c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is " 10177c478bd9Sstevel@tonic-gate "used to configure a generic attribute.\n"), 10187c478bd9Sstevel@tonic-gate rt_to_str(resource_scope)); 10197c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n")); 10207c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 10217c478bd9Sstevel@tonic-gate pt_to_str(PT_NAME), gettext("<name>")); 10227c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=boolean\n", 10237c478bd9Sstevel@tonic-gate cmd_to_str(CMD_SET), pt_to_str(PT_TYPE)); 10247c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=true | false\n", 10257c478bd9Sstevel@tonic-gate cmd_to_str(CMD_SET), pt_to_str(PT_VALUE)); 10267c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("or\n")); 10277c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=int\n", cmd_to_str(CMD_SET), 10287c478bd9Sstevel@tonic-gate pt_to_str(PT_TYPE)); 10297c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 10307c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE), gettext("<integer>")); 10317c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("or\n")); 10327c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=string\n", 10337c478bd9Sstevel@tonic-gate cmd_to_str(CMD_SET), pt_to_str(PT_TYPE)); 10347c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 10357c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE), gettext("<string>")); 10367c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("or\n")); 10377c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=uint\n", 10387c478bd9Sstevel@tonic-gate cmd_to_str(CMD_SET), pt_to_str(PT_TYPE)); 10397c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 10407c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE), gettext("<unsigned integer>")); 10417c478bd9Sstevel@tonic-gate break; 1042fa9e4066Sahrens case RT_DATASET: 1043fa9e4066Sahrens (void) fprintf(fp, gettext("The '%s' resource scope is " 1044fa9e4066Sahrens "used to export ZFS datasets.\n"), 1045fa9e4066Sahrens rt_to_str(resource_scope)); 1046fa9e4066Sahrens (void) fprintf(fp, gettext("Valid commands:\n")); 1047fa9e4066Sahrens (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 1048fa9e4066Sahrens pt_to_str(PT_NAME), gettext("<name>")); 1049fa9e4066Sahrens break; 10500209230bSgjelinek case RT_DCPU: 10510209230bSgjelinek (void) fprintf(fp, gettext("The '%s' resource scope " 10520209230bSgjelinek "configures the 'pools' facility to dedicate\na " 10530209230bSgjelinek "subset of the system's processors to this zone " 10540209230bSgjelinek "while it is running.\n"), 10550209230bSgjelinek rt_to_str(resource_scope)); 10560209230bSgjelinek (void) fprintf(fp, gettext("Valid commands:\n")); 10570209230bSgjelinek (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 10580209230bSgjelinek pt_to_str(PT_NCPUS), 10590209230bSgjelinek gettext("<unsigned integer | range>")); 10600209230bSgjelinek (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 10610209230bSgjelinek pt_to_str(PT_IMPORTANCE), 10620209230bSgjelinek gettext("<unsigned integer>")); 10630209230bSgjelinek break; 1064c97ad5cdSakolb case RT_PCAP: 1065c97ad5cdSakolb (void) fprintf(fp, gettext("The '%s' resource scope is " 1066c97ad5cdSakolb "used to set an upper limit (a cap) on the\n" 1067c97ad5cdSakolb "percentage of CPU that can be used by this zone. " 1068c97ad5cdSakolb "A '%s' value of 1\ncorresponds to one cpu. The " 1069c97ad5cdSakolb "value can be set higher than 1, up to the total\n" 1070c97ad5cdSakolb "number of CPUs on the system. The value can " 1071c97ad5cdSakolb "also be less than 1,\nrepresenting a fraction of " 1072c97ad5cdSakolb "a cpu.\n"), 1073c97ad5cdSakolb rt_to_str(resource_scope), pt_to_str(PT_NCPUS)); 1074c97ad5cdSakolb (void) fprintf(fp, gettext("Valid commands:\n")); 1075c97ad5cdSakolb (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 1076c97ad5cdSakolb pt_to_str(PT_NCPUS), gettext("<unsigned decimal>")); 1077c97ad5cdSakolb break; 10780209230bSgjelinek case RT_MCAP: 10790209230bSgjelinek (void) fprintf(fp, gettext("The '%s' resource scope is " 10800209230bSgjelinek "used to set an upper limit (a cap) on the\n" 10810209230bSgjelinek "amount of physical memory, swap space and locked " 10820209230bSgjelinek "memory that can be used by\nthis zone.\n"), 10830209230bSgjelinek rt_to_str(resource_scope)); 10840209230bSgjelinek (void) fprintf(fp, gettext("Valid commands:\n")); 10850209230bSgjelinek (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 10860209230bSgjelinek pt_to_str(PT_PHYSICAL), 10870209230bSgjelinek gettext("<qualified unsigned decimal>")); 10880209230bSgjelinek (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 10890209230bSgjelinek pt_to_str(PT_SWAP), 10900209230bSgjelinek gettext("<qualified unsigned decimal>")); 10910209230bSgjelinek (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 10920209230bSgjelinek pt_to_str(PT_LOCKED), 10930209230bSgjelinek gettext("<qualified unsigned decimal>")); 10940209230bSgjelinek break; 10957c478bd9Sstevel@tonic-gate } 10967c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("And from any resource scope, you " 10977c478bd9Sstevel@tonic-gate "can:\n")); 10987c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", cmd_to_str(CMD_END), 10997c478bd9Sstevel@tonic-gate gettext("(to conclude this operation)")); 11007c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", cmd_to_str(CMD_CANCEL), 11017c478bd9Sstevel@tonic-gate gettext("(to cancel this operation)")); 11027c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", cmd_to_str(CMD_EXIT), 11037c478bd9Sstevel@tonic-gate gettext("(to exit the zonecfg utility)")); 11047c478bd9Sstevel@tonic-gate } 11057c478bd9Sstevel@tonic-gate if (flags & HELP_USAGE) { 11067c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\t%s %s\n", gettext("usage"), 11077c478bd9Sstevel@tonic-gate execname, cmd_to_str(CMD_HELP)); 11087c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s -z <zone>\t\t\t(%s)\n", 11097c478bd9Sstevel@tonic-gate execname, gettext("interactive")); 11107c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s -z <zone> <command>\n", execname); 11117c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s -z <zone> -f <command-file>\n", 11127c478bd9Sstevel@tonic-gate execname); 11137c478bd9Sstevel@tonic-gate } 11147c478bd9Sstevel@tonic-gate if (flags & HELP_SUBCMDS) { 11157c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n\n", gettext("Commands")); 11167c478bd9Sstevel@tonic-gate for (i = 0; i <= CMD_MAX; i++) { 11177c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s\n", helptab[i].short_usage); 11187c478bd9Sstevel@tonic-gate if (verbose) 11197c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\n\n", long_help(i)); 11207c478bd9Sstevel@tonic-gate } 11217c478bd9Sstevel@tonic-gate } 11227c478bd9Sstevel@tonic-gate if (flags & HELP_SYNTAX) { 11237c478bd9Sstevel@tonic-gate if (!verbose) 11247c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\n"); 11257c478bd9Sstevel@tonic-gate (void) fprintf(fp, "<zone> := [A-Za-z0-9][A-Za-z0-9_.-]*\n"); 11267c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("\t(except the reserved words " 11277c478bd9Sstevel@tonic-gate "'%s' and anything starting with '%s')\n"), "global", 11287c478bd9Sstevel@tonic-gate "SUNW"); 11297c478bd9Sstevel@tonic-gate (void) fprintf(fp, 11307c478bd9Sstevel@tonic-gate gettext("\tName must be less than %d characters.\n"), 11317c478bd9Sstevel@tonic-gate ZONENAME_MAX); 11327c478bd9Sstevel@tonic-gate if (verbose) 11337c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\n"); 11347c478bd9Sstevel@tonic-gate } 11357c478bd9Sstevel@tonic-gate if (flags & HELP_NETADDR) { 11367c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("\n<net-addr> :=")); 11377c478bd9Sstevel@tonic-gate (void) fprintf(fp, 11387c478bd9Sstevel@tonic-gate gettext("\t<IPv4-address>[/<IPv4-prefix-length>] |\n")); 11397c478bd9Sstevel@tonic-gate (void) fprintf(fp, 11407c478bd9Sstevel@tonic-gate gettext("\t\t<IPv6-address>/<IPv6-prefix-length> |\n")); 11417c478bd9Sstevel@tonic-gate (void) fprintf(fp, 11427c478bd9Sstevel@tonic-gate gettext("\t\t<hostname>[/<IPv4-prefix-length>]\n")); 11437c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("See inet(3SOCKET) for IPv4 and " 11447c478bd9Sstevel@tonic-gate "IPv6 address syntax.\n")); 11457c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("<IPv4-prefix-length> := [0-32]\n")); 11467c478bd9Sstevel@tonic-gate (void) fprintf(fp, 11477c478bd9Sstevel@tonic-gate gettext("<IPv6-prefix-length> := [0-128]\n")); 11487c478bd9Sstevel@tonic-gate (void) fprintf(fp, 11497c478bd9Sstevel@tonic-gate gettext("<hostname> := [A-Za-z0-9][A-Za-z0-9-.]*\n")); 11507c478bd9Sstevel@tonic-gate } 11517c478bd9Sstevel@tonic-gate if (flags & HELP_RESOURCES) { 11529e7542f4Sdp (void) fprintf(fp, "<%s> := %s | %s | %s | %s | %s | %s |\n\t" 1153c97ad5cdSakolb "%s | %s | %s | %s\n\n", 11547c478bd9Sstevel@tonic-gate gettext("resource type"), rt_to_str(RT_FS), 11557c478bd9Sstevel@tonic-gate rt_to_str(RT_IPD), rt_to_str(RT_NET), rt_to_str(RT_DEVICE), 11569e7542f4Sdp rt_to_str(RT_RCTL), rt_to_str(RT_ATTR), 11570209230bSgjelinek rt_to_str(RT_DATASET), rt_to_str(RT_DCPU), 1158c97ad5cdSakolb rt_to_str(RT_PCAP), rt_to_str(RT_MCAP)); 11597c478bd9Sstevel@tonic-gate } 11607c478bd9Sstevel@tonic-gate if (flags & HELP_PROPS) { 11617c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("For resource type ... there are " 11627c478bd9Sstevel@tonic-gate "property types ...:\n")); 1163087719fdSdp (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 1164087719fdSdp pt_to_str(PT_ZONENAME)); 11657c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11667c478bd9Sstevel@tonic-gate pt_to_str(PT_ZONEPATH)); 11679acbbeafSnn (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11689acbbeafSnn pt_to_str(PT_BRAND)); 11697c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11707c478bd9Sstevel@tonic-gate pt_to_str(PT_AUTOBOOT)); 11713f2f09c1Sdp (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11723f2f09c1Sdp pt_to_str(PT_BOOTARGS)); 11737c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11747c478bd9Sstevel@tonic-gate pt_to_str(PT_POOL)); 1175ffbafc53Scomay (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 1176ffbafc53Scomay pt_to_str(PT_LIMITPRIV)); 11770209230bSgjelinek (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11780209230bSgjelinek pt_to_str(PT_SCHED)); 1179f4b3ec61Sdh (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 1180f4b3ec61Sdh pt_to_str(PT_IPTYPE)); 11815679c89fSjv (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11825679c89fSjv pt_to_str(PT_HOSTID)); 11830209230bSgjelinek (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11840209230bSgjelinek pt_to_str(PT_MAXLWPS)); 11850209230bSgjelinek (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11860209230bSgjelinek pt_to_str(PT_MAXSHMMEM)); 11870209230bSgjelinek (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11880209230bSgjelinek pt_to_str(PT_MAXSHMIDS)); 11890209230bSgjelinek (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11900209230bSgjelinek pt_to_str(PT_MAXMSGIDS)); 11910209230bSgjelinek (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11920209230bSgjelinek pt_to_str(PT_MAXSEMIDS)); 11930209230bSgjelinek (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11940209230bSgjelinek pt_to_str(PT_SHARES)); 1195*6d4d1c0dSbatschul (void) fprintf(fp, "\t%s\t\t%s, %s, %s, %s, %s\n", 1196*6d4d1c0dSbatschul rt_to_str(RT_FS), pt_to_str(PT_DIR), 1197*6d4d1c0dSbatschul pt_to_str(PT_SPECIAL), pt_to_str(PT_RAW), 1198*6d4d1c0dSbatschul pt_to_str(PT_TYPE), pt_to_str(PT_OPTIONS)); 11997c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", rt_to_str(RT_IPD), 12007c478bd9Sstevel@tonic-gate pt_to_str(PT_DIR)); 1201de860bd9Sgfaden (void) fprintf(fp, "\t%s\t\t%s, %s, %s\n", rt_to_str(RT_NET), 1202de860bd9Sgfaden pt_to_str(PT_ADDRESS), pt_to_str(PT_PHYSICAL), 1203de860bd9Sgfaden pt_to_str(PT_DEFROUTER)); 12047c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t\t%s\n", rt_to_str(RT_DEVICE), 12057c478bd9Sstevel@tonic-gate pt_to_str(PT_MATCH)); 12067c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t\t%s, %s\n", rt_to_str(RT_RCTL), 12077c478bd9Sstevel@tonic-gate pt_to_str(PT_NAME), pt_to_str(PT_VALUE)); 12087c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t\t%s, %s, %s\n", rt_to_str(RT_ATTR), 12097c478bd9Sstevel@tonic-gate pt_to_str(PT_NAME), pt_to_str(PT_TYPE), 12107c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE)); 1211fa9e4066Sahrens (void) fprintf(fp, "\t%s\t\t%s\n", rt_to_str(RT_DATASET), 1212fa9e4066Sahrens pt_to_str(PT_NAME)); 12130209230bSgjelinek (void) fprintf(fp, "\t%s\t%s, %s\n", rt_to_str(RT_DCPU), 12140209230bSgjelinek pt_to_str(PT_NCPUS), pt_to_str(PT_IMPORTANCE)); 1215c97ad5cdSakolb (void) fprintf(fp, "\t%s\t%s\n", rt_to_str(RT_PCAP), 1216c97ad5cdSakolb pt_to_str(PT_NCPUS)); 12170209230bSgjelinek (void) fprintf(fp, "\t%s\t%s, %s, %s\n", rt_to_str(RT_MCAP), 12180209230bSgjelinek pt_to_str(PT_PHYSICAL), pt_to_str(PT_SWAP), 12190209230bSgjelinek pt_to_str(PT_LOCKED)); 12207c478bd9Sstevel@tonic-gate } 12217c478bd9Sstevel@tonic-gate if (need_to_close) 12227c478bd9Sstevel@tonic-gate (void) pclose(fp); 12237c478bd9Sstevel@tonic-gate } 12247c478bd9Sstevel@tonic-gate 12257c478bd9Sstevel@tonic-gate static void 1226bbec428eSgjelinek zone_perror(char *prefix, int err, boolean_t set_saw) 12277c478bd9Sstevel@tonic-gate { 12287c478bd9Sstevel@tonic-gate zerr("%s: %s", prefix, zonecfg_strerror(err)); 12297c478bd9Sstevel@tonic-gate if (set_saw) 1230bbec428eSgjelinek saw_error = B_TRUE; 12317c478bd9Sstevel@tonic-gate } 12327c478bd9Sstevel@tonic-gate 12337c478bd9Sstevel@tonic-gate /* 12347c478bd9Sstevel@tonic-gate * zone_perror() expects a single string, but for remove and select 12357c478bd9Sstevel@tonic-gate * we have both the command and the resource type, so this wrapper 12367c478bd9Sstevel@tonic-gate * function serves the same purpose in a slightly different way. 12377c478bd9Sstevel@tonic-gate */ 12387c478bd9Sstevel@tonic-gate 12397c478bd9Sstevel@tonic-gate static void 1240bbec428eSgjelinek z_cmd_rt_perror(int cmd_num, int res_num, int err, boolean_t set_saw) 12417c478bd9Sstevel@tonic-gate { 12427c478bd9Sstevel@tonic-gate zerr("%s %s: %s", cmd_to_str(cmd_num), rt_to_str(res_num), 12437c478bd9Sstevel@tonic-gate zonecfg_strerror(err)); 12447c478bd9Sstevel@tonic-gate if (set_saw) 1245bbec428eSgjelinek saw_error = B_TRUE; 12467c478bd9Sstevel@tonic-gate } 12477c478bd9Sstevel@tonic-gate 12487c478bd9Sstevel@tonic-gate /* returns Z_OK if successful, Z_foo from <libzonecfg.h> otherwise */ 12497c478bd9Sstevel@tonic-gate static int 1250bbec428eSgjelinek initialize(boolean_t handle_expected) 12517c478bd9Sstevel@tonic-gate { 12527c478bd9Sstevel@tonic-gate int err; 12539acbbeafSnn char brandname[MAXNAMELEN]; 12547c478bd9Sstevel@tonic-gate 12557c478bd9Sstevel@tonic-gate if (zonecfg_check_handle(handle) != Z_OK) { 12567c478bd9Sstevel@tonic-gate if ((err = zonecfg_get_handle(zone, handle)) == Z_OK) { 1257bbec428eSgjelinek got_handle = B_TRUE; 12589acbbeafSnn if (zonecfg_get_brand(handle, brandname, 12599acbbeafSnn sizeof (brandname)) != Z_OK) { 12609acbbeafSnn zerr("Zone %s is inconsistent: missing " 12619acbbeafSnn "brand attribute", zone); 12629acbbeafSnn exit(Z_ERR); 12639acbbeafSnn } 12649acbbeafSnn if ((brand = brand_open(brandname)) == NULL) { 12659acbbeafSnn zerr("Zone %s uses non-existent brand \"%s\"." 12669acbbeafSnn " Unable to continue", zone, brandname); 12679acbbeafSnn exit(Z_ERR); 12689acbbeafSnn } 12690209230bSgjelinek } else if (global_zone && err == Z_NO_ZONE && !got_handle && 12700209230bSgjelinek !read_only_mode) { 12710209230bSgjelinek /* 12720209230bSgjelinek * We implicitly create the global zone config if it 12730209230bSgjelinek * doesn't exist. 12740209230bSgjelinek */ 12750209230bSgjelinek zone_dochandle_t tmphandle; 12760209230bSgjelinek 12770209230bSgjelinek if ((tmphandle = zonecfg_init_handle()) == NULL) { 1278bbec428eSgjelinek zone_perror(execname, Z_NOMEM, B_TRUE); 12790209230bSgjelinek exit(Z_ERR); 12800209230bSgjelinek } 12810209230bSgjelinek 12820209230bSgjelinek err = zonecfg_get_template_handle("SUNWblank", zone, 12830209230bSgjelinek tmphandle); 12840209230bSgjelinek 12850209230bSgjelinek if (err != Z_OK) { 12860209230bSgjelinek zonecfg_fini_handle(tmphandle); 1287bbec428eSgjelinek zone_perror("SUNWblank", err, B_TRUE); 12880209230bSgjelinek return (err); 12890209230bSgjelinek } 12900209230bSgjelinek 1291bbec428eSgjelinek need_to_commit = B_TRUE; 12920209230bSgjelinek zonecfg_fini_handle(handle); 12930209230bSgjelinek handle = tmphandle; 1294bbec428eSgjelinek got_handle = B_TRUE; 12950209230bSgjelinek 12967c478bd9Sstevel@tonic-gate } else { 12977c478bd9Sstevel@tonic-gate zone_perror(zone, err, handle_expected || got_handle); 12987c478bd9Sstevel@tonic-gate if (err == Z_NO_ZONE && !got_handle && 12997c478bd9Sstevel@tonic-gate interactive_mode && !read_only_mode) 13007c478bd9Sstevel@tonic-gate (void) printf(gettext("Use '%s' to begin " 13017c478bd9Sstevel@tonic-gate "configuring a new zone.\n"), 13027c478bd9Sstevel@tonic-gate cmd_to_str(CMD_CREATE)); 13037c478bd9Sstevel@tonic-gate return (err); 13047c478bd9Sstevel@tonic-gate } 13057c478bd9Sstevel@tonic-gate } 13067c478bd9Sstevel@tonic-gate return (Z_OK); 13077c478bd9Sstevel@tonic-gate } 13087c478bd9Sstevel@tonic-gate 1309bbec428eSgjelinek static boolean_t 1310087719fdSdp state_atleast(zone_state_t state) 1311087719fdSdp { 1312087719fdSdp zone_state_t state_num; 1313087719fdSdp int err; 1314087719fdSdp 1315087719fdSdp if ((err = zone_get_state(zone, &state_num)) != Z_OK) { 1316087719fdSdp /* all states are greater than "non-existent" */ 1317087719fdSdp if (err == Z_NO_ZONE) 1318087719fdSdp return (B_FALSE); 1319087719fdSdp zerr(gettext("Unexpectedly failed to determine state " 1320087719fdSdp "of zone %s: %s"), zone, zonecfg_strerror(err)); 1321087719fdSdp exit(Z_ERR); 1322087719fdSdp } 1323087719fdSdp return (state_num >= state); 1324087719fdSdp } 1325087719fdSdp 13267c478bd9Sstevel@tonic-gate /* 13277c478bd9Sstevel@tonic-gate * short_usage() is for bad syntax: getopt() issues, too many arguments, etc. 13287c478bd9Sstevel@tonic-gate */ 13297c478bd9Sstevel@tonic-gate 13307c478bd9Sstevel@tonic-gate void 13317c478bd9Sstevel@tonic-gate short_usage(int command) 13327c478bd9Sstevel@tonic-gate { 13337c478bd9Sstevel@tonic-gate /* lex_lineno has already been incremented in the lexer; compensate */ 13347c478bd9Sstevel@tonic-gate if (cmd_file_mode) { 13357c478bd9Sstevel@tonic-gate if (strcmp(cmd_file_name, "-") == 0) 13367c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 13377c478bd9Sstevel@tonic-gate gettext("syntax error on line %d\n"), 13387c478bd9Sstevel@tonic-gate lex_lineno - 1); 13397c478bd9Sstevel@tonic-gate else 13407c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 13417c478bd9Sstevel@tonic-gate gettext("syntax error on line %d of %s\n"), 13427c478bd9Sstevel@tonic-gate lex_lineno - 1, cmd_file_name); 13437c478bd9Sstevel@tonic-gate } 13447c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s:\n%s\n", gettext("usage"), 13457c478bd9Sstevel@tonic-gate helptab[command].short_usage); 1346bbec428eSgjelinek saw_error = B_TRUE; 13477c478bd9Sstevel@tonic-gate } 13487c478bd9Sstevel@tonic-gate 13497c478bd9Sstevel@tonic-gate /* 13507c478bd9Sstevel@tonic-gate * long_usage() is for bad semantics: e.g., wrong property type for a given 13517c478bd9Sstevel@tonic-gate * resource type. It is also used by longer_usage() below. 13527c478bd9Sstevel@tonic-gate */ 13537c478bd9Sstevel@tonic-gate 13547c478bd9Sstevel@tonic-gate void 1355bbec428eSgjelinek long_usage(uint_t cmd_num, boolean_t set_saw) 13567c478bd9Sstevel@tonic-gate { 13577c478bd9Sstevel@tonic-gate (void) fprintf(set_saw ? stderr : stdout, "%s:\n%s\n", gettext("usage"), 13587c478bd9Sstevel@tonic-gate helptab[cmd_num].short_usage); 13597c478bd9Sstevel@tonic-gate (void) fprintf(set_saw ? stderr : stdout, "\t%s\n", long_help(cmd_num)); 13607c478bd9Sstevel@tonic-gate if (set_saw) 1361bbec428eSgjelinek saw_error = B_TRUE; 13627c478bd9Sstevel@tonic-gate } 13637c478bd9Sstevel@tonic-gate 13647c478bd9Sstevel@tonic-gate /* 13657c478bd9Sstevel@tonic-gate * longer_usage() is for 'help foo' and 'foo -?': call long_usage() and also 13667c478bd9Sstevel@tonic-gate * any extra usage() flags as appropriate for whatever command. 13677c478bd9Sstevel@tonic-gate */ 13687c478bd9Sstevel@tonic-gate 13697c478bd9Sstevel@tonic-gate void 13707c478bd9Sstevel@tonic-gate longer_usage(uint_t cmd_num) 13717c478bd9Sstevel@tonic-gate { 1372bbec428eSgjelinek long_usage(cmd_num, B_FALSE); 13737c478bd9Sstevel@tonic-gate if (helptab[cmd_num].flags != 0) { 13747c478bd9Sstevel@tonic-gate (void) printf("\n"); 1375bbec428eSgjelinek usage(B_TRUE, helptab[cmd_num].flags); 13767c478bd9Sstevel@tonic-gate } 13777c478bd9Sstevel@tonic-gate } 13787c478bd9Sstevel@tonic-gate 13797c478bd9Sstevel@tonic-gate /* 13807c478bd9Sstevel@tonic-gate * scope_usage() is simply used when a command is called from the wrong scope. 13817c478bd9Sstevel@tonic-gate */ 13827c478bd9Sstevel@tonic-gate 13837c478bd9Sstevel@tonic-gate static void 13847c478bd9Sstevel@tonic-gate scope_usage(uint_t cmd_num) 13857c478bd9Sstevel@tonic-gate { 13867c478bd9Sstevel@tonic-gate zerr(gettext("The %s command only makes sense in the %s scope."), 13877c478bd9Sstevel@tonic-gate cmd_to_str(cmd_num), 13887c478bd9Sstevel@tonic-gate global_scope ? gettext("resource") : gettext("global")); 1389bbec428eSgjelinek saw_error = B_TRUE; 13907c478bd9Sstevel@tonic-gate } 13917c478bd9Sstevel@tonic-gate 13927c478bd9Sstevel@tonic-gate /* 1393bbec428eSgjelinek * On input, B_TRUE => yes, B_FALSE => no. 1394bbec428eSgjelinek * On return, B_TRUE => 1, B_FALSE => no, could not ask => -1. 13957c478bd9Sstevel@tonic-gate */ 13967c478bd9Sstevel@tonic-gate 13977c478bd9Sstevel@tonic-gate static int 1398bbec428eSgjelinek ask_yesno(boolean_t default_answer, const char *question) 13997c478bd9Sstevel@tonic-gate { 14007c478bd9Sstevel@tonic-gate char line[64]; /* should be enough to answer yes or no */ 14017c478bd9Sstevel@tonic-gate 14027c478bd9Sstevel@tonic-gate if (!ok_to_prompt) { 1403bbec428eSgjelinek saw_error = B_TRUE; 14047c478bd9Sstevel@tonic-gate return (-1); 14057c478bd9Sstevel@tonic-gate } 14067c478bd9Sstevel@tonic-gate for (;;) { 1407087719fdSdp if (printf("%s (%s)? ", question, 1408087719fdSdp default_answer ? "[y]/n" : "y/[n]") < 0) 1409087719fdSdp return (-1); 1410087719fdSdp if (fgets(line, sizeof (line), stdin) == NULL) 1411087719fdSdp return (-1); 1412087719fdSdp 1413087719fdSdp if (line[0] == '\n') 14147c478bd9Sstevel@tonic-gate return (default_answer ? 1 : 0); 14157c478bd9Sstevel@tonic-gate if (tolower(line[0]) == 'y') 14167c478bd9Sstevel@tonic-gate return (1); 14177c478bd9Sstevel@tonic-gate if (tolower(line[0]) == 'n') 14187c478bd9Sstevel@tonic-gate return (0); 14197c478bd9Sstevel@tonic-gate } 14207c478bd9Sstevel@tonic-gate } 14217c478bd9Sstevel@tonic-gate 14227c478bd9Sstevel@tonic-gate /* 14237c478bd9Sstevel@tonic-gate * Prints warning if zone already exists. 14247c478bd9Sstevel@tonic-gate * In interactive mode, prompts if we should continue anyway and returns Z_OK 14257c478bd9Sstevel@tonic-gate * if so, Z_ERR if not. In non-interactive mode, exits with Z_ERR. 14267c478bd9Sstevel@tonic-gate * 14277c478bd9Sstevel@tonic-gate * Note that if a zone exists and its state is >= INSTALLED, an error message 14287c478bd9Sstevel@tonic-gate * will be printed and this function will return Z_ERR regardless of mode. 14297c478bd9Sstevel@tonic-gate */ 14307c478bd9Sstevel@tonic-gate 14317c478bd9Sstevel@tonic-gate static int 1432bbec428eSgjelinek check_if_zone_already_exists(boolean_t force) 14337c478bd9Sstevel@tonic-gate { 14347c478bd9Sstevel@tonic-gate char line[ZONENAME_MAX + 128]; /* enough to ask a question */ 14357c478bd9Sstevel@tonic-gate zone_dochandle_t tmphandle; 14367c478bd9Sstevel@tonic-gate int res, answer; 14377c478bd9Sstevel@tonic-gate 14387c478bd9Sstevel@tonic-gate if ((tmphandle = zonecfg_init_handle()) == NULL) { 1439bbec428eSgjelinek zone_perror(execname, Z_NOMEM, B_TRUE); 14407c478bd9Sstevel@tonic-gate exit(Z_ERR); 14417c478bd9Sstevel@tonic-gate } 14427c478bd9Sstevel@tonic-gate res = zonecfg_get_handle(zone, tmphandle); 14437c478bd9Sstevel@tonic-gate zonecfg_fini_handle(tmphandle); 1444087719fdSdp if (res != Z_OK) 14457c478bd9Sstevel@tonic-gate return (Z_OK); 1446087719fdSdp 1447087719fdSdp if (state_atleast(ZONE_STATE_INSTALLED)) { 14487c478bd9Sstevel@tonic-gate zerr(gettext("Zone %s already installed; %s not allowed."), 14497c478bd9Sstevel@tonic-gate zone, cmd_to_str(CMD_CREATE)); 14507c478bd9Sstevel@tonic-gate return (Z_ERR); 14517c478bd9Sstevel@tonic-gate } 14527c478bd9Sstevel@tonic-gate 14537c478bd9Sstevel@tonic-gate if (force) { 14547c478bd9Sstevel@tonic-gate (void) printf(gettext("Zone %s already exists; overwriting.\n"), 14557c478bd9Sstevel@tonic-gate zone); 14567c478bd9Sstevel@tonic-gate return (Z_OK); 14577c478bd9Sstevel@tonic-gate } 14587c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), 14597c478bd9Sstevel@tonic-gate gettext("Zone %s already exists; %s anyway"), zone, 14607c478bd9Sstevel@tonic-gate cmd_to_str(CMD_CREATE)); 1461bbec428eSgjelinek if ((answer = ask_yesno(B_FALSE, line)) == -1) { 14627c478bd9Sstevel@tonic-gate zerr(gettext("Zone exists, input not from terminal and -F not " 14637c478bd9Sstevel@tonic-gate "specified:\n%s command ignored, exiting."), 14647c478bd9Sstevel@tonic-gate cmd_to_str(CMD_CREATE)); 14657c478bd9Sstevel@tonic-gate exit(Z_ERR); 14667c478bd9Sstevel@tonic-gate } 14677c478bd9Sstevel@tonic-gate return (answer == 1 ? Z_OK : Z_ERR); 14687c478bd9Sstevel@tonic-gate } 14697c478bd9Sstevel@tonic-gate 1470bbec428eSgjelinek static boolean_t 14717c478bd9Sstevel@tonic-gate zone_is_read_only(int cmd_num) 14727c478bd9Sstevel@tonic-gate { 14737c478bd9Sstevel@tonic-gate if (strncmp(zone, "SUNW", 4) == 0) { 14747c478bd9Sstevel@tonic-gate zerr(gettext("%s: zones beginning with SUNW are read-only."), 14757c478bd9Sstevel@tonic-gate zone); 1476bbec428eSgjelinek saw_error = B_TRUE; 1477bbec428eSgjelinek return (B_TRUE); 14787c478bd9Sstevel@tonic-gate } 14797c478bd9Sstevel@tonic-gate if (read_only_mode) { 14807c478bd9Sstevel@tonic-gate zerr(gettext("%s: cannot %s in read-only mode."), zone, 14817c478bd9Sstevel@tonic-gate cmd_to_str(cmd_num)); 1482bbec428eSgjelinek saw_error = B_TRUE; 1483bbec428eSgjelinek return (B_TRUE); 14847c478bd9Sstevel@tonic-gate } 1485bbec428eSgjelinek return (B_FALSE); 14867c478bd9Sstevel@tonic-gate } 14877c478bd9Sstevel@tonic-gate 14887c478bd9Sstevel@tonic-gate /* 14897c478bd9Sstevel@tonic-gate * Create a new configuration. 14907c478bd9Sstevel@tonic-gate */ 14917c478bd9Sstevel@tonic-gate void 14927c478bd9Sstevel@tonic-gate create_func(cmd_t *cmd) 14937c478bd9Sstevel@tonic-gate { 14947c478bd9Sstevel@tonic-gate int err, arg; 14957c478bd9Sstevel@tonic-gate char zone_template[ZONENAME_MAX]; 1496ee519a1fSgjelinek char attach_path[MAXPATHLEN]; 14977c478bd9Sstevel@tonic-gate zone_dochandle_t tmphandle; 1498bbec428eSgjelinek boolean_t force = B_FALSE; 1499bbec428eSgjelinek boolean_t attach = B_FALSE; 1500bbec428eSgjelinek boolean_t arg_err = B_FALSE; 15017c478bd9Sstevel@tonic-gate 15027c478bd9Sstevel@tonic-gate assert(cmd != NULL); 15037c478bd9Sstevel@tonic-gate 15047c478bd9Sstevel@tonic-gate /* This is the default if no arguments are given. */ 15057c478bd9Sstevel@tonic-gate (void) strlcpy(zone_template, "SUNWdefault", sizeof (zone_template)); 15067c478bd9Sstevel@tonic-gate 15077c478bd9Sstevel@tonic-gate optind = 0; 15089acbbeafSnn while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?a:bFt:")) 15099acbbeafSnn != EOF) { 15107c478bd9Sstevel@tonic-gate switch (arg) { 15117c478bd9Sstevel@tonic-gate case '?': 15127c478bd9Sstevel@tonic-gate if (optopt == '?') 15137c478bd9Sstevel@tonic-gate longer_usage(CMD_CREATE); 15147c478bd9Sstevel@tonic-gate else 15157c478bd9Sstevel@tonic-gate short_usage(CMD_CREATE); 1516bbec428eSgjelinek arg_err = B_TRUE; 15177ec75eb8Sgjelinek break; 1518ee519a1fSgjelinek case 'a': 1519ee519a1fSgjelinek (void) strlcpy(attach_path, optarg, 1520ee519a1fSgjelinek sizeof (attach_path)); 1521bbec428eSgjelinek attach = B_TRUE; 1522ee519a1fSgjelinek break; 15237c478bd9Sstevel@tonic-gate case 'b': 15247c478bd9Sstevel@tonic-gate (void) strlcpy(zone_template, "SUNWblank", 15257c478bd9Sstevel@tonic-gate sizeof (zone_template)); 15267c478bd9Sstevel@tonic-gate break; 15277c478bd9Sstevel@tonic-gate case 'F': 1528bbec428eSgjelinek force = B_TRUE; 15297c478bd9Sstevel@tonic-gate break; 15307c478bd9Sstevel@tonic-gate case 't': 15317c478bd9Sstevel@tonic-gate (void) strlcpy(zone_template, optarg, 15327c478bd9Sstevel@tonic-gate sizeof (zone_template)); 15337c478bd9Sstevel@tonic-gate break; 15347c478bd9Sstevel@tonic-gate default: 15357c478bd9Sstevel@tonic-gate short_usage(CMD_CREATE); 1536bbec428eSgjelinek arg_err = B_TRUE; 15377ec75eb8Sgjelinek break; 15387c478bd9Sstevel@tonic-gate } 15397c478bd9Sstevel@tonic-gate } 15407ec75eb8Sgjelinek if (arg_err) 15417ec75eb8Sgjelinek return; 15427ec75eb8Sgjelinek 15437c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 15447c478bd9Sstevel@tonic-gate short_usage(CMD_CREATE); 15457c478bd9Sstevel@tonic-gate return; 15467c478bd9Sstevel@tonic-gate } 15477c478bd9Sstevel@tonic-gate 15487c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_CREATE)) 15497c478bd9Sstevel@tonic-gate return; 15507c478bd9Sstevel@tonic-gate 15517c478bd9Sstevel@tonic-gate if (check_if_zone_already_exists(force) != Z_OK) 15527c478bd9Sstevel@tonic-gate return; 15537c478bd9Sstevel@tonic-gate 15547c478bd9Sstevel@tonic-gate /* 15557c478bd9Sstevel@tonic-gate * Get a temporary handle first. If that fails, the old handle 15567c478bd9Sstevel@tonic-gate * will not be lost. Then finish whichever one we don't need, 15577c478bd9Sstevel@tonic-gate * to avoid leaks. Then get the handle for zone_template, and 15587c478bd9Sstevel@tonic-gate * set the name to zone: this "copy, rename" method is how 15597c478bd9Sstevel@tonic-gate * create -[b|t] works. 15607c478bd9Sstevel@tonic-gate */ 15617c478bd9Sstevel@tonic-gate if ((tmphandle = zonecfg_init_handle()) == NULL) { 1562bbec428eSgjelinek zone_perror(execname, Z_NOMEM, B_TRUE); 15637c478bd9Sstevel@tonic-gate exit(Z_ERR); 15647c478bd9Sstevel@tonic-gate } 1565ee519a1fSgjelinek 1566ee519a1fSgjelinek if (attach) 156716ab8c7bSgjelinek err = zonecfg_get_attach_handle(attach_path, ZONE_DETACHED, 156816ab8c7bSgjelinek zone, B_FALSE, tmphandle); 1569ee519a1fSgjelinek else 1570ee519a1fSgjelinek err = zonecfg_get_template_handle(zone_template, zone, 1571ee519a1fSgjelinek tmphandle); 1572ee519a1fSgjelinek 1573ee519a1fSgjelinek if (err != Z_OK) { 15747c478bd9Sstevel@tonic-gate zonecfg_fini_handle(tmphandle); 1575ee519a1fSgjelinek if (attach && err == Z_NO_ZONE) 1576ee519a1fSgjelinek (void) fprintf(stderr, gettext("invalid path to " 1577ee519a1fSgjelinek "detached zone\n")); 1578ee519a1fSgjelinek else if (attach && err == Z_INVALID_DOCUMENT) 1579ee519a1fSgjelinek (void) fprintf(stderr, gettext("Cannot attach to an " 1580ee519a1fSgjelinek "earlier release of the operating system\n")); 1581ee519a1fSgjelinek else 1582bbec428eSgjelinek zone_perror(zone_template, err, B_TRUE); 15837c478bd9Sstevel@tonic-gate return; 15847c478bd9Sstevel@tonic-gate } 1585087719fdSdp 1586bbec428eSgjelinek need_to_commit = B_TRUE; 15877c478bd9Sstevel@tonic-gate zonecfg_fini_handle(handle); 15887c478bd9Sstevel@tonic-gate handle = tmphandle; 1589bbec428eSgjelinek got_handle = B_TRUE; 15907c478bd9Sstevel@tonic-gate } 15917c478bd9Sstevel@tonic-gate 15927c478bd9Sstevel@tonic-gate /* 15937c478bd9Sstevel@tonic-gate * This malloc()'s memory, which must be freed by the caller. 15947c478bd9Sstevel@tonic-gate */ 15957c478bd9Sstevel@tonic-gate static char * 15967c478bd9Sstevel@tonic-gate quoteit(char *instr) 15977c478bd9Sstevel@tonic-gate { 15987c478bd9Sstevel@tonic-gate char *outstr; 15997c478bd9Sstevel@tonic-gate size_t outstrsize = strlen(instr) + 3; /* 2 quotes + '\0' */ 16007c478bd9Sstevel@tonic-gate 16017c478bd9Sstevel@tonic-gate if ((outstr = malloc(outstrsize)) == NULL) { 1602bbec428eSgjelinek zone_perror(zone, Z_NOMEM, B_FALSE); 16037c478bd9Sstevel@tonic-gate exit(Z_ERR); 16047c478bd9Sstevel@tonic-gate } 16057c478bd9Sstevel@tonic-gate if (strchr(instr, ' ') == NULL) { 16067c478bd9Sstevel@tonic-gate (void) strlcpy(outstr, instr, outstrsize); 16077c478bd9Sstevel@tonic-gate return (outstr); 16087c478bd9Sstevel@tonic-gate } 16097c478bd9Sstevel@tonic-gate (void) snprintf(outstr, outstrsize, "\"%s\"", instr); 16107c478bd9Sstevel@tonic-gate return (outstr); 16117c478bd9Sstevel@tonic-gate } 16127c478bd9Sstevel@tonic-gate 16137c478bd9Sstevel@tonic-gate static void 16147c478bd9Sstevel@tonic-gate export_prop(FILE *of, int prop_num, char *prop_id) 16157c478bd9Sstevel@tonic-gate { 16167c478bd9Sstevel@tonic-gate char *quote_str; 16177c478bd9Sstevel@tonic-gate 16187c478bd9Sstevel@tonic-gate if (strlen(prop_id) == 0) 16197c478bd9Sstevel@tonic-gate return; 16207c478bd9Sstevel@tonic-gate quote_str = quoteit(prop_id); 16217c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 16227c478bd9Sstevel@tonic-gate pt_to_str(prop_num), quote_str); 16237c478bd9Sstevel@tonic-gate free(quote_str); 16247c478bd9Sstevel@tonic-gate } 16257c478bd9Sstevel@tonic-gate 16267c478bd9Sstevel@tonic-gate void 16277c478bd9Sstevel@tonic-gate export_func(cmd_t *cmd) 16287c478bd9Sstevel@tonic-gate { 16297c478bd9Sstevel@tonic-gate struct zone_nwiftab nwiftab; 16307c478bd9Sstevel@tonic-gate struct zone_fstab fstab; 16317c478bd9Sstevel@tonic-gate struct zone_devtab devtab; 16327c478bd9Sstevel@tonic-gate struct zone_attrtab attrtab; 16337c478bd9Sstevel@tonic-gate struct zone_rctltab rctltab; 1634fa9e4066Sahrens struct zone_dstab dstab; 16350209230bSgjelinek struct zone_psettab psettab; 16360209230bSgjelinek struct zone_mcaptab mcaptab; 16377c478bd9Sstevel@tonic-gate struct zone_rctlvaltab *valptr; 16387c478bd9Sstevel@tonic-gate int err, arg; 16397c478bd9Sstevel@tonic-gate char zonepath[MAXPATHLEN], outfile[MAXPATHLEN], pool[MAXNAMELEN]; 16403f2f09c1Sdp char bootargs[BOOTARGS_MAX]; 16410209230bSgjelinek char sched[MAXNAMELEN]; 16429acbbeafSnn char brand[MAXNAMELEN]; 16435679c89fSjv char hostidp[HW_HOSTID_LEN]; 1644ffbafc53Scomay char *limitpriv; 16457c478bd9Sstevel@tonic-gate FILE *of; 16467c478bd9Sstevel@tonic-gate boolean_t autoboot; 1647f4b3ec61Sdh zone_iptype_t iptype; 1648bbec428eSgjelinek boolean_t need_to_close = B_FALSE; 1649bbec428eSgjelinek boolean_t arg_err = B_FALSE; 16507c478bd9Sstevel@tonic-gate 16517c478bd9Sstevel@tonic-gate assert(cmd != NULL); 16527c478bd9Sstevel@tonic-gate 16537c478bd9Sstevel@tonic-gate outfile[0] = '\0'; 16547c478bd9Sstevel@tonic-gate optind = 0; 16557c478bd9Sstevel@tonic-gate while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?f:")) != EOF) { 16567c478bd9Sstevel@tonic-gate switch (arg) { 16577c478bd9Sstevel@tonic-gate case '?': 16587c478bd9Sstevel@tonic-gate if (optopt == '?') 16597c478bd9Sstevel@tonic-gate longer_usage(CMD_EXPORT); 16607c478bd9Sstevel@tonic-gate else 16617c478bd9Sstevel@tonic-gate short_usage(CMD_EXPORT); 1662bbec428eSgjelinek arg_err = B_TRUE; 16637ec75eb8Sgjelinek break; 16647c478bd9Sstevel@tonic-gate case 'f': 16657c478bd9Sstevel@tonic-gate (void) strlcpy(outfile, optarg, sizeof (outfile)); 16667c478bd9Sstevel@tonic-gate break; 16677c478bd9Sstevel@tonic-gate default: 16687c478bd9Sstevel@tonic-gate short_usage(CMD_EXPORT); 1669bbec428eSgjelinek arg_err = B_TRUE; 16707ec75eb8Sgjelinek break; 16717c478bd9Sstevel@tonic-gate } 16727c478bd9Sstevel@tonic-gate } 16737ec75eb8Sgjelinek if (arg_err) 16747ec75eb8Sgjelinek return; 16757ec75eb8Sgjelinek 16767c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 16777c478bd9Sstevel@tonic-gate short_usage(CMD_EXPORT); 16787c478bd9Sstevel@tonic-gate return; 16797c478bd9Sstevel@tonic-gate } 16807c478bd9Sstevel@tonic-gate if (strlen(outfile) == 0) { 16817c478bd9Sstevel@tonic-gate of = stdout; 16827c478bd9Sstevel@tonic-gate } else { 16837c478bd9Sstevel@tonic-gate if ((of = fopen(outfile, "w")) == NULL) { 16847c478bd9Sstevel@tonic-gate zerr(gettext("opening file %s: %s"), 16857c478bd9Sstevel@tonic-gate outfile, strerror(errno)); 16867c478bd9Sstevel@tonic-gate goto done; 16877c478bd9Sstevel@tonic-gate } 16887c478bd9Sstevel@tonic-gate setbuf(of, NULL); 1689bbec428eSgjelinek need_to_close = B_TRUE; 16907c478bd9Sstevel@tonic-gate } 16917c478bd9Sstevel@tonic-gate 1692bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK) 16937c478bd9Sstevel@tonic-gate goto done; 16947c478bd9Sstevel@tonic-gate 16957c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s -b\n", cmd_to_str(CMD_CREATE)); 16967c478bd9Sstevel@tonic-gate 16977c478bd9Sstevel@tonic-gate if (zonecfg_get_zonepath(handle, zonepath, sizeof (zonepath)) == Z_OK && 16987c478bd9Sstevel@tonic-gate strlen(zonepath) > 0) 16997c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 17007c478bd9Sstevel@tonic-gate pt_to_str(PT_ZONEPATH), zonepath); 17017c478bd9Sstevel@tonic-gate 17029acbbeafSnn if ((zone_get_brand(zone, brand, sizeof (brand)) == Z_OK) && 17039acbbeafSnn (strcmp(brand, NATIVE_BRAND_NAME) != 0)) 17049acbbeafSnn (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 17059acbbeafSnn pt_to_str(PT_BRAND), brand); 17069acbbeafSnn 17077c478bd9Sstevel@tonic-gate if (zonecfg_get_autoboot(handle, &autoboot) == Z_OK) 17087c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 17097c478bd9Sstevel@tonic-gate pt_to_str(PT_AUTOBOOT), autoboot ? "true" : "false"); 17107c478bd9Sstevel@tonic-gate 17113f2f09c1Sdp if (zonecfg_get_bootargs(handle, bootargs, sizeof (bootargs)) == Z_OK && 17123f2f09c1Sdp strlen(bootargs) > 0) { 17133f2f09c1Sdp (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 17143f2f09c1Sdp pt_to_str(PT_BOOTARGS), bootargs); 17153f2f09c1Sdp } 17163f2f09c1Sdp 17177c478bd9Sstevel@tonic-gate if (zonecfg_get_pool(handle, pool, sizeof (pool)) == Z_OK && 17187c478bd9Sstevel@tonic-gate strlen(pool) > 0) 17197c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 17207c478bd9Sstevel@tonic-gate pt_to_str(PT_POOL), pool); 17217c478bd9Sstevel@tonic-gate 1722ffbafc53Scomay if (zonecfg_get_limitpriv(handle, &limitpriv) == Z_OK && 1723ffbafc53Scomay strlen(limitpriv) > 0) { 1724ffbafc53Scomay (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 1725ffbafc53Scomay pt_to_str(PT_LIMITPRIV), limitpriv); 1726ffbafc53Scomay free(limitpriv); 1727ffbafc53Scomay } 1728ffbafc53Scomay 17290209230bSgjelinek if (zonecfg_get_sched_class(handle, sched, sizeof (sched)) == Z_OK && 17300209230bSgjelinek strlen(sched) > 0) 17310209230bSgjelinek (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 17320209230bSgjelinek pt_to_str(PT_SCHED), sched); 17333f2f09c1Sdp 1734f4b3ec61Sdh if (zonecfg_get_iptype(handle, &iptype) == Z_OK) { 1735f4b3ec61Sdh switch (iptype) { 1736f4b3ec61Sdh case ZS_SHARED: 1737f4b3ec61Sdh (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 1738f4b3ec61Sdh pt_to_str(PT_IPTYPE), "shared"); 1739f4b3ec61Sdh break; 1740f4b3ec61Sdh case ZS_EXCLUSIVE: 1741f4b3ec61Sdh (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 1742f4b3ec61Sdh pt_to_str(PT_IPTYPE), "exclusive"); 1743f4b3ec61Sdh break; 1744f4b3ec61Sdh } 1745f4b3ec61Sdh } 1746f4b3ec61Sdh 17475679c89fSjv if (zonecfg_get_hostid(handle, hostidp, sizeof (hostidp)) == Z_OK) { 17485679c89fSjv (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 17495679c89fSjv pt_to_str(PT_HOSTID), hostidp); 17505679c89fSjv } 17515679c89fSjv 17527c478bd9Sstevel@tonic-gate if ((err = zonecfg_setipdent(handle)) != Z_OK) { 1753bbec428eSgjelinek zone_perror(zone, err, B_FALSE); 17547c478bd9Sstevel@tonic-gate goto done; 17557c478bd9Sstevel@tonic-gate } 17567c478bd9Sstevel@tonic-gate while (zonecfg_getipdent(handle, &fstab) == Z_OK) { 17577c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 17587c478bd9Sstevel@tonic-gate rt_to_str(RT_IPD)); 17597c478bd9Sstevel@tonic-gate export_prop(of, PT_DIR, fstab.zone_fs_dir); 17607c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 17617c478bd9Sstevel@tonic-gate } 17627c478bd9Sstevel@tonic-gate (void) zonecfg_endipdent(handle); 17637c478bd9Sstevel@tonic-gate 17647c478bd9Sstevel@tonic-gate if ((err = zonecfg_setfsent(handle)) != Z_OK) { 1765bbec428eSgjelinek zone_perror(zone, err, B_FALSE); 17667c478bd9Sstevel@tonic-gate goto done; 17677c478bd9Sstevel@tonic-gate } 17687c478bd9Sstevel@tonic-gate while (zonecfg_getfsent(handle, &fstab) == Z_OK) { 17697c478bd9Sstevel@tonic-gate zone_fsopt_t *optptr; 17707c478bd9Sstevel@tonic-gate 17717c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 17727c478bd9Sstevel@tonic-gate rt_to_str(RT_FS)); 17737c478bd9Sstevel@tonic-gate export_prop(of, PT_DIR, fstab.zone_fs_dir); 17747c478bd9Sstevel@tonic-gate export_prop(of, PT_SPECIAL, fstab.zone_fs_special); 17757c478bd9Sstevel@tonic-gate export_prop(of, PT_RAW, fstab.zone_fs_raw); 17767c478bd9Sstevel@tonic-gate export_prop(of, PT_TYPE, fstab.zone_fs_type); 17777c478bd9Sstevel@tonic-gate for (optptr = fstab.zone_fs_options; optptr != NULL; 17787c478bd9Sstevel@tonic-gate optptr = optptr->zone_fsopt_next) { 17797c478bd9Sstevel@tonic-gate /* 17807c478bd9Sstevel@tonic-gate * Simple property values with embedded equal signs 17817c478bd9Sstevel@tonic-gate * need to be quoted to prevent the lexer from 17827c478bd9Sstevel@tonic-gate * mis-parsing them as complex name=value pairs. 17837c478bd9Sstevel@tonic-gate */ 17847c478bd9Sstevel@tonic-gate if (strchr(optptr->zone_fsopt_opt, '=')) 17857c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s \"%s\"\n", 17867c478bd9Sstevel@tonic-gate cmd_to_str(CMD_ADD), 17877c478bd9Sstevel@tonic-gate pt_to_str(PT_OPTIONS), 17887c478bd9Sstevel@tonic-gate optptr->zone_fsopt_opt); 17897c478bd9Sstevel@tonic-gate else 17907c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s %s\n", 17917c478bd9Sstevel@tonic-gate cmd_to_str(CMD_ADD), 17927c478bd9Sstevel@tonic-gate pt_to_str(PT_OPTIONS), 17937c478bd9Sstevel@tonic-gate optptr->zone_fsopt_opt); 17947c478bd9Sstevel@tonic-gate } 17957c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 17967c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(fstab.zone_fs_options); 17977c478bd9Sstevel@tonic-gate } 17987c478bd9Sstevel@tonic-gate (void) zonecfg_endfsent(handle); 17997c478bd9Sstevel@tonic-gate 18007c478bd9Sstevel@tonic-gate if ((err = zonecfg_setnwifent(handle)) != Z_OK) { 1801bbec428eSgjelinek zone_perror(zone, err, B_FALSE); 18027c478bd9Sstevel@tonic-gate goto done; 18037c478bd9Sstevel@tonic-gate } 18047c478bd9Sstevel@tonic-gate while (zonecfg_getnwifent(handle, &nwiftab) == Z_OK) { 18057c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 18067c478bd9Sstevel@tonic-gate rt_to_str(RT_NET)); 18077c478bd9Sstevel@tonic-gate export_prop(of, PT_ADDRESS, nwiftab.zone_nwif_address); 18087c478bd9Sstevel@tonic-gate export_prop(of, PT_PHYSICAL, nwiftab.zone_nwif_physical); 1809de860bd9Sgfaden export_prop(of, PT_DEFROUTER, nwiftab.zone_nwif_defrouter); 18107c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 18117c478bd9Sstevel@tonic-gate } 18127c478bd9Sstevel@tonic-gate (void) zonecfg_endnwifent(handle); 18137c478bd9Sstevel@tonic-gate 18147c478bd9Sstevel@tonic-gate if ((err = zonecfg_setdevent(handle)) != Z_OK) { 1815bbec428eSgjelinek zone_perror(zone, err, B_FALSE); 18167c478bd9Sstevel@tonic-gate goto done; 18177c478bd9Sstevel@tonic-gate } 18187c478bd9Sstevel@tonic-gate while (zonecfg_getdevent(handle, &devtab) == Z_OK) { 18197c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 18207c478bd9Sstevel@tonic-gate rt_to_str(RT_DEVICE)); 18217c478bd9Sstevel@tonic-gate export_prop(of, PT_MATCH, devtab.zone_dev_match); 18227c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 18237c478bd9Sstevel@tonic-gate } 18247c478bd9Sstevel@tonic-gate (void) zonecfg_enddevent(handle); 18257c478bd9Sstevel@tonic-gate 18267c478bd9Sstevel@tonic-gate if ((err = zonecfg_setrctlent(handle)) != Z_OK) { 1827bbec428eSgjelinek zone_perror(zone, err, B_FALSE); 18287c478bd9Sstevel@tonic-gate goto done; 18297c478bd9Sstevel@tonic-gate } 18307c478bd9Sstevel@tonic-gate while (zonecfg_getrctlent(handle, &rctltab) == Z_OK) { 18317c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s rctl\n", cmd_to_str(CMD_ADD)); 18327c478bd9Sstevel@tonic-gate export_prop(of, PT_NAME, rctltab.zone_rctl_name); 18337c478bd9Sstevel@tonic-gate for (valptr = rctltab.zone_rctl_valptr; valptr != NULL; 18347c478bd9Sstevel@tonic-gate valptr = valptr->zone_rctlval_next) { 18357c478bd9Sstevel@tonic-gate fprintf(of, "%s %s (%s=%s,%s=%s,%s=%s)\n", 18367c478bd9Sstevel@tonic-gate cmd_to_str(CMD_ADD), pt_to_str(PT_VALUE), 18377c478bd9Sstevel@tonic-gate pt_to_str(PT_PRIV), valptr->zone_rctlval_priv, 18387c478bd9Sstevel@tonic-gate pt_to_str(PT_LIMIT), valptr->zone_rctlval_limit, 18397c478bd9Sstevel@tonic-gate pt_to_str(PT_ACTION), valptr->zone_rctlval_action); 18407c478bd9Sstevel@tonic-gate } 18417c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 18427c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctltab.zone_rctl_valptr); 18437c478bd9Sstevel@tonic-gate } 18447c478bd9Sstevel@tonic-gate (void) zonecfg_endrctlent(handle); 18457c478bd9Sstevel@tonic-gate 18467c478bd9Sstevel@tonic-gate if ((err = zonecfg_setattrent(handle)) != Z_OK) { 1847bbec428eSgjelinek zone_perror(zone, err, B_FALSE); 18487c478bd9Sstevel@tonic-gate goto done; 18497c478bd9Sstevel@tonic-gate } 18507c478bd9Sstevel@tonic-gate while (zonecfg_getattrent(handle, &attrtab) == Z_OK) { 18517c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 18527c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR)); 18537c478bd9Sstevel@tonic-gate export_prop(of, PT_NAME, attrtab.zone_attr_name); 18547c478bd9Sstevel@tonic-gate export_prop(of, PT_TYPE, attrtab.zone_attr_type); 18557c478bd9Sstevel@tonic-gate export_prop(of, PT_VALUE, attrtab.zone_attr_value); 18567c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 18577c478bd9Sstevel@tonic-gate } 18587c478bd9Sstevel@tonic-gate (void) zonecfg_endattrent(handle); 18597c478bd9Sstevel@tonic-gate 1860fa9e4066Sahrens if ((err = zonecfg_setdsent(handle)) != Z_OK) { 1861bbec428eSgjelinek zone_perror(zone, err, B_FALSE); 1862fa9e4066Sahrens goto done; 1863fa9e4066Sahrens } 1864fa9e4066Sahrens while (zonecfg_getdsent(handle, &dstab) == Z_OK) { 1865fa9e4066Sahrens (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 1866fa9e4066Sahrens rt_to_str(RT_DATASET)); 1867fa9e4066Sahrens export_prop(of, PT_NAME, dstab.zone_dataset_name); 1868fa9e4066Sahrens (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 1869fa9e4066Sahrens } 1870fa9e4066Sahrens (void) zonecfg_enddsent(handle); 1871fa9e4066Sahrens 18720209230bSgjelinek if (zonecfg_getpsetent(handle, &psettab) == Z_OK) { 18730209230bSgjelinek (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 18740209230bSgjelinek rt_to_str(RT_DCPU)); 18750209230bSgjelinek if (strcmp(psettab.zone_ncpu_min, psettab.zone_ncpu_max) == 0) 18760209230bSgjelinek (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 18770209230bSgjelinek pt_to_str(PT_NCPUS), psettab.zone_ncpu_max); 18780209230bSgjelinek else 18790209230bSgjelinek (void) fprintf(of, "%s %s=%s-%s\n", cmd_to_str(CMD_SET), 18800209230bSgjelinek pt_to_str(PT_NCPUS), psettab.zone_ncpu_min, 18810209230bSgjelinek psettab.zone_ncpu_max); 18820209230bSgjelinek if (psettab.zone_importance[0] != '\0') 18830209230bSgjelinek (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 18840209230bSgjelinek pt_to_str(PT_IMPORTANCE), psettab.zone_importance); 18850209230bSgjelinek (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 18860209230bSgjelinek } 18870209230bSgjelinek 18880209230bSgjelinek if (zonecfg_getmcapent(handle, &mcaptab) == Z_OK) { 18890209230bSgjelinek char buf[128]; 18900209230bSgjelinek 18910209230bSgjelinek (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 18920209230bSgjelinek rt_to_str(RT_MCAP)); 18930209230bSgjelinek bytes_to_units(mcaptab.zone_physmem_cap, buf, sizeof (buf)); 18940209230bSgjelinek (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 18950209230bSgjelinek pt_to_str(PT_PHYSICAL), buf); 18960209230bSgjelinek (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 18970209230bSgjelinek } 18980209230bSgjelinek 1899c97ad5cdSakolb /* 1900c97ad5cdSakolb * There is nothing to export for pcap since this resource is just 1901c97ad5cdSakolb * a container for an rctl alias. 1902c97ad5cdSakolb */ 1903c97ad5cdSakolb 19047c478bd9Sstevel@tonic-gate done: 19057c478bd9Sstevel@tonic-gate if (need_to_close) 19067c478bd9Sstevel@tonic-gate (void) fclose(of); 19077c478bd9Sstevel@tonic-gate } 19087c478bd9Sstevel@tonic-gate 19097c478bd9Sstevel@tonic-gate void 19107c478bd9Sstevel@tonic-gate exit_func(cmd_t *cmd) 19117c478bd9Sstevel@tonic-gate { 19127c478bd9Sstevel@tonic-gate int arg, answer; 1913bbec428eSgjelinek boolean_t arg_err = B_FALSE; 19147c478bd9Sstevel@tonic-gate 19157c478bd9Sstevel@tonic-gate optind = 0; 19167c478bd9Sstevel@tonic-gate while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?F")) != EOF) { 19177c478bd9Sstevel@tonic-gate switch (arg) { 19187c478bd9Sstevel@tonic-gate case '?': 19197c478bd9Sstevel@tonic-gate longer_usage(CMD_EXIT); 1920bbec428eSgjelinek arg_err = B_TRUE; 19217ec75eb8Sgjelinek break; 19227c478bd9Sstevel@tonic-gate case 'F': 1923bbec428eSgjelinek force_exit = B_TRUE; 19247c478bd9Sstevel@tonic-gate break; 19257c478bd9Sstevel@tonic-gate default: 19267c478bd9Sstevel@tonic-gate short_usage(CMD_EXIT); 1927bbec428eSgjelinek arg_err = B_TRUE; 19287ec75eb8Sgjelinek break; 19297c478bd9Sstevel@tonic-gate } 19307c478bd9Sstevel@tonic-gate } 19317ec75eb8Sgjelinek if (arg_err) 19327ec75eb8Sgjelinek return; 19337ec75eb8Sgjelinek 19347c478bd9Sstevel@tonic-gate if (optind < cmd->cmd_argc) { 19357c478bd9Sstevel@tonic-gate short_usage(CMD_EXIT); 19367c478bd9Sstevel@tonic-gate return; 19377c478bd9Sstevel@tonic-gate } 19387c478bd9Sstevel@tonic-gate 19397c478bd9Sstevel@tonic-gate if (global_scope || force_exit) { 1940bbec428eSgjelinek time_to_exit = B_TRUE; 19417c478bd9Sstevel@tonic-gate return; 19427c478bd9Sstevel@tonic-gate } 19437c478bd9Sstevel@tonic-gate 1944bbec428eSgjelinek answer = ask_yesno(B_FALSE, "Resource incomplete; really quit"); 19457c478bd9Sstevel@tonic-gate if (answer == -1) { 19467c478bd9Sstevel@tonic-gate zerr(gettext("Resource incomplete, input " 19477c478bd9Sstevel@tonic-gate "not from terminal and -F not specified:\n%s command " 19487c478bd9Sstevel@tonic-gate "ignored, but exiting anyway."), cmd_to_str(CMD_EXIT)); 19497c478bd9Sstevel@tonic-gate exit(Z_ERR); 19507c478bd9Sstevel@tonic-gate } else if (answer == 1) { 1951bbec428eSgjelinek time_to_exit = B_TRUE; 19527c478bd9Sstevel@tonic-gate } 19537c478bd9Sstevel@tonic-gate /* (answer == 0) => just return */ 19547c478bd9Sstevel@tonic-gate } 19557c478bd9Sstevel@tonic-gate 19567c478bd9Sstevel@tonic-gate static int 19577c478bd9Sstevel@tonic-gate validate_zonepath_syntax(char *path) 19587c478bd9Sstevel@tonic-gate { 19597c478bd9Sstevel@tonic-gate if (path[0] != '/') { 19607c478bd9Sstevel@tonic-gate zerr(gettext("%s is not an absolute path."), path); 19617c478bd9Sstevel@tonic-gate return (Z_ERR); 19627c478bd9Sstevel@tonic-gate } 19637c478bd9Sstevel@tonic-gate if (strcmp(path, "/") == 0) { 19647c478bd9Sstevel@tonic-gate zerr(gettext("/ is not allowed as a %s."), 19657c478bd9Sstevel@tonic-gate pt_to_str(PT_ZONEPATH)); 19667c478bd9Sstevel@tonic-gate return (Z_ERR); 19677c478bd9Sstevel@tonic-gate } 19687c478bd9Sstevel@tonic-gate return (Z_OK); 19697c478bd9Sstevel@tonic-gate } 19707c478bd9Sstevel@tonic-gate 19717c478bd9Sstevel@tonic-gate static void 19727c478bd9Sstevel@tonic-gate add_resource(cmd_t *cmd) 19737c478bd9Sstevel@tonic-gate { 19747c478bd9Sstevel@tonic-gate int type; 19750209230bSgjelinek struct zone_psettab tmp_psettab; 19760209230bSgjelinek struct zone_mcaptab tmp_mcaptab; 1977c97ad5cdSakolb uint64_t tmp; 19780209230bSgjelinek uint64_t tmp_mcap; 19790209230bSgjelinek char pool[MAXNAMELEN]; 19807c478bd9Sstevel@tonic-gate 19817c478bd9Sstevel@tonic-gate if ((type = cmd->cmd_res_type) == RT_UNKNOWN) { 1982bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 19837c478bd9Sstevel@tonic-gate goto bad; 19847c478bd9Sstevel@tonic-gate } 19857c478bd9Sstevel@tonic-gate 19867c478bd9Sstevel@tonic-gate switch (type) { 19877c478bd9Sstevel@tonic-gate case RT_FS: 19887c478bd9Sstevel@tonic-gate bzero(&in_progress_fstab, sizeof (in_progress_fstab)); 19897c478bd9Sstevel@tonic-gate return; 19907c478bd9Sstevel@tonic-gate case RT_IPD: 1991087719fdSdp if (state_atleast(ZONE_STATE_INSTALLED)) { 19927c478bd9Sstevel@tonic-gate zerr(gettext("Zone %s already installed; %s %s not " 19937c478bd9Sstevel@tonic-gate "allowed."), zone, cmd_to_str(CMD_ADD), 19947c478bd9Sstevel@tonic-gate rt_to_str(RT_IPD)); 19957c478bd9Sstevel@tonic-gate goto bad; 19967c478bd9Sstevel@tonic-gate } 19977c478bd9Sstevel@tonic-gate bzero(&in_progress_ipdtab, sizeof (in_progress_ipdtab)); 19987c478bd9Sstevel@tonic-gate return; 19997c478bd9Sstevel@tonic-gate case RT_NET: 20007c478bd9Sstevel@tonic-gate bzero(&in_progress_nwiftab, sizeof (in_progress_nwiftab)); 20017c478bd9Sstevel@tonic-gate return; 20027c478bd9Sstevel@tonic-gate case RT_DEVICE: 20037c478bd9Sstevel@tonic-gate bzero(&in_progress_devtab, sizeof (in_progress_devtab)); 20047c478bd9Sstevel@tonic-gate return; 20057c478bd9Sstevel@tonic-gate case RT_RCTL: 20060209230bSgjelinek if (global_zone) 20070209230bSgjelinek zerr(gettext("WARNING: Setting a global zone resource " 20080209230bSgjelinek "control too low could deny\nservice " 20090209230bSgjelinek "to even the root user; " 20100209230bSgjelinek "this could render the system impossible\n" 20110209230bSgjelinek "to administer. Please use caution.")); 20127c478bd9Sstevel@tonic-gate bzero(&in_progress_rctltab, sizeof (in_progress_rctltab)); 20137c478bd9Sstevel@tonic-gate return; 20147c478bd9Sstevel@tonic-gate case RT_ATTR: 20157c478bd9Sstevel@tonic-gate bzero(&in_progress_attrtab, sizeof (in_progress_attrtab)); 20167c478bd9Sstevel@tonic-gate return; 2017fa9e4066Sahrens case RT_DATASET: 2018fa9e4066Sahrens bzero(&in_progress_dstab, sizeof (in_progress_dstab)); 2019fa9e4066Sahrens return; 20200209230bSgjelinek case RT_DCPU: 2021c97ad5cdSakolb /* Make sure there isn't already a cpu-set or cpu-cap entry. */ 20220209230bSgjelinek if (zonecfg_lookup_pset(handle, &tmp_psettab) == Z_OK) { 20230209230bSgjelinek zerr(gettext("The %s resource already exists."), 20240209230bSgjelinek rt_to_str(RT_DCPU)); 20250209230bSgjelinek goto bad; 20260209230bSgjelinek } 2027c97ad5cdSakolb if (zonecfg_get_aliased_rctl(handle, ALIAS_CPUCAP, &tmp) != 2028c97ad5cdSakolb Z_NO_ENTRY) { 2029c97ad5cdSakolb zerr(gettext("The %s resource already exists."), 2030c97ad5cdSakolb rt_to_str(RT_PCAP)); 2031c97ad5cdSakolb goto bad; 2032c97ad5cdSakolb } 20330209230bSgjelinek 20340209230bSgjelinek /* Make sure the pool property isn't set. */ 20350209230bSgjelinek if (zonecfg_get_pool(handle, pool, sizeof (pool)) == Z_OK && 20360209230bSgjelinek strlen(pool) > 0) { 20370209230bSgjelinek zerr(gettext("The %s property is already set. " 20380209230bSgjelinek "A persistent pool is incompatible with\nthe %s " 20390209230bSgjelinek "resource."), 20400209230bSgjelinek pt_to_str(PT_POOL), rt_to_str(RT_DCPU)); 20410209230bSgjelinek goto bad; 20420209230bSgjelinek } 20430209230bSgjelinek 20440209230bSgjelinek bzero(&in_progress_psettab, sizeof (in_progress_psettab)); 20450209230bSgjelinek return; 2046c97ad5cdSakolb case RT_PCAP: 2047c97ad5cdSakolb /* 2048c97ad5cdSakolb * Make sure there isn't already a cpu-set or incompatible 2049c97ad5cdSakolb * cpu-cap rctls. 2050c97ad5cdSakolb */ 2051c97ad5cdSakolb if (zonecfg_lookup_pset(handle, &tmp_psettab) == Z_OK) { 2052c97ad5cdSakolb zerr(gettext("The %s resource already exists."), 2053c97ad5cdSakolb rt_to_str(RT_DCPU)); 2054c97ad5cdSakolb goto bad; 2055c97ad5cdSakolb } 2056c97ad5cdSakolb 2057c97ad5cdSakolb switch (zonecfg_get_aliased_rctl(handle, ALIAS_CPUCAP, &tmp)) { 2058c97ad5cdSakolb case Z_ALIAS_DISALLOW: 2059c97ad5cdSakolb zone_perror(rt_to_str(RT_PCAP), Z_ALIAS_DISALLOW, 2060bbec428eSgjelinek B_FALSE); 2061c97ad5cdSakolb goto bad; 2062c97ad5cdSakolb 2063c97ad5cdSakolb case Z_OK: 2064c97ad5cdSakolb zerr(gettext("The %s resource already exists."), 2065c97ad5cdSakolb rt_to_str(RT_PCAP)); 2066c97ad5cdSakolb goto bad; 2067c97ad5cdSakolb 2068c97ad5cdSakolb default: 2069c97ad5cdSakolb break; 2070c97ad5cdSakolb } 2071c97ad5cdSakolb return; 20720209230bSgjelinek case RT_MCAP: 20730209230bSgjelinek /* 20740209230bSgjelinek * Make sure there isn't already a mem-cap entry or max-swap 20750209230bSgjelinek * or max-locked rctl. 20760209230bSgjelinek */ 20770209230bSgjelinek if (zonecfg_lookup_mcap(handle, &tmp_mcaptab) == Z_OK || 20780209230bSgjelinek zonecfg_get_aliased_rctl(handle, ALIAS_MAXSWAP, &tmp_mcap) 20790209230bSgjelinek == Z_OK || 20800209230bSgjelinek zonecfg_get_aliased_rctl(handle, ALIAS_MAXLOCKEDMEM, 20810209230bSgjelinek &tmp_mcap) == Z_OK) { 20820209230bSgjelinek zerr(gettext("The %s resource or a related resource " 20830209230bSgjelinek "control already exists."), rt_to_str(RT_MCAP)); 20840209230bSgjelinek goto bad; 20850209230bSgjelinek } 20860209230bSgjelinek if (global_zone) 20870209230bSgjelinek zerr(gettext("WARNING: Setting a global zone memory " 20880209230bSgjelinek "cap too low could deny\nservice " 20890209230bSgjelinek "to even the root user; " 20900209230bSgjelinek "this could render the system impossible\n" 20910209230bSgjelinek "to administer. Please use caution.")); 20920209230bSgjelinek bzero(&in_progress_mcaptab, sizeof (in_progress_mcaptab)); 20930209230bSgjelinek return; 20947c478bd9Sstevel@tonic-gate default: 2095bbec428eSgjelinek zone_perror(rt_to_str(type), Z_NO_RESOURCE_TYPE, B_TRUE); 2096bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 2097bbec428eSgjelinek usage(B_FALSE, HELP_RESOURCES); 20987c478bd9Sstevel@tonic-gate } 20997c478bd9Sstevel@tonic-gate bad: 2100bbec428eSgjelinek global_scope = B_TRUE; 21017c478bd9Sstevel@tonic-gate end_op = -1; 21027c478bd9Sstevel@tonic-gate } 21037c478bd9Sstevel@tonic-gate 21047c478bd9Sstevel@tonic-gate static void 21057c478bd9Sstevel@tonic-gate do_complex_rctl_val(complex_property_ptr_t cp) 21067c478bd9Sstevel@tonic-gate { 21077c478bd9Sstevel@tonic-gate struct zone_rctlvaltab *rctlvaltab; 21087c478bd9Sstevel@tonic-gate complex_property_ptr_t cx; 2109bbec428eSgjelinek boolean_t seen_priv = B_FALSE, seen_limit = B_FALSE, 2110bbec428eSgjelinek seen_action = B_FALSE; 21117c478bd9Sstevel@tonic-gate rctlblk_t *rctlblk; 21127c478bd9Sstevel@tonic-gate int err; 21137c478bd9Sstevel@tonic-gate 21147c478bd9Sstevel@tonic-gate if ((rctlvaltab = alloc_rctlvaltab()) == NULL) { 2115bbec428eSgjelinek zone_perror(zone, Z_NOMEM, B_TRUE); 21167c478bd9Sstevel@tonic-gate exit(Z_ERR); 21177c478bd9Sstevel@tonic-gate } 21187c478bd9Sstevel@tonic-gate for (cx = cp; cx != NULL; cx = cx->cp_next) { 21197c478bd9Sstevel@tonic-gate switch (cx->cp_type) { 21207c478bd9Sstevel@tonic-gate case PT_PRIV: 21217c478bd9Sstevel@tonic-gate if (seen_priv) { 21227c478bd9Sstevel@tonic-gate zerr(gettext("%s already specified"), 21237c478bd9Sstevel@tonic-gate pt_to_str(PT_PRIV)); 21247c478bd9Sstevel@tonic-gate goto bad; 21257c478bd9Sstevel@tonic-gate } 21267c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_priv, 21277c478bd9Sstevel@tonic-gate cx->cp_value, 21287c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_priv)); 2129bbec428eSgjelinek seen_priv = B_TRUE; 21307c478bd9Sstevel@tonic-gate break; 21317c478bd9Sstevel@tonic-gate case PT_LIMIT: 21327c478bd9Sstevel@tonic-gate if (seen_limit) { 21337c478bd9Sstevel@tonic-gate zerr(gettext("%s already specified"), 21347c478bd9Sstevel@tonic-gate pt_to_str(PT_LIMIT)); 21357c478bd9Sstevel@tonic-gate goto bad; 21367c478bd9Sstevel@tonic-gate } 21377c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_limit, 21387c478bd9Sstevel@tonic-gate cx->cp_value, 21397c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_limit)); 2140bbec428eSgjelinek seen_limit = B_TRUE; 21417c478bd9Sstevel@tonic-gate break; 21427c478bd9Sstevel@tonic-gate case PT_ACTION: 21437c478bd9Sstevel@tonic-gate if (seen_action) { 21447c478bd9Sstevel@tonic-gate zerr(gettext("%s already specified"), 21457c478bd9Sstevel@tonic-gate pt_to_str(PT_ACTION)); 21467c478bd9Sstevel@tonic-gate goto bad; 21477c478bd9Sstevel@tonic-gate } 21487c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_action, 21497c478bd9Sstevel@tonic-gate cx->cp_value, 21507c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_action)); 2151bbec428eSgjelinek seen_action = B_TRUE; 21527c478bd9Sstevel@tonic-gate break; 21537c478bd9Sstevel@tonic-gate default: 21547c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(PT_VALUE), 2155bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE); 2156bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 2157bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 21587c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctlvaltab); 21597c478bd9Sstevel@tonic-gate return; 21607c478bd9Sstevel@tonic-gate } 21617c478bd9Sstevel@tonic-gate } 21627c478bd9Sstevel@tonic-gate if (!seen_priv) 21637c478bd9Sstevel@tonic-gate zerr(gettext("%s not specified"), pt_to_str(PT_PRIV)); 21647c478bd9Sstevel@tonic-gate if (!seen_limit) 21657c478bd9Sstevel@tonic-gate zerr(gettext("%s not specified"), pt_to_str(PT_LIMIT)); 21667c478bd9Sstevel@tonic-gate if (!seen_action) 21677c478bd9Sstevel@tonic-gate zerr(gettext("%s not specified"), pt_to_str(PT_ACTION)); 21687c478bd9Sstevel@tonic-gate if (!seen_priv || !seen_limit || !seen_action) 21697c478bd9Sstevel@tonic-gate goto bad; 21707c478bd9Sstevel@tonic-gate rctlvaltab->zone_rctlval_next = NULL; 21717c478bd9Sstevel@tonic-gate rctlblk = alloca(rctlblk_size()); 21727c478bd9Sstevel@tonic-gate /* 21737c478bd9Sstevel@tonic-gate * Make sure the rctl value looks roughly correct; we won't know if 21747c478bd9Sstevel@tonic-gate * it's truly OK until we verify the configuration on the target 21757c478bd9Sstevel@tonic-gate * system. 21767c478bd9Sstevel@tonic-gate */ 21777c478bd9Sstevel@tonic-gate if (zonecfg_construct_rctlblk(rctlvaltab, rctlblk) != Z_OK || 21787c478bd9Sstevel@tonic-gate !zonecfg_valid_rctlblk(rctlblk)) { 21797c478bd9Sstevel@tonic-gate zerr(gettext("Invalid %s %s specification"), rt_to_str(RT_RCTL), 21807c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE)); 21817c478bd9Sstevel@tonic-gate goto bad; 21827c478bd9Sstevel@tonic-gate } 21837c478bd9Sstevel@tonic-gate err = zonecfg_add_rctl_value(&in_progress_rctltab, rctlvaltab); 21847c478bd9Sstevel@tonic-gate if (err != Z_OK) 2185bbec428eSgjelinek zone_perror(pt_to_str(PT_VALUE), err, B_TRUE); 21867c478bd9Sstevel@tonic-gate return; 21877c478bd9Sstevel@tonic-gate 21887c478bd9Sstevel@tonic-gate bad: 21897c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctlvaltab); 21907c478bd9Sstevel@tonic-gate } 21917c478bd9Sstevel@tonic-gate 21927c478bd9Sstevel@tonic-gate static void 21937c478bd9Sstevel@tonic-gate add_property(cmd_t *cmd) 21947c478bd9Sstevel@tonic-gate { 21957c478bd9Sstevel@tonic-gate char *prop_id; 21967c478bd9Sstevel@tonic-gate int err, res_type, prop_type; 21977c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 21987c478bd9Sstevel@tonic-gate list_property_ptr_t l; 21997c478bd9Sstevel@tonic-gate 22007c478bd9Sstevel@tonic-gate res_type = resource_scope; 22017c478bd9Sstevel@tonic-gate prop_type = cmd->cmd_prop_name[0]; 22027c478bd9Sstevel@tonic-gate if (res_type == RT_UNKNOWN || prop_type == PT_UNKNOWN) { 2203bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 22047c478bd9Sstevel@tonic-gate return; 22057c478bd9Sstevel@tonic-gate } 22067c478bd9Sstevel@tonic-gate 22077c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs != 1) { 2208bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 22097c478bd9Sstevel@tonic-gate return; 22107c478bd9Sstevel@tonic-gate } 22117c478bd9Sstevel@tonic-gate 2212bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 22137c478bd9Sstevel@tonic-gate return; 22147c478bd9Sstevel@tonic-gate 22157c478bd9Sstevel@tonic-gate switch (res_type) { 22167c478bd9Sstevel@tonic-gate case RT_FS: 22177c478bd9Sstevel@tonic-gate if (prop_type != PT_OPTIONS) { 22187c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 2219bbec428eSgjelinek B_TRUE); 2220bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 2221bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 22227c478bd9Sstevel@tonic-gate return; 22237c478bd9Sstevel@tonic-gate } 22247c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[0]; 22257c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE && 22267c478bd9Sstevel@tonic-gate pp->pv_type != PROP_VAL_LIST) { 22277c478bd9Sstevel@tonic-gate zerr(gettext("A %s or %s value was expected here."), 22287c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_SIMPLE), 22297c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_LIST)); 2230bbec428eSgjelinek saw_error = B_TRUE; 22317c478bd9Sstevel@tonic-gate return; 22327c478bd9Sstevel@tonic-gate } 22337c478bd9Sstevel@tonic-gate if (pp->pv_type == PROP_VAL_SIMPLE) { 22347c478bd9Sstevel@tonic-gate if (pp->pv_simple == NULL) { 2235bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 22367c478bd9Sstevel@tonic-gate return; 22377c478bd9Sstevel@tonic-gate } 22387c478bd9Sstevel@tonic-gate prop_id = pp->pv_simple; 22397c478bd9Sstevel@tonic-gate err = zonecfg_add_fs_option(&in_progress_fstab, 22407c478bd9Sstevel@tonic-gate prop_id); 22417c478bd9Sstevel@tonic-gate if (err != Z_OK) 2242bbec428eSgjelinek zone_perror(pt_to_str(prop_type), err, B_TRUE); 22437c478bd9Sstevel@tonic-gate } else { 22447c478bd9Sstevel@tonic-gate list_property_ptr_t list; 22457c478bd9Sstevel@tonic-gate 22467c478bd9Sstevel@tonic-gate for (list = pp->pv_list; list != NULL; 22477c478bd9Sstevel@tonic-gate list = list->lp_next) { 22487c478bd9Sstevel@tonic-gate prop_id = list->lp_simple; 22497c478bd9Sstevel@tonic-gate if (prop_id == NULL) 22507c478bd9Sstevel@tonic-gate break; 22517c478bd9Sstevel@tonic-gate err = zonecfg_add_fs_option( 22527c478bd9Sstevel@tonic-gate &in_progress_fstab, prop_id); 22537c478bd9Sstevel@tonic-gate if (err != Z_OK) 22547c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), err, 2255bbec428eSgjelinek B_TRUE); 22567c478bd9Sstevel@tonic-gate } 22577c478bd9Sstevel@tonic-gate } 22587c478bd9Sstevel@tonic-gate return; 22597c478bd9Sstevel@tonic-gate case RT_RCTL: 22607c478bd9Sstevel@tonic-gate if (prop_type != PT_VALUE) { 22617c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 2262bbec428eSgjelinek B_TRUE); 2263bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 2264bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 22657c478bd9Sstevel@tonic-gate return; 22667c478bd9Sstevel@tonic-gate } 22677c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[0]; 22687c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_COMPLEX && 22697c478bd9Sstevel@tonic-gate pp->pv_type != PROP_VAL_LIST) { 22707c478bd9Sstevel@tonic-gate zerr(gettext("A %s or %s value was expected here."), 22717c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_COMPLEX), 22727c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_LIST)); 2273bbec428eSgjelinek saw_error = B_TRUE; 22747c478bd9Sstevel@tonic-gate return; 22757c478bd9Sstevel@tonic-gate } 22767c478bd9Sstevel@tonic-gate if (pp->pv_type == PROP_VAL_COMPLEX) { 22777c478bd9Sstevel@tonic-gate do_complex_rctl_val(pp->pv_complex); 22787c478bd9Sstevel@tonic-gate return; 22797c478bd9Sstevel@tonic-gate } 22807c478bd9Sstevel@tonic-gate for (l = pp->pv_list; l != NULL; l = l->lp_next) 22817c478bd9Sstevel@tonic-gate do_complex_rctl_val(l->lp_complex); 22827c478bd9Sstevel@tonic-gate return; 22837c478bd9Sstevel@tonic-gate default: 2284bbec428eSgjelinek zone_perror(rt_to_str(res_type), Z_NO_RESOURCE_TYPE, B_TRUE); 2285bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 2286bbec428eSgjelinek usage(B_FALSE, HELP_RESOURCES); 22877c478bd9Sstevel@tonic-gate return; 22887c478bd9Sstevel@tonic-gate } 22897c478bd9Sstevel@tonic-gate } 22907c478bd9Sstevel@tonic-gate 22910209230bSgjelinek static boolean_t 22920209230bSgjelinek gz_invalid_resource(int type) 22930209230bSgjelinek { 22940209230bSgjelinek return (global_zone && (type == RT_FS || type == RT_IPD || 22950209230bSgjelinek type == RT_NET || type == RT_DEVICE || type == RT_ATTR || 22960209230bSgjelinek type == RT_DATASET)); 22970209230bSgjelinek } 22980209230bSgjelinek 22990209230bSgjelinek static boolean_t 23000209230bSgjelinek gz_invalid_rt_property(int type) 23010209230bSgjelinek { 23020209230bSgjelinek return (global_zone && (type == RT_ZONENAME || type == RT_ZONEPATH || 23030209230bSgjelinek type == RT_AUTOBOOT || type == RT_LIMITPRIV || 2304f4b3ec61Sdh type == RT_BOOTARGS || type == RT_BRAND || type == RT_SCHED || 23055679c89fSjv type == RT_IPTYPE || type == RT_HOSTID)); 23060209230bSgjelinek } 23070209230bSgjelinek 23080209230bSgjelinek static boolean_t 23090209230bSgjelinek gz_invalid_property(int type) 23100209230bSgjelinek { 23110209230bSgjelinek return (global_zone && (type == PT_ZONENAME || type == PT_ZONEPATH || 23120209230bSgjelinek type == PT_AUTOBOOT || type == PT_LIMITPRIV || 2313f4b3ec61Sdh type == PT_BOOTARGS || type == PT_BRAND || type == PT_SCHED || 23145679c89fSjv type == PT_IPTYPE || type == PT_HOSTID)); 23150209230bSgjelinek } 23160209230bSgjelinek 23177c478bd9Sstevel@tonic-gate void 23187c478bd9Sstevel@tonic-gate add_func(cmd_t *cmd) 23197c478bd9Sstevel@tonic-gate { 23207c478bd9Sstevel@tonic-gate int arg; 2321bbec428eSgjelinek boolean_t arg_err = B_FALSE; 23227c478bd9Sstevel@tonic-gate 23237c478bd9Sstevel@tonic-gate assert(cmd != NULL); 23247c478bd9Sstevel@tonic-gate 23257c478bd9Sstevel@tonic-gate optind = 0; 23267ec75eb8Sgjelinek while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?")) != EOF) { 23277c478bd9Sstevel@tonic-gate switch (arg) { 23287c478bd9Sstevel@tonic-gate case '?': 23297c478bd9Sstevel@tonic-gate longer_usage(CMD_ADD); 2330bbec428eSgjelinek arg_err = B_TRUE; 23317ec75eb8Sgjelinek break; 23327c478bd9Sstevel@tonic-gate default: 23337c478bd9Sstevel@tonic-gate short_usage(CMD_ADD); 2334bbec428eSgjelinek arg_err = B_TRUE; 23357ec75eb8Sgjelinek break; 23367c478bd9Sstevel@tonic-gate } 23377c478bd9Sstevel@tonic-gate } 23387ec75eb8Sgjelinek if (arg_err) 23397ec75eb8Sgjelinek return; 23407ec75eb8Sgjelinek 23417c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 23427c478bd9Sstevel@tonic-gate short_usage(CMD_ADD); 23437c478bd9Sstevel@tonic-gate return; 23447c478bd9Sstevel@tonic-gate } 23457c478bd9Sstevel@tonic-gate 23467c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_ADD)) 23477c478bd9Sstevel@tonic-gate return; 23487c478bd9Sstevel@tonic-gate 2349bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 23507c478bd9Sstevel@tonic-gate return; 23517c478bd9Sstevel@tonic-gate if (global_scope) { 23520209230bSgjelinek if (gz_invalid_resource(cmd->cmd_res_type)) { 23530209230bSgjelinek zerr(gettext("Cannot add a %s resource to the " 23540209230bSgjelinek "global zone."), rt_to_str(cmd->cmd_res_type)); 2355bbec428eSgjelinek saw_error = B_TRUE; 23560209230bSgjelinek return; 23570209230bSgjelinek } 23580209230bSgjelinek 2359bbec428eSgjelinek global_scope = B_FALSE; 23607c478bd9Sstevel@tonic-gate resource_scope = cmd->cmd_res_type; 23617c478bd9Sstevel@tonic-gate end_op = CMD_ADD; 23627c478bd9Sstevel@tonic-gate add_resource(cmd); 23637c478bd9Sstevel@tonic-gate } else 23647c478bd9Sstevel@tonic-gate add_property(cmd); 23657c478bd9Sstevel@tonic-gate } 23667c478bd9Sstevel@tonic-gate 2367087719fdSdp /* 2368087719fdSdp * This routine has an unusual implementation, because it tries very 2369087719fdSdp * hard to succeed in the face of a variety of failure modes. 2370087719fdSdp * The most common and most vexing occurs when the index file and 2371087719fdSdp * the /etc/zones/<zonename.xml> file are not both present. In 2372087719fdSdp * this case, delete must eradicate as much of the zone state as is left 2373087719fdSdp * so that the user can later create a new zone with the same name. 2374087719fdSdp */ 23757c478bd9Sstevel@tonic-gate void 23767c478bd9Sstevel@tonic-gate delete_func(cmd_t *cmd) 23777c478bd9Sstevel@tonic-gate { 23787c478bd9Sstevel@tonic-gate int err, arg, answer; 23797c478bd9Sstevel@tonic-gate char line[ZONENAME_MAX + 128]; /* enough to ask a question */ 2380bbec428eSgjelinek boolean_t force = B_FALSE; 2381bbec428eSgjelinek boolean_t arg_err = B_FALSE; 23827c478bd9Sstevel@tonic-gate 23837c478bd9Sstevel@tonic-gate optind = 0; 23847c478bd9Sstevel@tonic-gate while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?F")) != EOF) { 23857c478bd9Sstevel@tonic-gate switch (arg) { 23867c478bd9Sstevel@tonic-gate case '?': 23877c478bd9Sstevel@tonic-gate longer_usage(CMD_DELETE); 2388bbec428eSgjelinek arg_err = B_TRUE; 23897ec75eb8Sgjelinek break; 23907c478bd9Sstevel@tonic-gate case 'F': 2391bbec428eSgjelinek force = B_TRUE; 23927c478bd9Sstevel@tonic-gate break; 23937c478bd9Sstevel@tonic-gate default: 23947c478bd9Sstevel@tonic-gate short_usage(CMD_DELETE); 2395bbec428eSgjelinek arg_err = B_TRUE; 23967ec75eb8Sgjelinek break; 23977c478bd9Sstevel@tonic-gate } 23987c478bd9Sstevel@tonic-gate } 23997ec75eb8Sgjelinek if (arg_err) 24007ec75eb8Sgjelinek return; 24017ec75eb8Sgjelinek 24027c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 24037c478bd9Sstevel@tonic-gate short_usage(CMD_DELETE); 24047c478bd9Sstevel@tonic-gate return; 24057c478bd9Sstevel@tonic-gate } 24067c478bd9Sstevel@tonic-gate 24077c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_DELETE)) 24087c478bd9Sstevel@tonic-gate return; 24097c478bd9Sstevel@tonic-gate 24107c478bd9Sstevel@tonic-gate if (!force) { 2411087719fdSdp /* 2412087719fdSdp * Initialize sets up the global called "handle" and warns the 2413087719fdSdp * user if the zone is not configured. In force mode, we don't 2414087719fdSdp * trust that evaluation, and hence skip it. (We don't need the 2415087719fdSdp * handle to be loaded anyway, since zonecfg_destroy is done by 2416087719fdSdp * zonename). However, we also have to take care to emulate the 2417087719fdSdp * messages spit out by initialize; see below. 2418087719fdSdp */ 2419bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 2420087719fdSdp return; 2421087719fdSdp 24227c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), 24237c478bd9Sstevel@tonic-gate gettext("Are you sure you want to delete zone %s"), zone); 2424bbec428eSgjelinek if ((answer = ask_yesno(B_FALSE, line)) == -1) { 2425087719fdSdp zerr(gettext("Input not from terminal and -F not " 2426087719fdSdp "specified:\n%s command ignored, exiting."), 2427087719fdSdp cmd_to_str(CMD_DELETE)); 24287c478bd9Sstevel@tonic-gate exit(Z_ERR); 24297c478bd9Sstevel@tonic-gate } 24307c478bd9Sstevel@tonic-gate if (answer != 1) 24317c478bd9Sstevel@tonic-gate return; 24327c478bd9Sstevel@tonic-gate } 24337c478bd9Sstevel@tonic-gate 2434087719fdSdp if ((err = zonecfg_destroy(zone, force)) != Z_OK) { 2435087719fdSdp if ((err == Z_BAD_ZONE_STATE) && !force) { 2436087719fdSdp zerr(gettext("Zone %s not in %s state; %s not " 2437087719fdSdp "allowed. Use -F to force %s."), 2438087719fdSdp zone, zone_state_str(ZONE_STATE_CONFIGURED), 2439087719fdSdp cmd_to_str(CMD_DELETE), cmd_to_str(CMD_DELETE)); 2440087719fdSdp } else { 2441bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 2442087719fdSdp } 24437c478bd9Sstevel@tonic-gate } 2444bbec428eSgjelinek need_to_commit = B_FALSE; 2445087719fdSdp 2446087719fdSdp /* 2447087719fdSdp * Emulate initialize's messaging; if there wasn't a valid handle to 2448087719fdSdp * begin with, then user had typed delete (or delete -F) multiple 2449087719fdSdp * times. So we emit a message. 2450087719fdSdp * 2451087719fdSdp * We only do this in the 'force' case because normally, initialize() 2452087719fdSdp * takes care of this for us. 2453087719fdSdp */ 2454087719fdSdp if (force && zonecfg_check_handle(handle) != Z_OK && interactive_mode) 2455087719fdSdp (void) printf(gettext("Use '%s' to begin " 2456087719fdSdp "configuring a new zone.\n"), cmd_to_str(CMD_CREATE)); 24577c478bd9Sstevel@tonic-gate 24587c478bd9Sstevel@tonic-gate /* 24597c478bd9Sstevel@tonic-gate * Time for a new handle: finish the old one off first 24607c478bd9Sstevel@tonic-gate * then get a new one properly to avoid leaks. 24617c478bd9Sstevel@tonic-gate */ 2462087719fdSdp if (got_handle) { 2463087719fdSdp zonecfg_fini_handle(handle); 2464087719fdSdp if ((handle = zonecfg_init_handle()) == NULL) { 2465bbec428eSgjelinek zone_perror(execname, Z_NOMEM, B_TRUE); 2466087719fdSdp exit(Z_ERR); 2467087719fdSdp } 2468087719fdSdp if ((err = zonecfg_get_handle(zone, handle)) != Z_OK) { 2469087719fdSdp /* If there was no zone before, that's OK */ 2470087719fdSdp if (err != Z_NO_ZONE) 2471bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 2472bbec428eSgjelinek got_handle = B_FALSE; 2473087719fdSdp } 24747c478bd9Sstevel@tonic-gate } 24757c478bd9Sstevel@tonic-gate } 24767c478bd9Sstevel@tonic-gate 24777c478bd9Sstevel@tonic-gate static int 2478bbec428eSgjelinek fill_in_fstab(cmd_t *cmd, struct zone_fstab *fstab, boolean_t fill_in_only) 24797c478bd9Sstevel@tonic-gate { 24807c478bd9Sstevel@tonic-gate int err, i; 24817c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 24827c478bd9Sstevel@tonic-gate 2483bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK) 24847c478bd9Sstevel@tonic-gate return (err); 24857c478bd9Sstevel@tonic-gate 2486e193d1e6Svp bzero(fstab, sizeof (*fstab)); 24877c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 24887c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i]; 24897c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 24907c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here.")); 2491bbec428eSgjelinek saw_error = B_TRUE; 24927c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 24937c478bd9Sstevel@tonic-gate } 24947c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) { 24957c478bd9Sstevel@tonic-gate case PT_DIR: 24967c478bd9Sstevel@tonic-gate (void) strlcpy(fstab->zone_fs_dir, pp->pv_simple, 24977c478bd9Sstevel@tonic-gate sizeof (fstab->zone_fs_dir)); 24987c478bd9Sstevel@tonic-gate break; 24997c478bd9Sstevel@tonic-gate case PT_SPECIAL: 25007c478bd9Sstevel@tonic-gate (void) strlcpy(fstab->zone_fs_special, pp->pv_simple, 25017c478bd9Sstevel@tonic-gate sizeof (fstab->zone_fs_special)); 25027c478bd9Sstevel@tonic-gate break; 25037c478bd9Sstevel@tonic-gate case PT_RAW: 25047c478bd9Sstevel@tonic-gate (void) strlcpy(fstab->zone_fs_raw, pp->pv_simple, 25057c478bd9Sstevel@tonic-gate sizeof (fstab->zone_fs_raw)); 25067c478bd9Sstevel@tonic-gate break; 25077c478bd9Sstevel@tonic-gate case PT_TYPE: 25087c478bd9Sstevel@tonic-gate (void) strlcpy(fstab->zone_fs_type, pp->pv_simple, 25097c478bd9Sstevel@tonic-gate sizeof (fstab->zone_fs_type)); 25107c478bd9Sstevel@tonic-gate break; 25117c478bd9Sstevel@tonic-gate default: 25127c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 2513bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE); 25147c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 25157c478bd9Sstevel@tonic-gate } 25167c478bd9Sstevel@tonic-gate } 25177c478bd9Sstevel@tonic-gate if (fill_in_only) 25187c478bd9Sstevel@tonic-gate return (Z_OK); 25197c478bd9Sstevel@tonic-gate return (zonecfg_lookup_filesystem(handle, fstab)); 25207c478bd9Sstevel@tonic-gate } 25217c478bd9Sstevel@tonic-gate 25227c478bd9Sstevel@tonic-gate static int 2523bbec428eSgjelinek fill_in_ipdtab(cmd_t *cmd, struct zone_fstab *ipdtab, boolean_t fill_in_only) 25247c478bd9Sstevel@tonic-gate { 25257c478bd9Sstevel@tonic-gate int err, i; 25267c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 25277c478bd9Sstevel@tonic-gate 2528bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK) 25297c478bd9Sstevel@tonic-gate return (err); 25307c478bd9Sstevel@tonic-gate 2531e193d1e6Svp bzero(ipdtab, sizeof (*ipdtab)); 25327c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 25337c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i]; 25347c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 25357c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here.")); 2536bbec428eSgjelinek saw_error = B_TRUE; 25377c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 25387c478bd9Sstevel@tonic-gate } 25397c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) { 25407c478bd9Sstevel@tonic-gate case PT_DIR: 25417c478bd9Sstevel@tonic-gate (void) strlcpy(ipdtab->zone_fs_dir, pp->pv_simple, 25427c478bd9Sstevel@tonic-gate sizeof (ipdtab->zone_fs_dir)); 25437c478bd9Sstevel@tonic-gate break; 25447c478bd9Sstevel@tonic-gate default: 25457c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 2546bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE); 25477c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 25487c478bd9Sstevel@tonic-gate } 25497c478bd9Sstevel@tonic-gate } 25507c478bd9Sstevel@tonic-gate if (fill_in_only) 25517c478bd9Sstevel@tonic-gate return (Z_OK); 25527c478bd9Sstevel@tonic-gate return (zonecfg_lookup_ipd(handle, ipdtab)); 25537c478bd9Sstevel@tonic-gate } 25547c478bd9Sstevel@tonic-gate 25557c478bd9Sstevel@tonic-gate static int 2556bbec428eSgjelinek fill_in_nwiftab(cmd_t *cmd, struct zone_nwiftab *nwiftab, 2557bbec428eSgjelinek boolean_t fill_in_only) 25587c478bd9Sstevel@tonic-gate { 25597c478bd9Sstevel@tonic-gate int err, i; 25607c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 25617c478bd9Sstevel@tonic-gate 2562bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK) 25637c478bd9Sstevel@tonic-gate return (err); 25647c478bd9Sstevel@tonic-gate 2565e193d1e6Svp bzero(nwiftab, sizeof (*nwiftab)); 25667c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 25677c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i]; 25687c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 25697c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here.")); 2570bbec428eSgjelinek saw_error = B_TRUE; 25717c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 25727c478bd9Sstevel@tonic-gate } 25737c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) { 25747c478bd9Sstevel@tonic-gate case PT_ADDRESS: 25757c478bd9Sstevel@tonic-gate (void) strlcpy(nwiftab->zone_nwif_address, 25767c478bd9Sstevel@tonic-gate pp->pv_simple, sizeof (nwiftab->zone_nwif_address)); 25777c478bd9Sstevel@tonic-gate break; 25787c478bd9Sstevel@tonic-gate case PT_PHYSICAL: 25797c478bd9Sstevel@tonic-gate (void) strlcpy(nwiftab->zone_nwif_physical, 25807c478bd9Sstevel@tonic-gate pp->pv_simple, 25817c478bd9Sstevel@tonic-gate sizeof (nwiftab->zone_nwif_physical)); 25827c478bd9Sstevel@tonic-gate break; 2583de860bd9Sgfaden case PT_DEFROUTER: 2584de860bd9Sgfaden (void) strlcpy(nwiftab->zone_nwif_defrouter, 2585de860bd9Sgfaden pp->pv_simple, 2586de860bd9Sgfaden sizeof (nwiftab->zone_nwif_defrouter)); 2587de860bd9Sgfaden break; 25887c478bd9Sstevel@tonic-gate default: 25897c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 2590bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE); 25917c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 25927c478bd9Sstevel@tonic-gate } 25937c478bd9Sstevel@tonic-gate } 25947c478bd9Sstevel@tonic-gate if (fill_in_only) 25957c478bd9Sstevel@tonic-gate return (Z_OK); 25967c478bd9Sstevel@tonic-gate err = zonecfg_lookup_nwif(handle, nwiftab); 25977c478bd9Sstevel@tonic-gate return (err); 25987c478bd9Sstevel@tonic-gate } 25997c478bd9Sstevel@tonic-gate 26007c478bd9Sstevel@tonic-gate static int 2601bbec428eSgjelinek fill_in_devtab(cmd_t *cmd, struct zone_devtab *devtab, boolean_t fill_in_only) 26027c478bd9Sstevel@tonic-gate { 26037c478bd9Sstevel@tonic-gate int err, i; 26047c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 26057c478bd9Sstevel@tonic-gate 2606bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK) 26077c478bd9Sstevel@tonic-gate return (err); 26087c478bd9Sstevel@tonic-gate 2609e193d1e6Svp bzero(devtab, sizeof (*devtab)); 26107c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 26117c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i]; 26127c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 26137c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here.")); 2614bbec428eSgjelinek saw_error = B_TRUE; 26157c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 26167c478bd9Sstevel@tonic-gate } 26177c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) { 26187c478bd9Sstevel@tonic-gate case PT_MATCH: 26197c478bd9Sstevel@tonic-gate (void) strlcpy(devtab->zone_dev_match, pp->pv_simple, 26207c478bd9Sstevel@tonic-gate sizeof (devtab->zone_dev_match)); 26217c478bd9Sstevel@tonic-gate break; 26227c478bd9Sstevel@tonic-gate default: 26237c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 2624bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE); 26257c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 26267c478bd9Sstevel@tonic-gate } 26277c478bd9Sstevel@tonic-gate } 26287c478bd9Sstevel@tonic-gate if (fill_in_only) 26297c478bd9Sstevel@tonic-gate return (Z_OK); 26307c478bd9Sstevel@tonic-gate err = zonecfg_lookup_dev(handle, devtab); 26317c478bd9Sstevel@tonic-gate return (err); 26327c478bd9Sstevel@tonic-gate } 26337c478bd9Sstevel@tonic-gate 26347c478bd9Sstevel@tonic-gate static int 2635bbec428eSgjelinek fill_in_rctltab(cmd_t *cmd, struct zone_rctltab *rctltab, 2636bbec428eSgjelinek boolean_t fill_in_only) 26377c478bd9Sstevel@tonic-gate { 26387c478bd9Sstevel@tonic-gate int err, i; 26397c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 26407c478bd9Sstevel@tonic-gate 2641bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK) 26427c478bd9Sstevel@tonic-gate return (err); 26437c478bd9Sstevel@tonic-gate 2644e193d1e6Svp bzero(rctltab, sizeof (*rctltab)); 26457c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 26467c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i]; 26477c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 26487c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here.")); 2649bbec428eSgjelinek saw_error = B_TRUE; 26507c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 26517c478bd9Sstevel@tonic-gate } 26527c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) { 26537c478bd9Sstevel@tonic-gate case PT_NAME: 26547c478bd9Sstevel@tonic-gate (void) strlcpy(rctltab->zone_rctl_name, pp->pv_simple, 26557c478bd9Sstevel@tonic-gate sizeof (rctltab->zone_rctl_name)); 26567c478bd9Sstevel@tonic-gate break; 26577c478bd9Sstevel@tonic-gate default: 26587c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 2659bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE); 26607c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 26617c478bd9Sstevel@tonic-gate } 26627c478bd9Sstevel@tonic-gate } 26637c478bd9Sstevel@tonic-gate if (fill_in_only) 26647c478bd9Sstevel@tonic-gate return (Z_OK); 26657c478bd9Sstevel@tonic-gate err = zonecfg_lookup_rctl(handle, rctltab); 26667c478bd9Sstevel@tonic-gate return (err); 26677c478bd9Sstevel@tonic-gate } 26687c478bd9Sstevel@tonic-gate 26697c478bd9Sstevel@tonic-gate static int 2670bbec428eSgjelinek fill_in_attrtab(cmd_t *cmd, struct zone_attrtab *attrtab, 2671bbec428eSgjelinek boolean_t fill_in_only) 26727c478bd9Sstevel@tonic-gate { 26737c478bd9Sstevel@tonic-gate int err, i; 26747c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 26757c478bd9Sstevel@tonic-gate 2676bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK) 26777c478bd9Sstevel@tonic-gate return (err); 26787c478bd9Sstevel@tonic-gate 2679e193d1e6Svp bzero(attrtab, sizeof (*attrtab)); 26807c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 26817c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i]; 26827c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 26837c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here.")); 2684bbec428eSgjelinek saw_error = B_TRUE; 26857c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 26867c478bd9Sstevel@tonic-gate } 26877c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) { 26887c478bd9Sstevel@tonic-gate case PT_NAME: 26897c478bd9Sstevel@tonic-gate (void) strlcpy(attrtab->zone_attr_name, pp->pv_simple, 26907c478bd9Sstevel@tonic-gate sizeof (attrtab->zone_attr_name)); 26917c478bd9Sstevel@tonic-gate break; 26927c478bd9Sstevel@tonic-gate case PT_TYPE: 26937c478bd9Sstevel@tonic-gate (void) strlcpy(attrtab->zone_attr_type, pp->pv_simple, 26947c478bd9Sstevel@tonic-gate sizeof (attrtab->zone_attr_type)); 26957c478bd9Sstevel@tonic-gate break; 26967c478bd9Sstevel@tonic-gate case PT_VALUE: 26977c478bd9Sstevel@tonic-gate (void) strlcpy(attrtab->zone_attr_value, pp->pv_simple, 26987c478bd9Sstevel@tonic-gate sizeof (attrtab->zone_attr_value)); 26997c478bd9Sstevel@tonic-gate break; 27007c478bd9Sstevel@tonic-gate default: 27017c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 2702bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE); 27037c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 27047c478bd9Sstevel@tonic-gate } 27057c478bd9Sstevel@tonic-gate } 27067c478bd9Sstevel@tonic-gate if (fill_in_only) 27077c478bd9Sstevel@tonic-gate return (Z_OK); 27087c478bd9Sstevel@tonic-gate err = zonecfg_lookup_attr(handle, attrtab); 27097c478bd9Sstevel@tonic-gate return (err); 27107c478bd9Sstevel@tonic-gate } 27117c478bd9Sstevel@tonic-gate 2712fa9e4066Sahrens static int 2713bbec428eSgjelinek fill_in_dstab(cmd_t *cmd, struct zone_dstab *dstab, boolean_t fill_in_only) 2714fa9e4066Sahrens { 2715fa9e4066Sahrens int err, i; 2716fa9e4066Sahrens property_value_ptr_t pp; 2717fa9e4066Sahrens 2718bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK) 2719fa9e4066Sahrens return (err); 2720fa9e4066Sahrens 2721fa9e4066Sahrens dstab->zone_dataset_name[0] = '\0'; 2722fa9e4066Sahrens for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 2723fa9e4066Sahrens pp = cmd->cmd_property_ptr[i]; 2724fa9e4066Sahrens if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 2725fa9e4066Sahrens zerr(gettext("A simple value was expected here.")); 2726bbec428eSgjelinek saw_error = B_TRUE; 2727fa9e4066Sahrens return (Z_INSUFFICIENT_SPEC); 2728fa9e4066Sahrens } 2729fa9e4066Sahrens switch (cmd->cmd_prop_name[i]) { 2730fa9e4066Sahrens case PT_NAME: 2731fa9e4066Sahrens (void) strlcpy(dstab->zone_dataset_name, pp->pv_simple, 2732fa9e4066Sahrens sizeof (dstab->zone_dataset_name)); 2733fa9e4066Sahrens break; 2734fa9e4066Sahrens default: 2735fa9e4066Sahrens zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 2736bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE); 2737fa9e4066Sahrens return (Z_INSUFFICIENT_SPEC); 2738fa9e4066Sahrens } 2739fa9e4066Sahrens } 2740fa9e4066Sahrens if (fill_in_only) 2741fa9e4066Sahrens return (Z_OK); 2742fa9e4066Sahrens return (zonecfg_lookup_ds(handle, dstab)); 2743fa9e4066Sahrens } 2744fa9e4066Sahrens 27457c478bd9Sstevel@tonic-gate static void 27460209230bSgjelinek remove_aliased_rctl(int type, char *name) 27477c478bd9Sstevel@tonic-gate { 27480209230bSgjelinek int err; 27490209230bSgjelinek uint64_t tmp; 27507c478bd9Sstevel@tonic-gate 27510209230bSgjelinek if ((err = zonecfg_get_aliased_rctl(handle, name, &tmp)) != Z_OK) { 27520209230bSgjelinek zerr("%s %s: %s", cmd_to_str(CMD_CLEAR), pt_to_str(type), 27530209230bSgjelinek zonecfg_strerror(err)); 2754bbec428eSgjelinek saw_error = B_TRUE; 27557c478bd9Sstevel@tonic-gate return; 27567c478bd9Sstevel@tonic-gate } 27570209230bSgjelinek if ((err = zonecfg_rm_aliased_rctl(handle, name)) != Z_OK) { 27580209230bSgjelinek zerr("%s %s: %s", cmd_to_str(CMD_CLEAR), pt_to_str(type), 27590209230bSgjelinek zonecfg_strerror(err)); 2760bbec428eSgjelinek saw_error = B_TRUE; 27610209230bSgjelinek } else { 2762bbec428eSgjelinek need_to_commit = B_TRUE; 27630209230bSgjelinek } 27640209230bSgjelinek } 27657c478bd9Sstevel@tonic-gate 27660209230bSgjelinek static boolean_t 27670209230bSgjelinek prompt_remove_resource(cmd_t *cmd, char *rsrc) 27680209230bSgjelinek { 27690209230bSgjelinek int num; 27700209230bSgjelinek int answer; 27710209230bSgjelinek int arg; 27720209230bSgjelinek boolean_t force = B_FALSE; 27730209230bSgjelinek char prompt[128]; 2774bbec428eSgjelinek boolean_t arg_err = B_FALSE; 27750209230bSgjelinek 27760209230bSgjelinek optind = 0; 27770209230bSgjelinek while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "F")) != EOF) { 27780209230bSgjelinek switch (arg) { 27790209230bSgjelinek case 'F': 27800209230bSgjelinek force = B_TRUE; 27810209230bSgjelinek break; 27820209230bSgjelinek default: 2783bbec428eSgjelinek arg_err = B_TRUE; 27847ec75eb8Sgjelinek break; 27850209230bSgjelinek } 27860209230bSgjelinek } 27877ec75eb8Sgjelinek if (arg_err) 27887ec75eb8Sgjelinek return (B_FALSE); 27897ec75eb8Sgjelinek 27900209230bSgjelinek 27910209230bSgjelinek num = zonecfg_num_resources(handle, rsrc); 27920209230bSgjelinek 27930209230bSgjelinek if (num == 0) { 27940209230bSgjelinek z_cmd_rt_perror(CMD_REMOVE, cmd->cmd_res_type, Z_NO_ENTRY, 2795bbec428eSgjelinek B_TRUE); 27960209230bSgjelinek return (B_FALSE); 27970209230bSgjelinek } 27980209230bSgjelinek if (num > 1 && !force) { 27990209230bSgjelinek if (!interactive_mode) { 28000209230bSgjelinek zerr(gettext("There are multiple instances of this " 28010209230bSgjelinek "resource. Either qualify the resource to\n" 28020209230bSgjelinek "remove a single instance or use the -F option to " 28030209230bSgjelinek "remove all instances.")); 2804bbec428eSgjelinek saw_error = B_TRUE; 28050209230bSgjelinek return (B_FALSE); 28060209230bSgjelinek } 28070209230bSgjelinek (void) snprintf(prompt, sizeof (prompt), gettext( 28080209230bSgjelinek "Are you sure you want to remove ALL '%s' resources"), 28090209230bSgjelinek rsrc); 2810bbec428eSgjelinek answer = ask_yesno(B_FALSE, prompt); 28110209230bSgjelinek if (answer == -1) { 28120209230bSgjelinek zerr(gettext("Resource incomplete.")); 28130209230bSgjelinek return (B_FALSE); 28140209230bSgjelinek } 28150209230bSgjelinek if (answer != 1) 28160209230bSgjelinek return (B_FALSE); 28170209230bSgjelinek } 28180209230bSgjelinek return (B_TRUE); 28190209230bSgjelinek } 28200209230bSgjelinek 28210209230bSgjelinek static void 28220209230bSgjelinek remove_fs(cmd_t *cmd) 28230209230bSgjelinek { 28240209230bSgjelinek int err; 28250209230bSgjelinek 28260209230bSgjelinek /* traditional, qualified fs removal */ 28270209230bSgjelinek if (cmd->cmd_prop_nv_pairs > 0) { 28280209230bSgjelinek struct zone_fstab fstab; 28297c478bd9Sstevel@tonic-gate 2830bbec428eSgjelinek if ((err = fill_in_fstab(cmd, &fstab, B_FALSE)) != Z_OK) { 2831bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_FS, err, B_TRUE); 28327c478bd9Sstevel@tonic-gate return; 28337c478bd9Sstevel@tonic-gate } 28347c478bd9Sstevel@tonic-gate if ((err = zonecfg_delete_filesystem(handle, &fstab)) != Z_OK) 2835bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_FS, err, B_TRUE); 28367c478bd9Sstevel@tonic-gate else 2837bbec428eSgjelinek need_to_commit = B_TRUE; 28387c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(fstab.zone_fs_options); 28397c478bd9Sstevel@tonic-gate return; 28400209230bSgjelinek } 28410209230bSgjelinek 28420209230bSgjelinek /* 28430209230bSgjelinek * unqualified fs removal. remove all fs's but prompt if more 28440209230bSgjelinek * than one. 28450209230bSgjelinek */ 28460209230bSgjelinek if (!prompt_remove_resource(cmd, "fs")) 28470209230bSgjelinek return; 28480209230bSgjelinek 28490209230bSgjelinek if ((err = zonecfg_del_all_resources(handle, "fs")) != Z_OK) 2850bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_FS, err, B_TRUE); 28510209230bSgjelinek else 2852bbec428eSgjelinek need_to_commit = B_TRUE; 28530209230bSgjelinek } 28540209230bSgjelinek 28550209230bSgjelinek static void 28560209230bSgjelinek remove_ipd(cmd_t *cmd) 28570209230bSgjelinek { 28580209230bSgjelinek int err; 28590209230bSgjelinek 28600209230bSgjelinek if (state_atleast(ZONE_STATE_INSTALLED)) { 28610209230bSgjelinek zerr(gettext("Zone %s already installed; %s %s not allowed."), 28620209230bSgjelinek zone, cmd_to_str(CMD_REMOVE), rt_to_str(RT_IPD)); 28630209230bSgjelinek return; 28640209230bSgjelinek } 28650209230bSgjelinek 28660209230bSgjelinek /* traditional, qualified ipd removal */ 28670209230bSgjelinek if (cmd->cmd_prop_nv_pairs > 0) { 28680209230bSgjelinek struct zone_fstab fstab; 28690209230bSgjelinek 2870bbec428eSgjelinek if ((err = fill_in_ipdtab(cmd, &fstab, B_FALSE)) != Z_OK) { 2871bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_IPD, err, B_TRUE); 28727c478bd9Sstevel@tonic-gate return; 28737c478bd9Sstevel@tonic-gate } 28747c478bd9Sstevel@tonic-gate if ((err = zonecfg_delete_ipd(handle, &fstab)) != Z_OK) 2875bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_IPD, err, B_TRUE); 28767c478bd9Sstevel@tonic-gate else 2877bbec428eSgjelinek need_to_commit = B_TRUE; 28787c478bd9Sstevel@tonic-gate return; 28790209230bSgjelinek } 28800209230bSgjelinek 28810209230bSgjelinek /* 28820209230bSgjelinek * unqualified ipd removal. remove all ipds but prompt if more 28830209230bSgjelinek * than one. 28840209230bSgjelinek */ 28850209230bSgjelinek if (!prompt_remove_resource(cmd, "inherit-pkg-dir")) 28860209230bSgjelinek return; 28870209230bSgjelinek 28880209230bSgjelinek if ((err = zonecfg_del_all_resources(handle, "inherit-pkg-dir")) 28890209230bSgjelinek != Z_OK) 2890bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_IPD, err, B_TRUE); 28910209230bSgjelinek else 2892bbec428eSgjelinek need_to_commit = B_TRUE; 28930209230bSgjelinek } 28940209230bSgjelinek 28950209230bSgjelinek static void 28960209230bSgjelinek remove_net(cmd_t *cmd) 28970209230bSgjelinek { 28980209230bSgjelinek int err; 28990209230bSgjelinek 29000209230bSgjelinek /* traditional, qualified net removal */ 29010209230bSgjelinek if (cmd->cmd_prop_nv_pairs > 0) { 29020209230bSgjelinek struct zone_nwiftab nwiftab; 29030209230bSgjelinek 2904bbec428eSgjelinek if ((err = fill_in_nwiftab(cmd, &nwiftab, B_FALSE)) != Z_OK) { 2905bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_NET, err, B_TRUE); 29067c478bd9Sstevel@tonic-gate return; 29077c478bd9Sstevel@tonic-gate } 29087c478bd9Sstevel@tonic-gate if ((err = zonecfg_delete_nwif(handle, &nwiftab)) != Z_OK) 2909bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_NET, err, B_TRUE); 29107c478bd9Sstevel@tonic-gate else 2911bbec428eSgjelinek need_to_commit = B_TRUE; 29127c478bd9Sstevel@tonic-gate return; 29130209230bSgjelinek } 29140209230bSgjelinek 29150209230bSgjelinek /* 29160209230bSgjelinek * unqualified net removal. remove all nets but prompt if more 29170209230bSgjelinek * than one. 29180209230bSgjelinek */ 29190209230bSgjelinek if (!prompt_remove_resource(cmd, "net")) 29200209230bSgjelinek return; 29210209230bSgjelinek 29220209230bSgjelinek if ((err = zonecfg_del_all_resources(handle, "net")) != Z_OK) 2923bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_NET, err, B_TRUE); 29240209230bSgjelinek else 2925bbec428eSgjelinek need_to_commit = B_TRUE; 29260209230bSgjelinek } 29270209230bSgjelinek 29280209230bSgjelinek static void 29290209230bSgjelinek remove_device(cmd_t *cmd) 29300209230bSgjelinek { 29310209230bSgjelinek int err; 29320209230bSgjelinek 29330209230bSgjelinek /* traditional, qualified device removal */ 29340209230bSgjelinek if (cmd->cmd_prop_nv_pairs > 0) { 29350209230bSgjelinek struct zone_devtab devtab; 29360209230bSgjelinek 2937bbec428eSgjelinek if ((err = fill_in_devtab(cmd, &devtab, B_FALSE)) != Z_OK) { 2938bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DEVICE, err, B_TRUE); 29397c478bd9Sstevel@tonic-gate return; 29407c478bd9Sstevel@tonic-gate } 29417c478bd9Sstevel@tonic-gate if ((err = zonecfg_delete_dev(handle, &devtab)) != Z_OK) 2942bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DEVICE, err, B_TRUE); 29437c478bd9Sstevel@tonic-gate else 2944bbec428eSgjelinek need_to_commit = B_TRUE; 29457c478bd9Sstevel@tonic-gate return; 29460209230bSgjelinek } 29470209230bSgjelinek 29480209230bSgjelinek /* 29490209230bSgjelinek * unqualified device removal. remove all devices but prompt if more 29500209230bSgjelinek * than one. 29510209230bSgjelinek */ 29520209230bSgjelinek if (!prompt_remove_resource(cmd, "device")) 29537c478bd9Sstevel@tonic-gate return; 29540209230bSgjelinek 29550209230bSgjelinek if ((err = zonecfg_del_all_resources(handle, "device")) != Z_OK) 2956bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DEVICE, err, B_TRUE); 29570209230bSgjelinek else 2958bbec428eSgjelinek need_to_commit = B_TRUE; 29590209230bSgjelinek } 29600209230bSgjelinek 29610209230bSgjelinek static void 29620209230bSgjelinek remove_attr(cmd_t *cmd) 29630209230bSgjelinek { 29640209230bSgjelinek int err; 29650209230bSgjelinek 29660209230bSgjelinek /* traditional, qualified attr removal */ 29670209230bSgjelinek if (cmd->cmd_prop_nv_pairs > 0) { 29680209230bSgjelinek struct zone_attrtab attrtab; 29690209230bSgjelinek 2970bbec428eSgjelinek if ((err = fill_in_attrtab(cmd, &attrtab, B_FALSE)) != Z_OK) { 2971bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_ATTR, err, B_TRUE); 29727c478bd9Sstevel@tonic-gate return; 29737c478bd9Sstevel@tonic-gate } 29747c478bd9Sstevel@tonic-gate if ((err = zonecfg_delete_attr(handle, &attrtab)) != Z_OK) 2975bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_ATTR, err, B_TRUE); 29767c478bd9Sstevel@tonic-gate else 2977bbec428eSgjelinek need_to_commit = B_TRUE; 29787c478bd9Sstevel@tonic-gate return; 29790209230bSgjelinek } 29800209230bSgjelinek 29810209230bSgjelinek /* 29820209230bSgjelinek * unqualified attr removal. remove all attrs but prompt if more 29830209230bSgjelinek * than one. 29840209230bSgjelinek */ 29850209230bSgjelinek if (!prompt_remove_resource(cmd, "attr")) 29860209230bSgjelinek return; 29870209230bSgjelinek 29880209230bSgjelinek if ((err = zonecfg_del_all_resources(handle, "attr")) != Z_OK) 2989bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_ATTR, err, B_TRUE); 29900209230bSgjelinek else 2991bbec428eSgjelinek need_to_commit = B_TRUE; 29920209230bSgjelinek } 29930209230bSgjelinek 29940209230bSgjelinek static void 29950209230bSgjelinek remove_dataset(cmd_t *cmd) 29960209230bSgjelinek { 29970209230bSgjelinek int err; 29980209230bSgjelinek 29990209230bSgjelinek /* traditional, qualified dataset removal */ 30000209230bSgjelinek if (cmd->cmd_prop_nv_pairs > 0) { 30010209230bSgjelinek struct zone_dstab dstab; 30020209230bSgjelinek 3003bbec428eSgjelinek if ((err = fill_in_dstab(cmd, &dstab, B_FALSE)) != Z_OK) { 3004bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DATASET, err, B_TRUE); 3005fa9e4066Sahrens return; 3006fa9e4066Sahrens } 3007fa9e4066Sahrens if ((err = zonecfg_delete_ds(handle, &dstab)) != Z_OK) 3008bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DATASET, err, B_TRUE); 3009fa9e4066Sahrens else 3010bbec428eSgjelinek need_to_commit = B_TRUE; 3011fa9e4066Sahrens return; 30127c478bd9Sstevel@tonic-gate } 30130209230bSgjelinek 30140209230bSgjelinek /* 30150209230bSgjelinek * unqualified dataset removal. remove all datasets but prompt if more 30160209230bSgjelinek * than one. 30170209230bSgjelinek */ 30180209230bSgjelinek if (!prompt_remove_resource(cmd, "dataset")) 30190209230bSgjelinek return; 30200209230bSgjelinek 30210209230bSgjelinek if ((err = zonecfg_del_all_resources(handle, "dataset")) != Z_OK) 3022bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DATASET, err, B_TRUE); 30230209230bSgjelinek else 3024bbec428eSgjelinek need_to_commit = B_TRUE; 30250209230bSgjelinek } 30260209230bSgjelinek 30270209230bSgjelinek static void 30280209230bSgjelinek remove_rctl(cmd_t *cmd) 30290209230bSgjelinek { 30300209230bSgjelinek int err; 30310209230bSgjelinek 30320209230bSgjelinek /* traditional, qualified rctl removal */ 30330209230bSgjelinek if (cmd->cmd_prop_nv_pairs > 0) { 30340209230bSgjelinek struct zone_rctltab rctltab; 30350209230bSgjelinek 3036bbec428eSgjelinek if ((err = fill_in_rctltab(cmd, &rctltab, B_FALSE)) != Z_OK) { 3037bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_RCTL, err, B_TRUE); 30380209230bSgjelinek return; 30390209230bSgjelinek } 30400209230bSgjelinek if ((err = zonecfg_delete_rctl(handle, &rctltab)) != Z_OK) 3041bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_RCTL, err, B_TRUE); 30420209230bSgjelinek else 3043bbec428eSgjelinek need_to_commit = B_TRUE; 30440209230bSgjelinek zonecfg_free_rctl_value_list(rctltab.zone_rctl_valptr); 30450209230bSgjelinek return; 30460209230bSgjelinek } 30470209230bSgjelinek 30480209230bSgjelinek /* 30490209230bSgjelinek * unqualified rctl removal. remove all rctls but prompt if more 30500209230bSgjelinek * than one. 30510209230bSgjelinek */ 30520209230bSgjelinek if (!prompt_remove_resource(cmd, "rctl")) 30530209230bSgjelinek return; 30540209230bSgjelinek 30550209230bSgjelinek if ((err = zonecfg_del_all_resources(handle, "rctl")) != Z_OK) 3056bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_RCTL, err, B_TRUE); 30570209230bSgjelinek else 3058bbec428eSgjelinek need_to_commit = B_TRUE; 30590209230bSgjelinek } 30600209230bSgjelinek 30610209230bSgjelinek static void 30620209230bSgjelinek remove_pset() 30630209230bSgjelinek { 30640209230bSgjelinek int err; 30650209230bSgjelinek struct zone_psettab psettab; 30660209230bSgjelinek 30670209230bSgjelinek if ((err = zonecfg_lookup_pset(handle, &psettab)) != Z_OK) { 3068bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DCPU, err, B_TRUE); 30690209230bSgjelinek return; 30700209230bSgjelinek } 30710209230bSgjelinek if ((err = zonecfg_delete_pset(handle)) != Z_OK) 3072bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DCPU, err, B_TRUE); 30730209230bSgjelinek else 3074bbec428eSgjelinek need_to_commit = B_TRUE; 30750209230bSgjelinek } 30760209230bSgjelinek 3077c97ad5cdSakolb static void 3078c97ad5cdSakolb remove_pcap() 3079c97ad5cdSakolb { 3080c97ad5cdSakolb int err; 3081c97ad5cdSakolb uint64_t tmp; 3082c97ad5cdSakolb 3083c97ad5cdSakolb if (zonecfg_get_aliased_rctl(handle, ALIAS_CPUCAP, &tmp) != Z_OK) { 3084c97ad5cdSakolb zerr("%s %s: %s", cmd_to_str(CMD_REMOVE), rt_to_str(RT_PCAP), 3085c97ad5cdSakolb zonecfg_strerror(Z_NO_RESOURCE_TYPE)); 3086bbec428eSgjelinek saw_error = B_TRUE; 3087c97ad5cdSakolb return; 3088c97ad5cdSakolb } 3089c97ad5cdSakolb 3090c97ad5cdSakolb if ((err = zonecfg_rm_aliased_rctl(handle, ALIAS_CPUCAP)) != Z_OK) 3091bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_PCAP, err, B_TRUE); 3092c97ad5cdSakolb else 3093bbec428eSgjelinek need_to_commit = B_TRUE; 3094c97ad5cdSakolb } 3095c97ad5cdSakolb 30960209230bSgjelinek static void 30970209230bSgjelinek remove_mcap() 30980209230bSgjelinek { 30990209230bSgjelinek int err, res1, res2, res3; 31000209230bSgjelinek uint64_t tmp; 31010209230bSgjelinek struct zone_mcaptab mcaptab; 31020209230bSgjelinek boolean_t revert = B_FALSE; 31030209230bSgjelinek 31040209230bSgjelinek res1 = zonecfg_lookup_mcap(handle, &mcaptab); 31050209230bSgjelinek res2 = zonecfg_get_aliased_rctl(handle, ALIAS_MAXSWAP, &tmp); 31060209230bSgjelinek res3 = zonecfg_get_aliased_rctl(handle, ALIAS_MAXLOCKEDMEM, &tmp); 31070209230bSgjelinek 31080209230bSgjelinek /* if none of these exist, there is no resource to remove */ 31090209230bSgjelinek if (res1 != Z_OK && res2 != Z_OK && res3 != Z_OK) { 31100209230bSgjelinek zerr("%s %s: %s", cmd_to_str(CMD_REMOVE), rt_to_str(RT_MCAP), 31110209230bSgjelinek zonecfg_strerror(Z_NO_RESOURCE_TYPE)); 3112bbec428eSgjelinek saw_error = B_TRUE; 31130209230bSgjelinek return; 31140209230bSgjelinek } 31150209230bSgjelinek if (res1 == Z_OK) { 31160209230bSgjelinek if ((err = zonecfg_delete_mcap(handle)) != Z_OK) { 3117bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_MCAP, err, B_TRUE); 31180209230bSgjelinek revert = B_TRUE; 31190209230bSgjelinek } else { 3120bbec428eSgjelinek need_to_commit = B_TRUE; 31210209230bSgjelinek } 31220209230bSgjelinek } 31230209230bSgjelinek if (res2 == Z_OK) { 31240209230bSgjelinek if ((err = zonecfg_rm_aliased_rctl(handle, ALIAS_MAXSWAP)) 31250209230bSgjelinek != Z_OK) { 3126bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_MCAP, err, B_TRUE); 31270209230bSgjelinek revert = B_TRUE; 31280209230bSgjelinek } else { 3129bbec428eSgjelinek need_to_commit = B_TRUE; 31300209230bSgjelinek } 31310209230bSgjelinek } 31320209230bSgjelinek if (res3 == Z_OK) { 31330209230bSgjelinek if ((err = zonecfg_rm_aliased_rctl(handle, ALIAS_MAXLOCKEDMEM)) 31340209230bSgjelinek != Z_OK) { 3135bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_MCAP, err, B_TRUE); 31360209230bSgjelinek revert = B_TRUE; 31370209230bSgjelinek } else { 3138bbec428eSgjelinek need_to_commit = B_TRUE; 31390209230bSgjelinek } 31400209230bSgjelinek } 31410209230bSgjelinek 31420209230bSgjelinek if (revert) 3143bbec428eSgjelinek need_to_commit = B_FALSE; 31440209230bSgjelinek } 31450209230bSgjelinek 31460209230bSgjelinek static void 31470209230bSgjelinek remove_resource(cmd_t *cmd) 31480209230bSgjelinek { 31490209230bSgjelinek int type; 31500209230bSgjelinek int arg; 3151bbec428eSgjelinek boolean_t arg_err = B_FALSE; 31520209230bSgjelinek 31530209230bSgjelinek if ((type = cmd->cmd_res_type) == RT_UNKNOWN) { 3154bbec428eSgjelinek long_usage(CMD_REMOVE, B_TRUE); 31550209230bSgjelinek return; 31560209230bSgjelinek } 31570209230bSgjelinek 31580209230bSgjelinek optind = 0; 31590209230bSgjelinek while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?F")) != EOF) { 31600209230bSgjelinek switch (arg) { 31610209230bSgjelinek case '?': 31620209230bSgjelinek longer_usage(CMD_REMOVE); 3163bbec428eSgjelinek arg_err = B_TRUE; 31647ec75eb8Sgjelinek break; 31650209230bSgjelinek case 'F': 31660209230bSgjelinek break; 31670209230bSgjelinek default: 31680209230bSgjelinek short_usage(CMD_REMOVE); 3169bbec428eSgjelinek arg_err = B_TRUE; 31707ec75eb8Sgjelinek break; 31710209230bSgjelinek } 31720209230bSgjelinek } 31737ec75eb8Sgjelinek if (arg_err) 31747ec75eb8Sgjelinek return; 31750209230bSgjelinek 3176bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 31770209230bSgjelinek return; 31780209230bSgjelinek 31790209230bSgjelinek switch (type) { 31800209230bSgjelinek case RT_FS: 31810209230bSgjelinek remove_fs(cmd); 31820209230bSgjelinek return; 31830209230bSgjelinek case RT_IPD: 31840209230bSgjelinek remove_ipd(cmd); 31850209230bSgjelinek return; 31860209230bSgjelinek case RT_NET: 31870209230bSgjelinek remove_net(cmd); 31880209230bSgjelinek return; 31890209230bSgjelinek case RT_DEVICE: 31900209230bSgjelinek remove_device(cmd); 31910209230bSgjelinek return; 31920209230bSgjelinek case RT_RCTL: 31930209230bSgjelinek remove_rctl(cmd); 31940209230bSgjelinek return; 31950209230bSgjelinek case RT_ATTR: 31960209230bSgjelinek remove_attr(cmd); 31970209230bSgjelinek return; 31980209230bSgjelinek case RT_DATASET: 31990209230bSgjelinek remove_dataset(cmd); 32000209230bSgjelinek return; 32010209230bSgjelinek case RT_DCPU: 32020209230bSgjelinek remove_pset(); 32030209230bSgjelinek return; 3204c97ad5cdSakolb case RT_PCAP: 3205c97ad5cdSakolb remove_pcap(); 3206c97ad5cdSakolb return; 32070209230bSgjelinek case RT_MCAP: 32080209230bSgjelinek remove_mcap(); 32090209230bSgjelinek return; 32100209230bSgjelinek default: 3211bbec428eSgjelinek zone_perror(rt_to_str(type), Z_NO_RESOURCE_TYPE, B_TRUE); 3212bbec428eSgjelinek long_usage(CMD_REMOVE, B_TRUE); 3213bbec428eSgjelinek usage(B_FALSE, HELP_RESOURCES); 32140209230bSgjelinek return; 32150209230bSgjelinek } 32160209230bSgjelinek } 32177c478bd9Sstevel@tonic-gate 32187c478bd9Sstevel@tonic-gate static void 32197c478bd9Sstevel@tonic-gate remove_property(cmd_t *cmd) 32207c478bd9Sstevel@tonic-gate { 32217c478bd9Sstevel@tonic-gate char *prop_id; 32227c478bd9Sstevel@tonic-gate int err, res_type, prop_type; 32237c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 32247c478bd9Sstevel@tonic-gate struct zone_rctlvaltab *rctlvaltab; 32257c478bd9Sstevel@tonic-gate complex_property_ptr_t cx; 32267c478bd9Sstevel@tonic-gate 32277c478bd9Sstevel@tonic-gate res_type = resource_scope; 32287c478bd9Sstevel@tonic-gate prop_type = cmd->cmd_prop_name[0]; 32297c478bd9Sstevel@tonic-gate if (res_type == RT_UNKNOWN || prop_type == PT_UNKNOWN) { 3230bbec428eSgjelinek long_usage(CMD_REMOVE, B_TRUE); 32317c478bd9Sstevel@tonic-gate return; 32327c478bd9Sstevel@tonic-gate } 32337c478bd9Sstevel@tonic-gate 32347c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs != 1) { 3235bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 32367c478bd9Sstevel@tonic-gate return; 32377c478bd9Sstevel@tonic-gate } 32387c478bd9Sstevel@tonic-gate 3239bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 32407c478bd9Sstevel@tonic-gate return; 32417c478bd9Sstevel@tonic-gate 32427c478bd9Sstevel@tonic-gate switch (res_type) { 32437c478bd9Sstevel@tonic-gate case RT_FS: 32447c478bd9Sstevel@tonic-gate if (prop_type != PT_OPTIONS) { 32457c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 3246bbec428eSgjelinek B_TRUE); 3247bbec428eSgjelinek long_usage(CMD_REMOVE, B_TRUE); 3248bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 32497c478bd9Sstevel@tonic-gate return; 32507c478bd9Sstevel@tonic-gate } 32517c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[0]; 32527c478bd9Sstevel@tonic-gate if (pp->pv_type == PROP_VAL_COMPLEX) { 32537c478bd9Sstevel@tonic-gate zerr(gettext("A %s or %s value was expected here."), 32547c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_SIMPLE), 32557c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_LIST)); 3256bbec428eSgjelinek saw_error = B_TRUE; 32577c478bd9Sstevel@tonic-gate return; 32587c478bd9Sstevel@tonic-gate } 32597c478bd9Sstevel@tonic-gate if (pp->pv_type == PROP_VAL_SIMPLE) { 32607c478bd9Sstevel@tonic-gate if (pp->pv_simple == NULL) { 3261bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 32627c478bd9Sstevel@tonic-gate return; 32637c478bd9Sstevel@tonic-gate } 32647c478bd9Sstevel@tonic-gate prop_id = pp->pv_simple; 32657c478bd9Sstevel@tonic-gate err = zonecfg_remove_fs_option(&in_progress_fstab, 32667c478bd9Sstevel@tonic-gate prop_id); 32677c478bd9Sstevel@tonic-gate if (err != Z_OK) 3268bbec428eSgjelinek zone_perror(pt_to_str(prop_type), err, B_TRUE); 32697c478bd9Sstevel@tonic-gate } else { 32707c478bd9Sstevel@tonic-gate list_property_ptr_t list; 32717c478bd9Sstevel@tonic-gate 32727c478bd9Sstevel@tonic-gate for (list = pp->pv_list; list != NULL; 32737c478bd9Sstevel@tonic-gate list = list->lp_next) { 32747c478bd9Sstevel@tonic-gate prop_id = list->lp_simple; 32757c478bd9Sstevel@tonic-gate if (prop_id == NULL) 32767c478bd9Sstevel@tonic-gate break; 32777c478bd9Sstevel@tonic-gate err = zonecfg_remove_fs_option( 32787c478bd9Sstevel@tonic-gate &in_progress_fstab, prop_id); 32797c478bd9Sstevel@tonic-gate if (err != Z_OK) 32807c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), err, 3281bbec428eSgjelinek B_TRUE); 32827c478bd9Sstevel@tonic-gate } 32837c478bd9Sstevel@tonic-gate } 32847c478bd9Sstevel@tonic-gate return; 32857c478bd9Sstevel@tonic-gate case RT_RCTL: 32867c478bd9Sstevel@tonic-gate if (prop_type != PT_VALUE) { 32877c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 3288bbec428eSgjelinek B_TRUE); 3289bbec428eSgjelinek long_usage(CMD_REMOVE, B_TRUE); 3290bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 32917c478bd9Sstevel@tonic-gate return; 32927c478bd9Sstevel@tonic-gate } 32937c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[0]; 32947c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_COMPLEX) { 32957c478bd9Sstevel@tonic-gate zerr(gettext("A %s value was expected here."), 32967c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_COMPLEX)); 3297bbec428eSgjelinek saw_error = B_TRUE; 32987c478bd9Sstevel@tonic-gate return; 32997c478bd9Sstevel@tonic-gate } 33007c478bd9Sstevel@tonic-gate if ((rctlvaltab = alloc_rctlvaltab()) == NULL) { 3301bbec428eSgjelinek zone_perror(zone, Z_NOMEM, B_TRUE); 33027c478bd9Sstevel@tonic-gate exit(Z_ERR); 33037c478bd9Sstevel@tonic-gate } 33047c478bd9Sstevel@tonic-gate for (cx = pp->pv_complex; cx != NULL; cx = cx->cp_next) { 33057c478bd9Sstevel@tonic-gate switch (cx->cp_type) { 33067c478bd9Sstevel@tonic-gate case PT_PRIV: 33077c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_priv, 33087c478bd9Sstevel@tonic-gate cx->cp_value, 33097c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_priv)); 33107c478bd9Sstevel@tonic-gate break; 33117c478bd9Sstevel@tonic-gate case PT_LIMIT: 33127c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_limit, 33137c478bd9Sstevel@tonic-gate cx->cp_value, 33147c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_limit)); 33157c478bd9Sstevel@tonic-gate break; 33167c478bd9Sstevel@tonic-gate case PT_ACTION: 33177c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_action, 33187c478bd9Sstevel@tonic-gate cx->cp_value, 33197c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_action)); 33207c478bd9Sstevel@tonic-gate break; 33217c478bd9Sstevel@tonic-gate default: 33227c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), 3323bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE); 3324bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 3325bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 33267c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctlvaltab); 33277c478bd9Sstevel@tonic-gate return; 33287c478bd9Sstevel@tonic-gate } 33297c478bd9Sstevel@tonic-gate } 33307c478bd9Sstevel@tonic-gate rctlvaltab->zone_rctlval_next = NULL; 33317c478bd9Sstevel@tonic-gate err = zonecfg_remove_rctl_value(&in_progress_rctltab, 33327c478bd9Sstevel@tonic-gate rctlvaltab); 33337c478bd9Sstevel@tonic-gate if (err != Z_OK) 3334bbec428eSgjelinek zone_perror(pt_to_str(prop_type), err, B_TRUE); 33357c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctlvaltab); 33367c478bd9Sstevel@tonic-gate return; 3337de860bd9Sgfaden case RT_NET: 3338de860bd9Sgfaden if (prop_type != PT_DEFROUTER) { 3339de860bd9Sgfaden zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 3340bbec428eSgjelinek B_TRUE); 3341bbec428eSgjelinek long_usage(CMD_REMOVE, B_TRUE); 3342bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 3343de860bd9Sgfaden return; 3344de860bd9Sgfaden } else { 3345de860bd9Sgfaden bzero(&in_progress_nwiftab.zone_nwif_defrouter, 3346de860bd9Sgfaden sizeof (in_progress_nwiftab.zone_nwif_defrouter)); 3347de860bd9Sgfaden return; 3348de860bd9Sgfaden } 33497c478bd9Sstevel@tonic-gate default: 3350bbec428eSgjelinek zone_perror(rt_to_str(res_type), Z_NO_RESOURCE_TYPE, B_TRUE); 3351bbec428eSgjelinek long_usage(CMD_REMOVE, B_TRUE); 3352bbec428eSgjelinek usage(B_FALSE, HELP_RESOURCES); 33537c478bd9Sstevel@tonic-gate return; 33547c478bd9Sstevel@tonic-gate } 33557c478bd9Sstevel@tonic-gate } 33567c478bd9Sstevel@tonic-gate 33577c478bd9Sstevel@tonic-gate void 33587c478bd9Sstevel@tonic-gate remove_func(cmd_t *cmd) 33597c478bd9Sstevel@tonic-gate { 33607c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_REMOVE)) 33617c478bd9Sstevel@tonic-gate return; 33627c478bd9Sstevel@tonic-gate 33637c478bd9Sstevel@tonic-gate assert(cmd != NULL); 33647c478bd9Sstevel@tonic-gate 33650209230bSgjelinek if (global_scope) { 33660209230bSgjelinek if (gz_invalid_resource(cmd->cmd_res_type)) { 33670209230bSgjelinek zerr(gettext("%s is not a valid resource for the " 33680209230bSgjelinek "global zone."), rt_to_str(cmd->cmd_res_type)); 3369bbec428eSgjelinek saw_error = B_TRUE; 33700209230bSgjelinek return; 33710209230bSgjelinek } 33727c478bd9Sstevel@tonic-gate remove_resource(cmd); 33730209230bSgjelinek } else { 33747c478bd9Sstevel@tonic-gate remove_property(cmd); 33750209230bSgjelinek } 33760209230bSgjelinek } 33770209230bSgjelinek 33780209230bSgjelinek static void 33790209230bSgjelinek clear_property(cmd_t *cmd) 33800209230bSgjelinek { 33810209230bSgjelinek int res_type, prop_type; 33820209230bSgjelinek 33830209230bSgjelinek res_type = resource_scope; 33840209230bSgjelinek prop_type = cmd->cmd_res_type; 33850209230bSgjelinek if (res_type == RT_UNKNOWN || prop_type == PT_UNKNOWN) { 3386bbec428eSgjelinek long_usage(CMD_CLEAR, B_TRUE); 33870209230bSgjelinek return; 33880209230bSgjelinek } 33890209230bSgjelinek 3390bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 33910209230bSgjelinek return; 33920209230bSgjelinek 33930209230bSgjelinek switch (res_type) { 33940209230bSgjelinek case RT_FS: 33950209230bSgjelinek if (prop_type == PT_RAW) { 33960209230bSgjelinek in_progress_fstab.zone_fs_raw[0] = '\0'; 3397bbec428eSgjelinek need_to_commit = B_TRUE; 33980209230bSgjelinek return; 33990209230bSgjelinek } 34000209230bSgjelinek break; 34010209230bSgjelinek case RT_DCPU: 34020209230bSgjelinek if (prop_type == PT_IMPORTANCE) { 34030209230bSgjelinek in_progress_psettab.zone_importance[0] = '\0'; 3404bbec428eSgjelinek need_to_commit = B_TRUE; 34050209230bSgjelinek return; 34060209230bSgjelinek } 34070209230bSgjelinek break; 34080209230bSgjelinek case RT_MCAP: 34090209230bSgjelinek switch (prop_type) { 34100209230bSgjelinek case PT_PHYSICAL: 34110209230bSgjelinek in_progress_mcaptab.zone_physmem_cap[0] = '\0'; 3412bbec428eSgjelinek need_to_commit = B_TRUE; 34130209230bSgjelinek return; 34140209230bSgjelinek case PT_SWAP: 34150209230bSgjelinek remove_aliased_rctl(PT_SWAP, ALIAS_MAXSWAP); 34160209230bSgjelinek return; 34170209230bSgjelinek case PT_LOCKED: 34180209230bSgjelinek remove_aliased_rctl(PT_LOCKED, ALIAS_MAXLOCKEDMEM); 34190209230bSgjelinek return; 34200209230bSgjelinek } 34210209230bSgjelinek break; 34220209230bSgjelinek default: 34230209230bSgjelinek break; 34240209230bSgjelinek } 34250209230bSgjelinek 3426bbec428eSgjelinek zone_perror(pt_to_str(prop_type), Z_CLEAR_DISALLOW, B_TRUE); 34270209230bSgjelinek } 34280209230bSgjelinek 34290209230bSgjelinek static void 34300209230bSgjelinek clear_global(cmd_t *cmd) 34310209230bSgjelinek { 34320209230bSgjelinek int err, type; 34330209230bSgjelinek 34340209230bSgjelinek if ((type = cmd->cmd_res_type) == RT_UNKNOWN) { 3435bbec428eSgjelinek long_usage(CMD_CLEAR, B_TRUE); 34360209230bSgjelinek return; 34370209230bSgjelinek } 34380209230bSgjelinek 3439bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 34400209230bSgjelinek return; 34410209230bSgjelinek 34420209230bSgjelinek switch (type) { 34430209230bSgjelinek case PT_ZONENAME: 34440209230bSgjelinek /* FALLTHRU */ 34450209230bSgjelinek case PT_ZONEPATH: 34460209230bSgjelinek /* FALLTHRU */ 34470209230bSgjelinek case PT_BRAND: 3448bbec428eSgjelinek zone_perror(pt_to_str(type), Z_CLEAR_DISALLOW, B_TRUE); 34490209230bSgjelinek return; 34500209230bSgjelinek case PT_AUTOBOOT: 34510209230bSgjelinek /* false is default; we'll treat as equivalent to clearing */ 34520209230bSgjelinek if ((err = zonecfg_set_autoboot(handle, B_FALSE)) != Z_OK) 3453bbec428eSgjelinek z_cmd_rt_perror(CMD_CLEAR, RT_AUTOBOOT, err, B_TRUE); 34540209230bSgjelinek else 3455bbec428eSgjelinek need_to_commit = B_TRUE; 34560209230bSgjelinek return; 34570209230bSgjelinek case PT_POOL: 34580209230bSgjelinek if ((err = zonecfg_set_pool(handle, NULL)) != Z_OK) 3459bbec428eSgjelinek z_cmd_rt_perror(CMD_CLEAR, RT_POOL, err, B_TRUE); 34600209230bSgjelinek else 3461bbec428eSgjelinek need_to_commit = B_TRUE; 34620209230bSgjelinek return; 34630209230bSgjelinek case PT_LIMITPRIV: 34640209230bSgjelinek if ((err = zonecfg_set_limitpriv(handle, NULL)) != Z_OK) 3465bbec428eSgjelinek z_cmd_rt_perror(CMD_CLEAR, RT_LIMITPRIV, err, B_TRUE); 34660209230bSgjelinek else 3467bbec428eSgjelinek need_to_commit = B_TRUE; 34680209230bSgjelinek return; 34690209230bSgjelinek case PT_BOOTARGS: 34700209230bSgjelinek if ((err = zonecfg_set_bootargs(handle, NULL)) != Z_OK) 3471bbec428eSgjelinek z_cmd_rt_perror(CMD_CLEAR, RT_BOOTARGS, err, B_TRUE); 34720209230bSgjelinek else 3473bbec428eSgjelinek need_to_commit = B_TRUE; 34740209230bSgjelinek return; 34750209230bSgjelinek case PT_SCHED: 34760209230bSgjelinek if ((err = zonecfg_set_sched(handle, NULL)) != Z_OK) 3477bbec428eSgjelinek z_cmd_rt_perror(CMD_CLEAR, RT_SCHED, err, B_TRUE); 34780209230bSgjelinek else 3479bbec428eSgjelinek need_to_commit = B_TRUE; 34800209230bSgjelinek return; 3481f4b3ec61Sdh case PT_IPTYPE: 3482f4b3ec61Sdh /* shared is default; we'll treat as equivalent to clearing */ 3483f4b3ec61Sdh if ((err = zonecfg_set_iptype(handle, ZS_SHARED)) != Z_OK) 3484bbec428eSgjelinek z_cmd_rt_perror(CMD_CLEAR, RT_IPTYPE, err, B_TRUE); 3485f4b3ec61Sdh else 3486bbec428eSgjelinek need_to_commit = B_TRUE; 3487f4b3ec61Sdh return; 34880209230bSgjelinek case PT_MAXLWPS: 34890209230bSgjelinek remove_aliased_rctl(PT_MAXLWPS, ALIAS_MAXLWPS); 34900209230bSgjelinek return; 34910209230bSgjelinek case PT_MAXSHMMEM: 34920209230bSgjelinek remove_aliased_rctl(PT_MAXSHMMEM, ALIAS_MAXSHMMEM); 34930209230bSgjelinek return; 34940209230bSgjelinek case PT_MAXSHMIDS: 34950209230bSgjelinek remove_aliased_rctl(PT_MAXSHMIDS, ALIAS_MAXSHMIDS); 34960209230bSgjelinek return; 34970209230bSgjelinek case PT_MAXMSGIDS: 34980209230bSgjelinek remove_aliased_rctl(PT_MAXMSGIDS, ALIAS_MAXMSGIDS); 34990209230bSgjelinek return; 35000209230bSgjelinek case PT_MAXSEMIDS: 35010209230bSgjelinek remove_aliased_rctl(PT_MAXSEMIDS, ALIAS_MAXSEMIDS); 35020209230bSgjelinek return; 35030209230bSgjelinek case PT_SHARES: 35040209230bSgjelinek remove_aliased_rctl(PT_SHARES, ALIAS_SHARES); 35050209230bSgjelinek return; 35065679c89fSjv case PT_HOSTID: 35075679c89fSjv if ((err = zonecfg_set_hostid(handle, NULL)) != Z_OK) 35085679c89fSjv z_cmd_rt_perror(CMD_CLEAR, RT_HOSTID, err, B_TRUE); 35095679c89fSjv else 35105679c89fSjv need_to_commit = B_TRUE; 35115679c89fSjv return; 35120209230bSgjelinek default: 3513bbec428eSgjelinek zone_perror(pt_to_str(type), Z_NO_PROPERTY_TYPE, B_TRUE); 3514bbec428eSgjelinek long_usage(CMD_CLEAR, B_TRUE); 3515bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 35160209230bSgjelinek return; 35170209230bSgjelinek } 35180209230bSgjelinek } 35190209230bSgjelinek 35200209230bSgjelinek void 35210209230bSgjelinek clear_func(cmd_t *cmd) 35220209230bSgjelinek { 35230209230bSgjelinek if (zone_is_read_only(CMD_CLEAR)) 35240209230bSgjelinek return; 35250209230bSgjelinek 35260209230bSgjelinek assert(cmd != NULL); 35270209230bSgjelinek 35280209230bSgjelinek if (global_scope) { 35290209230bSgjelinek if (gz_invalid_property(cmd->cmd_res_type)) { 35300209230bSgjelinek zerr(gettext("%s is not a valid property for the " 35310209230bSgjelinek "global zone."), pt_to_str(cmd->cmd_res_type)); 3532bbec428eSgjelinek saw_error = B_TRUE; 35330209230bSgjelinek return; 35340209230bSgjelinek } 35350209230bSgjelinek 35360209230bSgjelinek clear_global(cmd); 35370209230bSgjelinek } else { 35380209230bSgjelinek clear_property(cmd); 35390209230bSgjelinek } 35407c478bd9Sstevel@tonic-gate } 35417c478bd9Sstevel@tonic-gate 35427c478bd9Sstevel@tonic-gate void 35437c478bd9Sstevel@tonic-gate select_func(cmd_t *cmd) 35447c478bd9Sstevel@tonic-gate { 35450209230bSgjelinek int type, err, res; 35460209230bSgjelinek uint64_t limit; 3547c97ad5cdSakolb uint64_t tmp; 35487c478bd9Sstevel@tonic-gate 35497c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_SELECT)) 35507c478bd9Sstevel@tonic-gate return; 35517c478bd9Sstevel@tonic-gate 35527c478bd9Sstevel@tonic-gate assert(cmd != NULL); 35537c478bd9Sstevel@tonic-gate 35547c478bd9Sstevel@tonic-gate if (global_scope) { 3555bbec428eSgjelinek global_scope = B_FALSE; 35567c478bd9Sstevel@tonic-gate resource_scope = cmd->cmd_res_type; 35577c478bd9Sstevel@tonic-gate end_op = CMD_SELECT; 35587c478bd9Sstevel@tonic-gate } else { 35597c478bd9Sstevel@tonic-gate scope_usage(CMD_SELECT); 35607c478bd9Sstevel@tonic-gate return; 35617c478bd9Sstevel@tonic-gate } 35627c478bd9Sstevel@tonic-gate 35637c478bd9Sstevel@tonic-gate if ((type = cmd->cmd_res_type) == RT_UNKNOWN) { 3564bbec428eSgjelinek long_usage(CMD_SELECT, B_TRUE); 35657c478bd9Sstevel@tonic-gate return; 35667c478bd9Sstevel@tonic-gate } 35677c478bd9Sstevel@tonic-gate 3568bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 35697c478bd9Sstevel@tonic-gate return; 35707c478bd9Sstevel@tonic-gate 35717c478bd9Sstevel@tonic-gate switch (type) { 35727c478bd9Sstevel@tonic-gate case RT_FS: 3573bbec428eSgjelinek if ((err = fill_in_fstab(cmd, &old_fstab, B_FALSE)) != Z_OK) { 3574bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_FS, err, B_TRUE); 3575bbec428eSgjelinek global_scope = B_TRUE; 35767c478bd9Sstevel@tonic-gate } 35777c478bd9Sstevel@tonic-gate bcopy(&old_fstab, &in_progress_fstab, 35787c478bd9Sstevel@tonic-gate sizeof (struct zone_fstab)); 35797c478bd9Sstevel@tonic-gate return; 35807c478bd9Sstevel@tonic-gate case RT_IPD: 3581087719fdSdp if (state_atleast(ZONE_STATE_INCOMPLETE)) { 35827c478bd9Sstevel@tonic-gate zerr(gettext("Zone %s not in %s state; %s %s not " 35837c478bd9Sstevel@tonic-gate "allowed."), zone, 35847c478bd9Sstevel@tonic-gate zone_state_str(ZONE_STATE_CONFIGURED), 35857c478bd9Sstevel@tonic-gate cmd_to_str(CMD_SELECT), rt_to_str(RT_IPD)); 3586bbec428eSgjelinek global_scope = B_TRUE; 35877c478bd9Sstevel@tonic-gate end_op = -1; 35887c478bd9Sstevel@tonic-gate return; 35897c478bd9Sstevel@tonic-gate } 3590bbec428eSgjelinek if ((err = fill_in_ipdtab(cmd, &old_ipdtab, B_FALSE)) != Z_OK) { 3591bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_IPD, err, B_TRUE); 3592bbec428eSgjelinek global_scope = B_TRUE; 35937c478bd9Sstevel@tonic-gate } 35947c478bd9Sstevel@tonic-gate bcopy(&old_ipdtab, &in_progress_ipdtab, 35957c478bd9Sstevel@tonic-gate sizeof (struct zone_fstab)); 35967c478bd9Sstevel@tonic-gate return; 35977c478bd9Sstevel@tonic-gate case RT_NET: 3598bbec428eSgjelinek if ((err = fill_in_nwiftab(cmd, &old_nwiftab, B_FALSE)) 3599bbec428eSgjelinek != Z_OK) { 3600bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_NET, err, B_TRUE); 3601bbec428eSgjelinek global_scope = B_TRUE; 36027c478bd9Sstevel@tonic-gate } 36037c478bd9Sstevel@tonic-gate bcopy(&old_nwiftab, &in_progress_nwiftab, 36047c478bd9Sstevel@tonic-gate sizeof (struct zone_nwiftab)); 36057c478bd9Sstevel@tonic-gate return; 36067c478bd9Sstevel@tonic-gate case RT_DEVICE: 3607bbec428eSgjelinek if ((err = fill_in_devtab(cmd, &old_devtab, B_FALSE)) != Z_OK) { 3608bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_DEVICE, err, B_TRUE); 3609bbec428eSgjelinek global_scope = B_TRUE; 36107c478bd9Sstevel@tonic-gate } 36117c478bd9Sstevel@tonic-gate bcopy(&old_devtab, &in_progress_devtab, 36127c478bd9Sstevel@tonic-gate sizeof (struct zone_devtab)); 36137c478bd9Sstevel@tonic-gate return; 36147c478bd9Sstevel@tonic-gate case RT_RCTL: 3615bbec428eSgjelinek if ((err = fill_in_rctltab(cmd, &old_rctltab, B_FALSE)) 3616bbec428eSgjelinek != Z_OK) { 3617bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_RCTL, err, B_TRUE); 3618bbec428eSgjelinek global_scope = B_TRUE; 36197c478bd9Sstevel@tonic-gate } 36207c478bd9Sstevel@tonic-gate bcopy(&old_rctltab, &in_progress_rctltab, 36217c478bd9Sstevel@tonic-gate sizeof (struct zone_rctltab)); 36227c478bd9Sstevel@tonic-gate return; 36237c478bd9Sstevel@tonic-gate case RT_ATTR: 3624bbec428eSgjelinek if ((err = fill_in_attrtab(cmd, &old_attrtab, B_FALSE)) 3625bbec428eSgjelinek != Z_OK) { 3626bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_ATTR, err, B_TRUE); 3627bbec428eSgjelinek global_scope = B_TRUE; 36287c478bd9Sstevel@tonic-gate } 36297c478bd9Sstevel@tonic-gate bcopy(&old_attrtab, &in_progress_attrtab, 36307c478bd9Sstevel@tonic-gate sizeof (struct zone_attrtab)); 36317c478bd9Sstevel@tonic-gate return; 3632fa9e4066Sahrens case RT_DATASET: 3633bbec428eSgjelinek if ((err = fill_in_dstab(cmd, &old_dstab, B_FALSE)) != Z_OK) { 3634bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_DATASET, err, B_TRUE); 3635bbec428eSgjelinek global_scope = B_TRUE; 3636fa9e4066Sahrens } 3637fa9e4066Sahrens bcopy(&old_dstab, &in_progress_dstab, 3638fa9e4066Sahrens sizeof (struct zone_dstab)); 3639fa9e4066Sahrens return; 36400209230bSgjelinek case RT_DCPU: 36410209230bSgjelinek if ((err = zonecfg_lookup_pset(handle, &old_psettab)) != Z_OK) { 3642bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_DCPU, err, B_TRUE); 3643bbec428eSgjelinek global_scope = B_TRUE; 36440209230bSgjelinek } 36450209230bSgjelinek bcopy(&old_psettab, &in_progress_psettab, 36460209230bSgjelinek sizeof (struct zone_psettab)); 36470209230bSgjelinek return; 3648c97ad5cdSakolb case RT_PCAP: 3649c97ad5cdSakolb if ((err = zonecfg_get_aliased_rctl(handle, ALIAS_CPUCAP, &tmp)) 3650c97ad5cdSakolb != Z_OK) { 3651bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_PCAP, err, B_TRUE); 3652bbec428eSgjelinek global_scope = B_TRUE; 3653c97ad5cdSakolb } 3654c97ad5cdSakolb return; 36550209230bSgjelinek case RT_MCAP: 36560209230bSgjelinek /* if none of these exist, there is no resource to select */ 36570209230bSgjelinek if ((res = zonecfg_lookup_mcap(handle, &old_mcaptab)) != Z_OK && 36580209230bSgjelinek zonecfg_get_aliased_rctl(handle, ALIAS_MAXSWAP, &limit) 36590209230bSgjelinek != Z_OK && 36600209230bSgjelinek zonecfg_get_aliased_rctl(handle, ALIAS_MAXLOCKEDMEM, &limit) 36610209230bSgjelinek != Z_OK) { 36620209230bSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_MCAP, Z_NO_RESOURCE_TYPE, 3663bbec428eSgjelinek B_TRUE); 3664bbec428eSgjelinek global_scope = B_TRUE; 36650209230bSgjelinek } 36660209230bSgjelinek if (res == Z_OK) 36670209230bSgjelinek bcopy(&old_mcaptab, &in_progress_mcaptab, 36680209230bSgjelinek sizeof (struct zone_mcaptab)); 36690209230bSgjelinek else 36700209230bSgjelinek bzero(&in_progress_mcaptab, 36710209230bSgjelinek sizeof (in_progress_mcaptab)); 36720209230bSgjelinek return; 36737c478bd9Sstevel@tonic-gate default: 3674bbec428eSgjelinek zone_perror(rt_to_str(type), Z_NO_RESOURCE_TYPE, B_TRUE); 3675bbec428eSgjelinek long_usage(CMD_SELECT, B_TRUE); 3676bbec428eSgjelinek usage(B_FALSE, HELP_RESOURCES); 36777c478bd9Sstevel@tonic-gate return; 36787c478bd9Sstevel@tonic-gate } 36797c478bd9Sstevel@tonic-gate } 36807c478bd9Sstevel@tonic-gate 36817c478bd9Sstevel@tonic-gate /* 36827c478bd9Sstevel@tonic-gate * Network "addresses" can be one of the following forms: 36837c478bd9Sstevel@tonic-gate * <IPv4 address> 36847c478bd9Sstevel@tonic-gate * <IPv4 address>/<prefix length> 36857c478bd9Sstevel@tonic-gate * <IPv6 address>/<prefix length> 36867c478bd9Sstevel@tonic-gate * <host name> 36877c478bd9Sstevel@tonic-gate * <host name>/<prefix length> 36887c478bd9Sstevel@tonic-gate * In other words, the "/" followed by a prefix length is allowed but not 36897c478bd9Sstevel@tonic-gate * required for IPv4 addresses and host names, and required for IPv6 addresses. 36907c478bd9Sstevel@tonic-gate * If a prefix length is given, it must be in the allowable range: 0 to 32 for 36917c478bd9Sstevel@tonic-gate * IPv4 addresses and host names, 0 to 128 for IPv6 addresses. 36927c478bd9Sstevel@tonic-gate * Host names must start with an alpha-numeric character, and all subsequent 36937c478bd9Sstevel@tonic-gate * characters must be either alpha-numeric or "-". 36947c478bd9Sstevel@tonic-gate */ 36957c478bd9Sstevel@tonic-gate 36967c478bd9Sstevel@tonic-gate static int 36977c478bd9Sstevel@tonic-gate validate_net_address_syntax(char *address) 36987c478bd9Sstevel@tonic-gate { 36997c478bd9Sstevel@tonic-gate char *slashp, part1[MAXHOSTNAMELEN]; 37007c478bd9Sstevel@tonic-gate struct in6_addr in6; 37017c478bd9Sstevel@tonic-gate struct in_addr in4; 37027c478bd9Sstevel@tonic-gate int prefixlen, i; 37037c478bd9Sstevel@tonic-gate 37047c478bd9Sstevel@tonic-gate /* 37057c478bd9Sstevel@tonic-gate * Copy the part before any '/' into part1 or copy the whole 37067c478bd9Sstevel@tonic-gate * thing if there is no '/'. 37077c478bd9Sstevel@tonic-gate */ 37087c478bd9Sstevel@tonic-gate if ((slashp = strchr(address, '/')) != NULL) { 37097c478bd9Sstevel@tonic-gate *slashp = '\0'; 37107c478bd9Sstevel@tonic-gate (void) strlcpy(part1, address, sizeof (part1)); 37117c478bd9Sstevel@tonic-gate *slashp = '/'; 37127c478bd9Sstevel@tonic-gate prefixlen = atoi(++slashp); 37137c478bd9Sstevel@tonic-gate } else { 37147c478bd9Sstevel@tonic-gate (void) strlcpy(part1, address, sizeof (part1)); 37157c478bd9Sstevel@tonic-gate } 37167c478bd9Sstevel@tonic-gate 37177c478bd9Sstevel@tonic-gate if (inet_pton(AF_INET6, part1, &in6) == 1) { 37187c478bd9Sstevel@tonic-gate if (slashp == NULL) { 37197c478bd9Sstevel@tonic-gate zerr(gettext("%s: IPv6 addresses " 37207c478bd9Sstevel@tonic-gate "require /prefix-length suffix."), address); 37217c478bd9Sstevel@tonic-gate return (Z_ERR); 37227c478bd9Sstevel@tonic-gate } 37237c478bd9Sstevel@tonic-gate if (prefixlen < 0 || prefixlen > 128) { 37247c478bd9Sstevel@tonic-gate zerr(gettext("%s: IPv6 address " 37257c478bd9Sstevel@tonic-gate "prefix lengths must be 0 - 128."), address); 37267c478bd9Sstevel@tonic-gate return (Z_ERR); 37277c478bd9Sstevel@tonic-gate } 37287c478bd9Sstevel@tonic-gate return (Z_OK); 37297c478bd9Sstevel@tonic-gate } 37307c478bd9Sstevel@tonic-gate 37317c478bd9Sstevel@tonic-gate /* At this point, any /prefix must be for IPv4. */ 37327c478bd9Sstevel@tonic-gate if (slashp != NULL) { 37337c478bd9Sstevel@tonic-gate if (prefixlen < 0 || prefixlen > 32) { 37347c478bd9Sstevel@tonic-gate zerr(gettext("%s: IPv4 address " 37357c478bd9Sstevel@tonic-gate "prefix lengths must be 0 - 32."), address); 37367c478bd9Sstevel@tonic-gate return (Z_ERR); 37377c478bd9Sstevel@tonic-gate } 37387c478bd9Sstevel@tonic-gate } 37397c478bd9Sstevel@tonic-gate if (inet_pton(AF_INET, part1, &in4) == 1) 37407c478bd9Sstevel@tonic-gate return (Z_OK); 37417c478bd9Sstevel@tonic-gate 37427c478bd9Sstevel@tonic-gate /* address may also be a host name */ 37437c478bd9Sstevel@tonic-gate if (!isalnum(part1[0])) { 37447c478bd9Sstevel@tonic-gate zerr(gettext("%s: bogus host name or network address syntax"), 37457c478bd9Sstevel@tonic-gate part1); 3746bbec428eSgjelinek saw_error = B_TRUE; 3747bbec428eSgjelinek usage(B_FALSE, HELP_NETADDR); 37487c478bd9Sstevel@tonic-gate return (Z_ERR); 37497c478bd9Sstevel@tonic-gate } 37507c478bd9Sstevel@tonic-gate for (i = 1; part1[i]; i++) 37517c478bd9Sstevel@tonic-gate if (!isalnum(part1[i]) && part1[i] != '-' && part1[i] != '.') { 37527c478bd9Sstevel@tonic-gate zerr(gettext("%s: bogus host name or " 37537c478bd9Sstevel@tonic-gate "network address syntax"), part1); 3754bbec428eSgjelinek saw_error = B_TRUE; 3755bbec428eSgjelinek usage(B_FALSE, HELP_NETADDR); 37567c478bd9Sstevel@tonic-gate return (Z_ERR); 37577c478bd9Sstevel@tonic-gate } 37587c478bd9Sstevel@tonic-gate return (Z_OK); 37597c478bd9Sstevel@tonic-gate } 37607c478bd9Sstevel@tonic-gate 37617c478bd9Sstevel@tonic-gate static int 3762c9f134eaSjv validate_net_physical_syntax(const char *ifname) 37637c478bd9Sstevel@tonic-gate { 3764c9f134eaSjv ifspec_t ifnameprop; 3765c9f134eaSjv zone_iptype_t iptype; 3766c9f134eaSjv 376737b210dcSjv if (zonecfg_get_iptype(handle, &iptype) != Z_OK) { 3768c9f134eaSjv zerr(gettext("zone configuration has an invalid or nonexistent " 3769c9f134eaSjv "ip-type property")); 3770c9f134eaSjv return (Z_ERR); 3771c9f134eaSjv } 3772c9f134eaSjv switch (iptype) { 3773c9f134eaSjv case ZS_SHARED: 3774c9f134eaSjv if (ifparse_ifspec(ifname, &ifnameprop) == B_FALSE) { 3775c9f134eaSjv zerr(gettext("%s: invalid physical interface name"), 3776c9f134eaSjv ifname); 3777c9f134eaSjv return (Z_ERR); 3778c9f134eaSjv } 3779c9f134eaSjv if (ifnameprop.ifsp_lunvalid) { 3780c9f134eaSjv zerr(gettext("%s: LUNs not allowed in physical " 3781c9f134eaSjv "interface names"), ifname); 3782c9f134eaSjv return (Z_ERR); 3783c9f134eaSjv } 3784c9f134eaSjv break; 3785c9f134eaSjv case ZS_EXCLUSIVE: 3786c9f134eaSjv if (dladm_valid_linkname(ifname) == B_FALSE) { 3787c9f134eaSjv if (strchr(ifname, ':') != NULL) 3788c9f134eaSjv zerr(gettext("%s: physical interface name " 3789c9f134eaSjv "required; logical interface name not " 3790c9f134eaSjv "allowed"), ifname); 3791c9f134eaSjv else 3792c9f134eaSjv zerr(gettext("%s: invalid physical interface " 3793c9f134eaSjv "name"), ifname); 3794c9f134eaSjv return (Z_ERR); 3795c9f134eaSjv } 3796c9f134eaSjv break; 3797c9f134eaSjv } 3798c9f134eaSjv return (Z_OK); 37997c478bd9Sstevel@tonic-gate } 38007c478bd9Sstevel@tonic-gate 38017c478bd9Sstevel@tonic-gate static boolean_t 38027c478bd9Sstevel@tonic-gate valid_fs_type(const char *type) 38037c478bd9Sstevel@tonic-gate { 38047c478bd9Sstevel@tonic-gate /* 38057c478bd9Sstevel@tonic-gate * Is this a valid path component? 38067c478bd9Sstevel@tonic-gate */ 38077c478bd9Sstevel@tonic-gate if (strlen(type) + 1 > MAXNAMELEN) 38087c478bd9Sstevel@tonic-gate return (B_FALSE); 38097c478bd9Sstevel@tonic-gate /* 38107c478bd9Sstevel@tonic-gate * Make sure a bad value for "type" doesn't make 38117c478bd9Sstevel@tonic-gate * /usr/lib/fs/<type>/mount turn into something else. 38127c478bd9Sstevel@tonic-gate */ 38137c478bd9Sstevel@tonic-gate if (strchr(type, '/') != NULL || type[0] == '\0' || 38147c478bd9Sstevel@tonic-gate strcmp(type, ".") == 0 || strcmp(type, "..") == 0) 3815087719fdSdp return (B_FALSE); 38167c478bd9Sstevel@tonic-gate /* 38177c478bd9Sstevel@tonic-gate * More detailed verification happens later by zoneadm(1m). 38187c478bd9Sstevel@tonic-gate */ 38197c478bd9Sstevel@tonic-gate return (B_TRUE); 38207c478bd9Sstevel@tonic-gate } 38217c478bd9Sstevel@tonic-gate 3822f4b3ec61Sdh static boolean_t 3823f4b3ec61Sdh allow_exclusive() 3824f4b3ec61Sdh { 3825f4b3ec61Sdh brand_handle_t bh; 3826f4b3ec61Sdh char brand[MAXNAMELEN]; 3827f4b3ec61Sdh boolean_t ret; 3828f4b3ec61Sdh 3829f4b3ec61Sdh if (zonecfg_get_brand(handle, brand, sizeof (brand)) != Z_OK) { 3830f4b3ec61Sdh zerr("%s: %s\n", zone, gettext("could not get zone brand")); 3831f4b3ec61Sdh return (B_FALSE); 3832f4b3ec61Sdh } 3833f4b3ec61Sdh if ((bh = brand_open(brand)) == NULL) { 3834f4b3ec61Sdh zerr("%s: %s\n", zone, gettext("unknown brand.")); 3835f4b3ec61Sdh return (B_FALSE); 3836f4b3ec61Sdh } 3837f4b3ec61Sdh ret = brand_allow_exclusive_ip(bh); 3838f4b3ec61Sdh brand_close(bh); 3839f4b3ec61Sdh if (!ret) 3840f4b3ec61Sdh zerr(gettext("%s cannot be '%s' when %s is '%s'."), 3841f4b3ec61Sdh pt_to_str(PT_IPTYPE), "exclusive", 3842f4b3ec61Sdh pt_to_str(PT_BRAND), brand); 3843f4b3ec61Sdh return (ret); 3844f4b3ec61Sdh } 3845f4b3ec61Sdh 38460209230bSgjelinek static void 38470209230bSgjelinek set_aliased_rctl(char *alias, int prop_type, char *s) 38480209230bSgjelinek { 38490209230bSgjelinek uint64_t limit; 38500209230bSgjelinek int err; 38510209230bSgjelinek char tmp[128]; 38520209230bSgjelinek 38530209230bSgjelinek if (global_zone && strcmp(alias, ALIAS_SHARES) != 0) 38540209230bSgjelinek zerr(gettext("WARNING: Setting a global zone resource " 38550209230bSgjelinek "control too low could deny\nservice " 38560209230bSgjelinek "to even the root user; " 38570209230bSgjelinek "this could render the system impossible\n" 38580209230bSgjelinek "to administer. Please use caution.")); 38590209230bSgjelinek 38600209230bSgjelinek /* convert memory based properties */ 38610209230bSgjelinek if (prop_type == PT_MAXSHMMEM) { 38620209230bSgjelinek if (!zonecfg_valid_memlimit(s, &limit)) { 38630209230bSgjelinek zerr(gettext("A non-negative number with a required " 38640209230bSgjelinek "scale suffix (K, M, G or T) was expected\nhere.")); 3865bbec428eSgjelinek saw_error = B_TRUE; 38660209230bSgjelinek return; 38670209230bSgjelinek } 38680209230bSgjelinek 38690209230bSgjelinek (void) snprintf(tmp, sizeof (tmp), "%llu", limit); 38700209230bSgjelinek s = tmp; 38710209230bSgjelinek } 38720209230bSgjelinek 38730209230bSgjelinek if (!zonecfg_aliased_rctl_ok(handle, alias)) { 3874bbec428eSgjelinek zone_perror(pt_to_str(prop_type), Z_ALIAS_DISALLOW, B_FALSE); 3875bbec428eSgjelinek saw_error = B_TRUE; 38760209230bSgjelinek } else if (!zonecfg_valid_alias_limit(alias, s, &limit)) { 38770209230bSgjelinek zerr(gettext("%s property is out of range."), 38780209230bSgjelinek pt_to_str(prop_type)); 3879bbec428eSgjelinek saw_error = B_TRUE; 38800209230bSgjelinek } else if ((err = zonecfg_set_aliased_rctl(handle, alias, limit)) 38810209230bSgjelinek != Z_OK) { 3882bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 3883bbec428eSgjelinek saw_error = B_TRUE; 38840209230bSgjelinek } else { 3885bbec428eSgjelinek need_to_commit = B_TRUE; 38860209230bSgjelinek } 38870209230bSgjelinek } 38880209230bSgjelinek 38897c478bd9Sstevel@tonic-gate void 38907c478bd9Sstevel@tonic-gate set_func(cmd_t *cmd) 38917c478bd9Sstevel@tonic-gate { 38927c478bd9Sstevel@tonic-gate char *prop_id; 3893555afedfScarlsonj int arg, err, res_type, prop_type; 38947c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 38957c478bd9Sstevel@tonic-gate boolean_t autoboot; 3896f4b3ec61Sdh zone_iptype_t iptype; 3897bbec428eSgjelinek boolean_t force_set = B_FALSE; 38980209230bSgjelinek size_t physmem_size = sizeof (in_progress_mcaptab.zone_physmem_cap); 38990209230bSgjelinek uint64_t mem_cap, mem_limit; 3900c97ad5cdSakolb float cap; 3901c97ad5cdSakolb char *unitp; 39020209230bSgjelinek struct zone_psettab tmp_psettab; 3903bbec428eSgjelinek boolean_t arg_err = B_FALSE; 39047c478bd9Sstevel@tonic-gate 39057c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_SET)) 39067c478bd9Sstevel@tonic-gate return; 39077c478bd9Sstevel@tonic-gate 39087c478bd9Sstevel@tonic-gate assert(cmd != NULL); 39097c478bd9Sstevel@tonic-gate 3910555afedfScarlsonj optind = opterr = 0; 3911555afedfScarlsonj while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "F")) != EOF) { 3912555afedfScarlsonj switch (arg) { 3913555afedfScarlsonj case 'F': 3914bbec428eSgjelinek force_set = B_TRUE; 3915555afedfScarlsonj break; 3916555afedfScarlsonj default: 3917555afedfScarlsonj if (optopt == '?') 3918555afedfScarlsonj longer_usage(CMD_SET); 3919555afedfScarlsonj else 3920555afedfScarlsonj short_usage(CMD_SET); 3921bbec428eSgjelinek arg_err = B_TRUE; 39227ec75eb8Sgjelinek break; 3923555afedfScarlsonj } 3924555afedfScarlsonj } 39257ec75eb8Sgjelinek if (arg_err) 39267ec75eb8Sgjelinek return; 3927555afedfScarlsonj 39287c478bd9Sstevel@tonic-gate prop_type = cmd->cmd_prop_name[0]; 39297c478bd9Sstevel@tonic-gate if (global_scope) { 39300209230bSgjelinek if (gz_invalid_property(prop_type)) { 39310209230bSgjelinek zerr(gettext("%s is not a valid property for the " 39320209230bSgjelinek "global zone."), pt_to_str(prop_type)); 3933bbec428eSgjelinek saw_error = B_TRUE; 39340209230bSgjelinek return; 39350209230bSgjelinek } 39360209230bSgjelinek 3937087719fdSdp if (prop_type == PT_ZONENAME) { 3938087719fdSdp res_type = RT_ZONENAME; 3939087719fdSdp } else if (prop_type == PT_ZONEPATH) { 39407c478bd9Sstevel@tonic-gate res_type = RT_ZONEPATH; 39417c478bd9Sstevel@tonic-gate } else if (prop_type == PT_AUTOBOOT) { 39427c478bd9Sstevel@tonic-gate res_type = RT_AUTOBOOT; 39439acbbeafSnn } else if (prop_type == PT_BRAND) { 39449acbbeafSnn res_type = RT_BRAND; 39457c478bd9Sstevel@tonic-gate } else if (prop_type == PT_POOL) { 39467c478bd9Sstevel@tonic-gate res_type = RT_POOL; 3947ffbafc53Scomay } else if (prop_type == PT_LIMITPRIV) { 3948ffbafc53Scomay res_type = RT_LIMITPRIV; 39493f2f09c1Sdp } else if (prop_type == PT_BOOTARGS) { 39503f2f09c1Sdp res_type = RT_BOOTARGS; 39510209230bSgjelinek } else if (prop_type == PT_SCHED) { 39520209230bSgjelinek res_type = RT_SCHED; 3953f4b3ec61Sdh } else if (prop_type == PT_IPTYPE) { 3954f4b3ec61Sdh res_type = RT_IPTYPE; 39550209230bSgjelinek } else if (prop_type == PT_MAXLWPS) { 39560209230bSgjelinek res_type = RT_MAXLWPS; 39570209230bSgjelinek } else if (prop_type == PT_MAXSHMMEM) { 39580209230bSgjelinek res_type = RT_MAXSHMMEM; 39590209230bSgjelinek } else if (prop_type == PT_MAXSHMIDS) { 39600209230bSgjelinek res_type = RT_MAXSHMIDS; 39610209230bSgjelinek } else if (prop_type == PT_MAXMSGIDS) { 39620209230bSgjelinek res_type = RT_MAXMSGIDS; 39630209230bSgjelinek } else if (prop_type == PT_MAXSEMIDS) { 39640209230bSgjelinek res_type = RT_MAXSEMIDS; 39650209230bSgjelinek } else if (prop_type == PT_SHARES) { 39660209230bSgjelinek res_type = RT_SHARES; 39675679c89fSjv } else if (prop_type == PT_HOSTID) { 39685679c89fSjv res_type = RT_HOSTID; 39697c478bd9Sstevel@tonic-gate } else { 39707c478bd9Sstevel@tonic-gate zerr(gettext("Cannot set a resource-specific property " 39717c478bd9Sstevel@tonic-gate "from the global scope.")); 3972bbec428eSgjelinek saw_error = B_TRUE; 39737c478bd9Sstevel@tonic-gate return; 39747c478bd9Sstevel@tonic-gate } 39757c478bd9Sstevel@tonic-gate } else { 39767c478bd9Sstevel@tonic-gate res_type = resource_scope; 39777c478bd9Sstevel@tonic-gate } 39787c478bd9Sstevel@tonic-gate 3979555afedfScarlsonj if (force_set) { 3980555afedfScarlsonj if (res_type != RT_ZONEPATH) { 3981555afedfScarlsonj zerr(gettext("Only zonepath setting can be forced.")); 3982bbec428eSgjelinek saw_error = B_TRUE; 3983555afedfScarlsonj return; 3984555afedfScarlsonj } 3985555afedfScarlsonj if (!zonecfg_in_alt_root()) { 3986555afedfScarlsonj zerr(gettext("Zonepath is changeable only in an " 3987555afedfScarlsonj "alternate root.")); 3988bbec428eSgjelinek saw_error = B_TRUE; 3989555afedfScarlsonj return; 3990555afedfScarlsonj } 3991555afedfScarlsonj } 3992555afedfScarlsonj 39937c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[0]; 39947c478bd9Sstevel@tonic-gate /* 39957c478bd9Sstevel@tonic-gate * A nasty expression but not that complicated: 39967c478bd9Sstevel@tonic-gate * 1. fs options are simple or list (tested below) 39977c478bd9Sstevel@tonic-gate * 2. rctl value's are complex or list (tested below) 39987c478bd9Sstevel@tonic-gate * Anything else should be simple. 39997c478bd9Sstevel@tonic-gate */ 40007c478bd9Sstevel@tonic-gate if (!(res_type == RT_FS && prop_type == PT_OPTIONS) && 40017c478bd9Sstevel@tonic-gate !(res_type == RT_RCTL && prop_type == PT_VALUE) && 40027c478bd9Sstevel@tonic-gate (pp->pv_type != PROP_VAL_SIMPLE || 40037c478bd9Sstevel@tonic-gate (prop_id = pp->pv_simple) == NULL)) { 40047c478bd9Sstevel@tonic-gate zerr(gettext("A %s value was expected here."), 40057c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_SIMPLE)); 4006bbec428eSgjelinek saw_error = B_TRUE; 40077c478bd9Sstevel@tonic-gate return; 40087c478bd9Sstevel@tonic-gate } 40097c478bd9Sstevel@tonic-gate if (prop_type == PT_UNKNOWN) { 4010bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 40117c478bd9Sstevel@tonic-gate return; 40127c478bd9Sstevel@tonic-gate } 40137c478bd9Sstevel@tonic-gate 4014087719fdSdp /* 4015087719fdSdp * Special case: the user can change the zone name prior to 'create'; 4016087719fdSdp * if the zone already exists, we fall through letting initialize() 4017087719fdSdp * and the rest of the logic run. 4018087719fdSdp */ 4019bbec428eSgjelinek if (res_type == RT_ZONENAME && got_handle == B_FALSE && 4020087719fdSdp !state_atleast(ZONE_STATE_CONFIGURED)) { 4021fb03efaaSdp if ((err = zonecfg_validate_zonename(prop_id)) != Z_OK) { 4022bbec428eSgjelinek zone_perror(prop_id, err, B_TRUE); 4023bbec428eSgjelinek usage(B_FALSE, HELP_SYNTAX); 4024fb03efaaSdp return; 4025fb03efaaSdp } 4026087719fdSdp (void) strlcpy(zone, prop_id, sizeof (zone)); 4027087719fdSdp return; 4028087719fdSdp } 4029087719fdSdp 4030bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 40317c478bd9Sstevel@tonic-gate return; 40327c478bd9Sstevel@tonic-gate 40337c478bd9Sstevel@tonic-gate switch (res_type) { 4034087719fdSdp case RT_ZONENAME: 4035087719fdSdp if ((err = zonecfg_set_name(handle, prop_id)) != Z_OK) { 4036087719fdSdp /* 4037087719fdSdp * Use prop_id instead of 'zone' here, since we're 4038087719fdSdp * reporting a problem about the *new* zonename. 4039087719fdSdp */ 4040bbec428eSgjelinek zone_perror(prop_id, err, B_TRUE); 4041bbec428eSgjelinek usage(B_FALSE, HELP_SYNTAX); 4042087719fdSdp } else { 4043bbec428eSgjelinek need_to_commit = B_TRUE; 4044087719fdSdp (void) strlcpy(zone, prop_id, sizeof (zone)); 4045087719fdSdp } 4046087719fdSdp return; 40477c478bd9Sstevel@tonic-gate case RT_ZONEPATH: 4048555afedfScarlsonj if (!force_set && state_atleast(ZONE_STATE_INSTALLED)) { 40497c478bd9Sstevel@tonic-gate zerr(gettext("Zone %s already installed; %s %s not " 40507c478bd9Sstevel@tonic-gate "allowed."), zone, cmd_to_str(CMD_SET), 40517c478bd9Sstevel@tonic-gate rt_to_str(RT_ZONEPATH)); 40527c478bd9Sstevel@tonic-gate return; 40537c478bd9Sstevel@tonic-gate } 40547c478bd9Sstevel@tonic-gate if (validate_zonepath_syntax(prop_id) != Z_OK) { 4055bbec428eSgjelinek saw_error = B_TRUE; 40567c478bd9Sstevel@tonic-gate return; 40577c478bd9Sstevel@tonic-gate } 40587c478bd9Sstevel@tonic-gate if ((err = zonecfg_set_zonepath(handle, prop_id)) != Z_OK) 4059bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 40607c478bd9Sstevel@tonic-gate else 4061bbec428eSgjelinek need_to_commit = B_TRUE; 40627c478bd9Sstevel@tonic-gate return; 40639acbbeafSnn case RT_BRAND: 40649acbbeafSnn if (state_atleast(ZONE_STATE_INSTALLED)) { 40659acbbeafSnn zerr(gettext("Zone %s already installed; %s %s not " 40669acbbeafSnn "allowed."), zone, cmd_to_str(CMD_SET), 40679acbbeafSnn rt_to_str(RT_BRAND)); 40689acbbeafSnn return; 40699acbbeafSnn } 40709acbbeafSnn if ((err = zonecfg_set_brand(handle, prop_id)) != Z_OK) 4071bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 40729acbbeafSnn else 4073bbec428eSgjelinek need_to_commit = B_TRUE; 40749acbbeafSnn return; 40757c478bd9Sstevel@tonic-gate case RT_AUTOBOOT: 40767c478bd9Sstevel@tonic-gate if (strcmp(prop_id, "true") == 0) { 40777c478bd9Sstevel@tonic-gate autoboot = B_TRUE; 40787c478bd9Sstevel@tonic-gate } else if (strcmp(prop_id, "false") == 0) { 40797c478bd9Sstevel@tonic-gate autoboot = B_FALSE; 40807c478bd9Sstevel@tonic-gate } else { 40817c478bd9Sstevel@tonic-gate zerr(gettext("%s value must be '%s' or '%s'."), 40827c478bd9Sstevel@tonic-gate pt_to_str(PT_AUTOBOOT), "true", "false"); 4083bbec428eSgjelinek saw_error = B_TRUE; 40847c478bd9Sstevel@tonic-gate return; 40857c478bd9Sstevel@tonic-gate } 40867c478bd9Sstevel@tonic-gate if ((err = zonecfg_set_autoboot(handle, autoboot)) != Z_OK) 4087bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 40887c478bd9Sstevel@tonic-gate else 4089bbec428eSgjelinek need_to_commit = B_TRUE; 40907c478bd9Sstevel@tonic-gate return; 40917c478bd9Sstevel@tonic-gate case RT_POOL: 40920209230bSgjelinek /* don't allow use of the reserved temporary pool names */ 40930209230bSgjelinek if (strncmp("SUNW", prop_id, 4) == 0) { 40940209230bSgjelinek zerr(gettext("pool names starting with SUNW are " 40950209230bSgjelinek "reserved.")); 4096bbec428eSgjelinek saw_error = B_TRUE; 40970209230bSgjelinek return; 40980209230bSgjelinek } 40990209230bSgjelinek 41000209230bSgjelinek /* can't set pool if dedicated-cpu exists */ 41010209230bSgjelinek if (zonecfg_lookup_pset(handle, &tmp_psettab) == Z_OK) { 41020209230bSgjelinek zerr(gettext("The %s resource already exists. " 41030209230bSgjelinek "A persistent pool is incompatible\nwith the %s " 41040209230bSgjelinek "resource."), rt_to_str(RT_DCPU), 41050209230bSgjelinek rt_to_str(RT_DCPU)); 4106bbec428eSgjelinek saw_error = B_TRUE; 41070209230bSgjelinek return; 41080209230bSgjelinek } 41090209230bSgjelinek 41107c478bd9Sstevel@tonic-gate if ((err = zonecfg_set_pool(handle, prop_id)) != Z_OK) 4111bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 41127c478bd9Sstevel@tonic-gate else 4113bbec428eSgjelinek need_to_commit = B_TRUE; 41147c478bd9Sstevel@tonic-gate return; 4115ffbafc53Scomay case RT_LIMITPRIV: 4116ffbafc53Scomay if ((err = zonecfg_set_limitpriv(handle, prop_id)) != Z_OK) 4117bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 4118ffbafc53Scomay else 4119bbec428eSgjelinek need_to_commit = B_TRUE; 4120ffbafc53Scomay return; 41213f2f09c1Sdp case RT_BOOTARGS: 41223f2f09c1Sdp if ((err = zonecfg_set_bootargs(handle, prop_id)) != Z_OK) 4123bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 41243f2f09c1Sdp else 4125bbec428eSgjelinek need_to_commit = B_TRUE; 41263f2f09c1Sdp return; 41270209230bSgjelinek case RT_SCHED: 41280209230bSgjelinek if ((err = zonecfg_set_sched(handle, prop_id)) != Z_OK) 4129bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 41300209230bSgjelinek else 4131bbec428eSgjelinek need_to_commit = B_TRUE; 41320209230bSgjelinek return; 4133f4b3ec61Sdh case RT_IPTYPE: 4134f4b3ec61Sdh if (strcmp(prop_id, "shared") == 0) { 4135f4b3ec61Sdh iptype = ZS_SHARED; 4136f4b3ec61Sdh } else if (strcmp(prop_id, "exclusive") == 0) { 4137f4b3ec61Sdh iptype = ZS_EXCLUSIVE; 4138f4b3ec61Sdh } else { 4139f4b3ec61Sdh zerr(gettext("%s value must be '%s' or '%s'."), 4140f4b3ec61Sdh pt_to_str(PT_IPTYPE), "shared", "exclusive"); 4141bbec428eSgjelinek saw_error = B_TRUE; 4142f4b3ec61Sdh return; 4143f4b3ec61Sdh } 4144f4b3ec61Sdh if (iptype == ZS_EXCLUSIVE && !allow_exclusive()) { 4145bbec428eSgjelinek saw_error = B_TRUE; 4146f4b3ec61Sdh return; 4147f4b3ec61Sdh } 4148f4b3ec61Sdh if ((err = zonecfg_set_iptype(handle, iptype)) != Z_OK) 4149bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 4150f4b3ec61Sdh else 4151bbec428eSgjelinek need_to_commit = B_TRUE; 4152f4b3ec61Sdh return; 41530209230bSgjelinek case RT_MAXLWPS: 41540209230bSgjelinek set_aliased_rctl(ALIAS_MAXLWPS, prop_type, prop_id); 41550209230bSgjelinek return; 41560209230bSgjelinek case RT_MAXSHMMEM: 41570209230bSgjelinek set_aliased_rctl(ALIAS_MAXSHMMEM, prop_type, prop_id); 41580209230bSgjelinek return; 41590209230bSgjelinek case RT_MAXSHMIDS: 41600209230bSgjelinek set_aliased_rctl(ALIAS_MAXSHMIDS, prop_type, prop_id); 41610209230bSgjelinek return; 41620209230bSgjelinek case RT_MAXMSGIDS: 41630209230bSgjelinek set_aliased_rctl(ALIAS_MAXMSGIDS, prop_type, prop_id); 41640209230bSgjelinek return; 41650209230bSgjelinek case RT_MAXSEMIDS: 41660209230bSgjelinek set_aliased_rctl(ALIAS_MAXSEMIDS, prop_type, prop_id); 41670209230bSgjelinek return; 41680209230bSgjelinek case RT_SHARES: 41690209230bSgjelinek set_aliased_rctl(ALIAS_SHARES, prop_type, prop_id); 41700209230bSgjelinek return; 41715679c89fSjv case RT_HOSTID: 41725679c89fSjv if ((err = zonecfg_set_hostid(handle, prop_id)) != Z_OK) { 41735679c89fSjv if (err == Z_TOO_BIG) { 41745679c89fSjv zerr(gettext("hostid string is too large: %s"), 41755679c89fSjv prop_id); 41765679c89fSjv saw_error = B_TRUE; 41775679c89fSjv } else { 41785679c89fSjv zone_perror(pt_to_str(prop_type), err, B_TRUE); 41795679c89fSjv } 41805679c89fSjv return; 41815679c89fSjv } 41825679c89fSjv need_to_commit = B_TRUE; 41835679c89fSjv return; 41847c478bd9Sstevel@tonic-gate case RT_FS: 41857c478bd9Sstevel@tonic-gate switch (prop_type) { 41867c478bd9Sstevel@tonic-gate case PT_DIR: 41877c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_fstab.zone_fs_dir, prop_id, 41887c478bd9Sstevel@tonic-gate sizeof (in_progress_fstab.zone_fs_dir)); 41897c478bd9Sstevel@tonic-gate return; 41907c478bd9Sstevel@tonic-gate case PT_SPECIAL: 41917c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_fstab.zone_fs_special, 41927c478bd9Sstevel@tonic-gate prop_id, 41937c478bd9Sstevel@tonic-gate sizeof (in_progress_fstab.zone_fs_special)); 41947c478bd9Sstevel@tonic-gate return; 41957c478bd9Sstevel@tonic-gate case PT_RAW: 41967c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_fstab.zone_fs_raw, 41977c478bd9Sstevel@tonic-gate prop_id, sizeof (in_progress_fstab.zone_fs_raw)); 41987c478bd9Sstevel@tonic-gate return; 41997c478bd9Sstevel@tonic-gate case PT_TYPE: 42007c478bd9Sstevel@tonic-gate if (!valid_fs_type(prop_id)) { 42017c478bd9Sstevel@tonic-gate zerr(gettext("\"%s\" is not a valid %s."), 42027c478bd9Sstevel@tonic-gate prop_id, pt_to_str(PT_TYPE)); 4203bbec428eSgjelinek saw_error = B_TRUE; 42047c478bd9Sstevel@tonic-gate return; 42057c478bd9Sstevel@tonic-gate } 42067c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_fstab.zone_fs_type, prop_id, 42077c478bd9Sstevel@tonic-gate sizeof (in_progress_fstab.zone_fs_type)); 42087c478bd9Sstevel@tonic-gate return; 42097c478bd9Sstevel@tonic-gate case PT_OPTIONS: 42107c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE && 42117c478bd9Sstevel@tonic-gate pp->pv_type != PROP_VAL_LIST) { 42127c478bd9Sstevel@tonic-gate zerr(gettext("A %s or %s value was expected " 42137c478bd9Sstevel@tonic-gate "here."), pvt_to_str(PROP_VAL_SIMPLE), 42147c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_LIST)); 4215bbec428eSgjelinek saw_error = B_TRUE; 42167c478bd9Sstevel@tonic-gate return; 42177c478bd9Sstevel@tonic-gate } 42187c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list( 42197c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_options); 42207c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_options = NULL; 42217c478bd9Sstevel@tonic-gate if (!(pp->pv_type == PROP_VAL_LIST && 42227c478bd9Sstevel@tonic-gate pp->pv_list == NULL)) 42237c478bd9Sstevel@tonic-gate add_property(cmd); 42247c478bd9Sstevel@tonic-gate return; 42257c478bd9Sstevel@tonic-gate default: 42267c478bd9Sstevel@tonic-gate break; 42277c478bd9Sstevel@tonic-gate } 4228bbec428eSgjelinek zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, B_TRUE); 4229bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4230bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 42317c478bd9Sstevel@tonic-gate return; 42327c478bd9Sstevel@tonic-gate case RT_IPD: 42337c478bd9Sstevel@tonic-gate switch (prop_type) { 42347c478bd9Sstevel@tonic-gate case PT_DIR: 42357c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_ipdtab.zone_fs_dir, prop_id, 42367c478bd9Sstevel@tonic-gate sizeof (in_progress_ipdtab.zone_fs_dir)); 42377c478bd9Sstevel@tonic-gate return; 42387c478bd9Sstevel@tonic-gate default: 42397c478bd9Sstevel@tonic-gate break; 42407c478bd9Sstevel@tonic-gate } 4241bbec428eSgjelinek zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, B_TRUE); 4242bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4243bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 42447c478bd9Sstevel@tonic-gate return; 42457c478bd9Sstevel@tonic-gate case RT_NET: 42467c478bd9Sstevel@tonic-gate switch (prop_type) { 42477c478bd9Sstevel@tonic-gate case PT_ADDRESS: 42487c478bd9Sstevel@tonic-gate if (validate_net_address_syntax(prop_id) != Z_OK) { 4249bbec428eSgjelinek saw_error = B_TRUE; 42507c478bd9Sstevel@tonic-gate return; 42517c478bd9Sstevel@tonic-gate } 42527c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_nwiftab.zone_nwif_address, 42537c478bd9Sstevel@tonic-gate prop_id, 42547c478bd9Sstevel@tonic-gate sizeof (in_progress_nwiftab.zone_nwif_address)); 42557c478bd9Sstevel@tonic-gate break; 42567c478bd9Sstevel@tonic-gate case PT_PHYSICAL: 42577c478bd9Sstevel@tonic-gate if (validate_net_physical_syntax(prop_id) != Z_OK) { 4258bbec428eSgjelinek saw_error = B_TRUE; 42597c478bd9Sstevel@tonic-gate return; 42607c478bd9Sstevel@tonic-gate } 42617c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_nwiftab.zone_nwif_physical, 42627c478bd9Sstevel@tonic-gate prop_id, 42637c478bd9Sstevel@tonic-gate sizeof (in_progress_nwiftab.zone_nwif_physical)); 42647c478bd9Sstevel@tonic-gate break; 4265de860bd9Sgfaden case PT_DEFROUTER: 4266de860bd9Sgfaden if (validate_net_address_syntax(prop_id) != Z_OK) { 4267bbec428eSgjelinek saw_error = B_TRUE; 4268de860bd9Sgfaden return; 4269de860bd9Sgfaden } 4270de860bd9Sgfaden (void) strlcpy(in_progress_nwiftab.zone_nwif_defrouter, 4271de860bd9Sgfaden prop_id, 4272de860bd9Sgfaden sizeof (in_progress_nwiftab.zone_nwif_defrouter)); 4273de860bd9Sgfaden break; 42747c478bd9Sstevel@tonic-gate default: 42757c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 4276bbec428eSgjelinek B_TRUE); 4277bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4278bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 42797c478bd9Sstevel@tonic-gate return; 42807c478bd9Sstevel@tonic-gate } 42817c478bd9Sstevel@tonic-gate return; 42827c478bd9Sstevel@tonic-gate case RT_DEVICE: 42837c478bd9Sstevel@tonic-gate switch (prop_type) { 42847c478bd9Sstevel@tonic-gate case PT_MATCH: 42857c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_devtab.zone_dev_match, 42867c478bd9Sstevel@tonic-gate prop_id, 42877c478bd9Sstevel@tonic-gate sizeof (in_progress_devtab.zone_dev_match)); 42887c478bd9Sstevel@tonic-gate break; 42897c478bd9Sstevel@tonic-gate default: 42907c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 4291bbec428eSgjelinek B_TRUE); 4292bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4293bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 42947c478bd9Sstevel@tonic-gate return; 42957c478bd9Sstevel@tonic-gate } 42967c478bd9Sstevel@tonic-gate return; 42977c478bd9Sstevel@tonic-gate case RT_RCTL: 42987c478bd9Sstevel@tonic-gate switch (prop_type) { 42997c478bd9Sstevel@tonic-gate case PT_NAME: 43007c478bd9Sstevel@tonic-gate if (!zonecfg_valid_rctlname(prop_id)) { 43017c478bd9Sstevel@tonic-gate zerr(gettext("'%s' is not a valid zone %s " 43027c478bd9Sstevel@tonic-gate "name."), prop_id, rt_to_str(RT_RCTL)); 43037c478bd9Sstevel@tonic-gate return; 43047c478bd9Sstevel@tonic-gate } 43057c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_rctltab.zone_rctl_name, 43067c478bd9Sstevel@tonic-gate prop_id, 43077c478bd9Sstevel@tonic-gate sizeof (in_progress_rctltab.zone_rctl_name)); 43087c478bd9Sstevel@tonic-gate break; 43097c478bd9Sstevel@tonic-gate case PT_VALUE: 43107c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_COMPLEX && 43117c478bd9Sstevel@tonic-gate pp->pv_type != PROP_VAL_LIST) { 43127c478bd9Sstevel@tonic-gate zerr(gettext("A %s or %s value was expected " 43137c478bd9Sstevel@tonic-gate "here."), pvt_to_str(PROP_VAL_COMPLEX), 43147c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_LIST)); 4315bbec428eSgjelinek saw_error = B_TRUE; 43167c478bd9Sstevel@tonic-gate return; 43177c478bd9Sstevel@tonic-gate } 43187c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list( 43197c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_valptr); 43207c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_valptr = NULL; 43217c478bd9Sstevel@tonic-gate if (!(pp->pv_type == PROP_VAL_LIST && 43227c478bd9Sstevel@tonic-gate pp->pv_list == NULL)) 43237c478bd9Sstevel@tonic-gate add_property(cmd); 43247c478bd9Sstevel@tonic-gate break; 43257c478bd9Sstevel@tonic-gate default: 43267c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 4327bbec428eSgjelinek B_TRUE); 4328bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4329bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 43307c478bd9Sstevel@tonic-gate return; 43317c478bd9Sstevel@tonic-gate } 43327c478bd9Sstevel@tonic-gate return; 43337c478bd9Sstevel@tonic-gate case RT_ATTR: 43347c478bd9Sstevel@tonic-gate switch (prop_type) { 43357c478bd9Sstevel@tonic-gate case PT_NAME: 43367c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_attrtab.zone_attr_name, 43377c478bd9Sstevel@tonic-gate prop_id, 43387c478bd9Sstevel@tonic-gate sizeof (in_progress_attrtab.zone_attr_name)); 43397c478bd9Sstevel@tonic-gate break; 43407c478bd9Sstevel@tonic-gate case PT_TYPE: 43417c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_attrtab.zone_attr_type, 43427c478bd9Sstevel@tonic-gate prop_id, 43437c478bd9Sstevel@tonic-gate sizeof (in_progress_attrtab.zone_attr_type)); 43447c478bd9Sstevel@tonic-gate break; 43457c478bd9Sstevel@tonic-gate case PT_VALUE: 43467c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_attrtab.zone_attr_value, 43477c478bd9Sstevel@tonic-gate prop_id, 43487c478bd9Sstevel@tonic-gate sizeof (in_progress_attrtab.zone_attr_value)); 43497c478bd9Sstevel@tonic-gate break; 43507c478bd9Sstevel@tonic-gate default: 43517c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 4352bbec428eSgjelinek B_TRUE); 4353bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4354bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 43557c478bd9Sstevel@tonic-gate return; 43567c478bd9Sstevel@tonic-gate } 43577c478bd9Sstevel@tonic-gate return; 4358fa9e4066Sahrens case RT_DATASET: 4359fa9e4066Sahrens switch (prop_type) { 4360fa9e4066Sahrens case PT_NAME: 4361fa9e4066Sahrens (void) strlcpy(in_progress_dstab.zone_dataset_name, 4362fa9e4066Sahrens prop_id, 4363fa9e4066Sahrens sizeof (in_progress_dstab.zone_dataset_name)); 4364fa9e4066Sahrens return; 4365fa9e4066Sahrens default: 4366fa9e4066Sahrens break; 4367fa9e4066Sahrens } 4368bbec428eSgjelinek zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, B_TRUE); 4369bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4370bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 43710209230bSgjelinek return; 43720209230bSgjelinek case RT_DCPU: 43730209230bSgjelinek switch (prop_type) { 43740209230bSgjelinek char *lowp, *highp; 43750209230bSgjelinek 43760209230bSgjelinek case PT_NCPUS: 43770209230bSgjelinek lowp = prop_id; 43780209230bSgjelinek if ((highp = strchr(prop_id, '-')) != NULL) 43790209230bSgjelinek *highp++ = '\0'; 43800209230bSgjelinek else 43810209230bSgjelinek highp = lowp; 43820209230bSgjelinek 43830209230bSgjelinek /* Make sure the input makes sense. */ 43840209230bSgjelinek if (!zonecfg_valid_ncpus(lowp, highp)) { 43850209230bSgjelinek zerr(gettext("%s property is out of range."), 43860209230bSgjelinek pt_to_str(PT_NCPUS)); 4387bbec428eSgjelinek saw_error = B_TRUE; 43880209230bSgjelinek return; 43890209230bSgjelinek } 43900209230bSgjelinek 43910209230bSgjelinek (void) strlcpy( 43920209230bSgjelinek in_progress_psettab.zone_ncpu_min, lowp, 43930209230bSgjelinek sizeof (in_progress_psettab.zone_ncpu_min)); 43940209230bSgjelinek (void) strlcpy( 43950209230bSgjelinek in_progress_psettab.zone_ncpu_max, highp, 43960209230bSgjelinek sizeof (in_progress_psettab.zone_ncpu_max)); 43970209230bSgjelinek return; 43980209230bSgjelinek case PT_IMPORTANCE: 43990209230bSgjelinek /* Make sure the value makes sense. */ 44000209230bSgjelinek if (!zonecfg_valid_importance(prop_id)) { 44010209230bSgjelinek zerr(gettext("%s property is out of range."), 44020209230bSgjelinek pt_to_str(PT_IMPORTANCE)); 4403bbec428eSgjelinek saw_error = B_TRUE; 44040209230bSgjelinek return; 44050209230bSgjelinek } 44060209230bSgjelinek 44070209230bSgjelinek (void) strlcpy(in_progress_psettab.zone_importance, 44080209230bSgjelinek prop_id, 44090209230bSgjelinek sizeof (in_progress_psettab.zone_importance)); 44100209230bSgjelinek return; 44110209230bSgjelinek default: 44120209230bSgjelinek break; 44130209230bSgjelinek } 4414bbec428eSgjelinek zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, B_TRUE); 4415bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4416bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 44170209230bSgjelinek return; 4418c97ad5cdSakolb case RT_PCAP: 4419c97ad5cdSakolb if (prop_type != PT_NCPUS) { 4420c97ad5cdSakolb zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 4421bbec428eSgjelinek B_TRUE); 4422bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4423bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 4424c97ad5cdSakolb return; 4425c97ad5cdSakolb } 4426c97ad5cdSakolb 4427c97ad5cdSakolb /* 4428c97ad5cdSakolb * We already checked that an rctl alias is allowed in 4429c97ad5cdSakolb * the add_resource() function. 4430c97ad5cdSakolb */ 4431c97ad5cdSakolb 4432c97ad5cdSakolb if ((cap = strtof(prop_id, &unitp)) <= 0 || *unitp != '\0' || 4433c97ad5cdSakolb (int)(cap * 100) < 1) { 4434c97ad5cdSakolb zerr(gettext("%s property is out of range."), 4435c97ad5cdSakolb pt_to_str(PT_NCPUS)); 4436bbec428eSgjelinek saw_error = B_TRUE; 4437c97ad5cdSakolb return; 4438c97ad5cdSakolb } 4439c97ad5cdSakolb 4440c97ad5cdSakolb if ((err = zonecfg_set_aliased_rctl(handle, ALIAS_CPUCAP, 4441c97ad5cdSakolb (int)(cap * 100))) != Z_OK) 4442bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 4443c97ad5cdSakolb else 4444bbec428eSgjelinek need_to_commit = B_TRUE; 4445c97ad5cdSakolb return; 44460209230bSgjelinek case RT_MCAP: 44470209230bSgjelinek switch (prop_type) { 44480209230bSgjelinek case PT_PHYSICAL: 44490209230bSgjelinek if (!zonecfg_valid_memlimit(prop_id, &mem_cap)) { 44500209230bSgjelinek zerr(gettext("A positive number with a " 44510209230bSgjelinek "required scale suffix (K, M, G or T) was " 44520209230bSgjelinek "expected here.")); 4453bbec428eSgjelinek saw_error = B_TRUE; 44540209230bSgjelinek } else if (mem_cap < ONE_MB) { 44550209230bSgjelinek zerr(gettext("%s value is too small. It must " 44560209230bSgjelinek "be at least 1M."), pt_to_str(PT_PHYSICAL)); 4457bbec428eSgjelinek saw_error = B_TRUE; 44580209230bSgjelinek } else { 44590209230bSgjelinek snprintf(in_progress_mcaptab.zone_physmem_cap, 44600209230bSgjelinek physmem_size, "%llu", mem_cap); 44610209230bSgjelinek } 44620209230bSgjelinek break; 44630209230bSgjelinek case PT_SWAP: 44640209230bSgjelinek /* 44650209230bSgjelinek * We have to check if an rctl is allowed here since 44660209230bSgjelinek * there might already be a rctl defined that blocks 44670209230bSgjelinek * the alias. 44680209230bSgjelinek */ 44690209230bSgjelinek if (!zonecfg_aliased_rctl_ok(handle, ALIAS_MAXSWAP)) { 44700209230bSgjelinek zone_perror(pt_to_str(PT_MAXSWAP), 4471bbec428eSgjelinek Z_ALIAS_DISALLOW, B_FALSE); 4472bbec428eSgjelinek saw_error = B_TRUE; 44730209230bSgjelinek return; 44740209230bSgjelinek } 44750209230bSgjelinek 44760209230bSgjelinek if (global_zone) 44770209230bSgjelinek mem_limit = ONE_MB * 100; 44780209230bSgjelinek else 44790209230bSgjelinek mem_limit = ONE_MB * 50; 44800209230bSgjelinek 44810209230bSgjelinek if (!zonecfg_valid_memlimit(prop_id, &mem_cap)) { 44820209230bSgjelinek zerr(gettext("A positive number with a " 44830209230bSgjelinek "required scale suffix (K, M, G or T) was " 44840209230bSgjelinek "expected here.")); 4485bbec428eSgjelinek saw_error = B_TRUE; 44860209230bSgjelinek } else if (mem_cap < mem_limit) { 44870209230bSgjelinek char buf[128]; 44880209230bSgjelinek 44890209230bSgjelinek (void) snprintf(buf, sizeof (buf), "%llu", 44900209230bSgjelinek mem_limit); 44910209230bSgjelinek bytes_to_units(buf, buf, sizeof (buf)); 44920209230bSgjelinek zerr(gettext("%s value is too small. It must " 44930209230bSgjelinek "be at least %s."), pt_to_str(PT_SWAP), 44940209230bSgjelinek buf); 4495bbec428eSgjelinek saw_error = B_TRUE; 44960209230bSgjelinek } else { 44970209230bSgjelinek if ((err = zonecfg_set_aliased_rctl(handle, 44980209230bSgjelinek ALIAS_MAXSWAP, mem_cap)) != Z_OK) 4499bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 45000209230bSgjelinek else 4501bbec428eSgjelinek need_to_commit = B_TRUE; 45020209230bSgjelinek } 45030209230bSgjelinek break; 45040209230bSgjelinek case PT_LOCKED: 45050209230bSgjelinek /* 45060209230bSgjelinek * We have to check if an rctl is allowed here since 45070209230bSgjelinek * there might already be a rctl defined that blocks 45080209230bSgjelinek * the alias. 45090209230bSgjelinek */ 45100209230bSgjelinek if (!zonecfg_aliased_rctl_ok(handle, 45110209230bSgjelinek ALIAS_MAXLOCKEDMEM)) { 45120209230bSgjelinek zone_perror(pt_to_str(PT_LOCKED), 4513bbec428eSgjelinek Z_ALIAS_DISALLOW, B_FALSE); 4514bbec428eSgjelinek saw_error = B_TRUE; 45150209230bSgjelinek return; 45160209230bSgjelinek } 45170209230bSgjelinek 45180209230bSgjelinek if (!zonecfg_valid_memlimit(prop_id, &mem_cap)) { 45190209230bSgjelinek zerr(gettext("A non-negative number with a " 45200209230bSgjelinek "required scale suffix (K, M, G or T) was " 45210209230bSgjelinek "expected\nhere.")); 4522bbec428eSgjelinek saw_error = B_TRUE; 45230209230bSgjelinek } else { 45240209230bSgjelinek if ((err = zonecfg_set_aliased_rctl(handle, 45250209230bSgjelinek ALIAS_MAXLOCKEDMEM, mem_cap)) != Z_OK) 4526bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 45270209230bSgjelinek else 4528bbec428eSgjelinek need_to_commit = B_TRUE; 45290209230bSgjelinek } 45300209230bSgjelinek break; 45310209230bSgjelinek default: 45320209230bSgjelinek zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 4533bbec428eSgjelinek B_TRUE); 4534bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4535bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 45360209230bSgjelinek return; 45370209230bSgjelinek } 45380209230bSgjelinek 4539fa9e4066Sahrens return; 45407c478bd9Sstevel@tonic-gate default: 4541bbec428eSgjelinek zone_perror(rt_to_str(res_type), Z_NO_RESOURCE_TYPE, B_TRUE); 4542bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4543bbec428eSgjelinek usage(B_FALSE, HELP_RESOURCES); 45447c478bd9Sstevel@tonic-gate return; 45457c478bd9Sstevel@tonic-gate } 45467c478bd9Sstevel@tonic-gate } 45477c478bd9Sstevel@tonic-gate 45487c478bd9Sstevel@tonic-gate static void 4549bbec428eSgjelinek output_prop(FILE *fp, int pnum, char *pval, boolean_t print_notspec) 45507c478bd9Sstevel@tonic-gate { 45517c478bd9Sstevel@tonic-gate char *qstr; 45527c478bd9Sstevel@tonic-gate 45537c478bd9Sstevel@tonic-gate if (*pval != '\0') { 45547c478bd9Sstevel@tonic-gate qstr = quoteit(pval); 45550209230bSgjelinek if (pnum == PT_SWAP || pnum == PT_LOCKED) 45560209230bSgjelinek (void) fprintf(fp, "\t[%s: %s]\n", pt_to_str(pnum), 45570209230bSgjelinek qstr); 45580209230bSgjelinek else 45590209230bSgjelinek (void) fprintf(fp, "\t%s: %s\n", pt_to_str(pnum), qstr); 45607c478bd9Sstevel@tonic-gate free(qstr); 45617c478bd9Sstevel@tonic-gate } else if (print_notspec) 4562087719fdSdp (void) fprintf(fp, gettext("\t%s not specified\n"), 4563087719fdSdp pt_to_str(pnum)); 4564087719fdSdp } 4565087719fdSdp 4566087719fdSdp static void 4567087719fdSdp info_zonename(zone_dochandle_t handle, FILE *fp) 4568087719fdSdp { 4569087719fdSdp char zonename[ZONENAME_MAX]; 4570087719fdSdp 4571087719fdSdp if (zonecfg_get_name(handle, zonename, sizeof (zonename)) == Z_OK) 4572087719fdSdp (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_ZONENAME), 4573087719fdSdp zonename); 4574087719fdSdp else 4575087719fdSdp (void) fprintf(fp, gettext("%s not specified\n"), 4576087719fdSdp pt_to_str(PT_ZONENAME)); 45777c478bd9Sstevel@tonic-gate } 45787c478bd9Sstevel@tonic-gate 45797c478bd9Sstevel@tonic-gate static void 45807c478bd9Sstevel@tonic-gate info_zonepath(zone_dochandle_t handle, FILE *fp) 45817c478bd9Sstevel@tonic-gate { 45827c478bd9Sstevel@tonic-gate char zonepath[MAXPATHLEN]; 45837c478bd9Sstevel@tonic-gate 45847c478bd9Sstevel@tonic-gate if (zonecfg_get_zonepath(handle, zonepath, sizeof (zonepath)) == Z_OK) 45857c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_ZONEPATH), 45867c478bd9Sstevel@tonic-gate zonepath); 4587087719fdSdp else { 4588087719fdSdp (void) fprintf(fp, gettext("%s not specified\n"), 4589087719fdSdp pt_to_str(PT_ZONEPATH)); 4590087719fdSdp } 45917c478bd9Sstevel@tonic-gate } 45927c478bd9Sstevel@tonic-gate 45939acbbeafSnn static void 45949acbbeafSnn info_brand(zone_dochandle_t handle, FILE *fp) 45959acbbeafSnn { 45969acbbeafSnn char brand[MAXNAMELEN]; 45979acbbeafSnn 45989acbbeafSnn if (zonecfg_get_brand(handle, brand, sizeof (brand)) == Z_OK) 45999acbbeafSnn (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_BRAND), 46009acbbeafSnn brand); 46019acbbeafSnn else 46029acbbeafSnn (void) fprintf(fp, "%s %s\n", pt_to_str(PT_BRAND), 46039acbbeafSnn gettext("not specified")); 46049acbbeafSnn } 46059acbbeafSnn 46067c478bd9Sstevel@tonic-gate static void 46077c478bd9Sstevel@tonic-gate info_autoboot(zone_dochandle_t handle, FILE *fp) 46087c478bd9Sstevel@tonic-gate { 46097c478bd9Sstevel@tonic-gate boolean_t autoboot; 46107c478bd9Sstevel@tonic-gate int err; 46117c478bd9Sstevel@tonic-gate 46127c478bd9Sstevel@tonic-gate if ((err = zonecfg_get_autoboot(handle, &autoboot)) == Z_OK) 46137c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_AUTOBOOT), 46147c478bd9Sstevel@tonic-gate autoboot ? "true" : "false"); 46157c478bd9Sstevel@tonic-gate else 4616bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 46177c478bd9Sstevel@tonic-gate } 46187c478bd9Sstevel@tonic-gate 46197c478bd9Sstevel@tonic-gate static void 46207c478bd9Sstevel@tonic-gate info_pool(zone_dochandle_t handle, FILE *fp) 46217c478bd9Sstevel@tonic-gate { 46227c478bd9Sstevel@tonic-gate char pool[MAXNAMELEN]; 46237c478bd9Sstevel@tonic-gate int err; 46247c478bd9Sstevel@tonic-gate 46257c478bd9Sstevel@tonic-gate if ((err = zonecfg_get_pool(handle, pool, sizeof (pool))) == Z_OK) 46267c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_POOL), pool); 46277c478bd9Sstevel@tonic-gate else 4628bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 46297c478bd9Sstevel@tonic-gate } 46307c478bd9Sstevel@tonic-gate 4631ffbafc53Scomay static void 4632ffbafc53Scomay info_limitpriv(zone_dochandle_t handle, FILE *fp) 4633ffbafc53Scomay { 4634ffbafc53Scomay char *limitpriv; 4635ffbafc53Scomay int err; 4636ffbafc53Scomay 4637ffbafc53Scomay if ((err = zonecfg_get_limitpriv(handle, &limitpriv)) == Z_OK) { 4638ffbafc53Scomay (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_LIMITPRIV), 4639ffbafc53Scomay limitpriv); 4640ffbafc53Scomay free(limitpriv); 4641ffbafc53Scomay } else { 4642bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 4643ffbafc53Scomay } 4644ffbafc53Scomay } 4645ffbafc53Scomay 46463f2f09c1Sdp static void 46473f2f09c1Sdp info_bootargs(zone_dochandle_t handle, FILE *fp) 46483f2f09c1Sdp { 46493f2f09c1Sdp char bootargs[BOOTARGS_MAX]; 46503f2f09c1Sdp int err; 46513f2f09c1Sdp 46523f2f09c1Sdp if ((err = zonecfg_get_bootargs(handle, bootargs, 46533f2f09c1Sdp sizeof (bootargs))) == Z_OK) { 46543f2f09c1Sdp (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_BOOTARGS), 46553f2f09c1Sdp bootargs); 46563f2f09c1Sdp } else { 4657bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 46583f2f09c1Sdp } 46593f2f09c1Sdp } 46603f2f09c1Sdp 46610209230bSgjelinek static void 46620209230bSgjelinek info_sched(zone_dochandle_t handle, FILE *fp) 46630209230bSgjelinek { 46640209230bSgjelinek char sched[MAXNAMELEN]; 46650209230bSgjelinek int err; 46660209230bSgjelinek 46670209230bSgjelinek if ((err = zonecfg_get_sched_class(handle, sched, sizeof (sched))) 46680209230bSgjelinek == Z_OK) { 46690209230bSgjelinek (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_SCHED), sched); 46700209230bSgjelinek } else { 4671bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 46720209230bSgjelinek } 46730209230bSgjelinek } 46740209230bSgjelinek 4675f4b3ec61Sdh static void 4676f4b3ec61Sdh info_iptype(zone_dochandle_t handle, FILE *fp) 4677f4b3ec61Sdh { 4678f4b3ec61Sdh zone_iptype_t iptype; 4679f4b3ec61Sdh int err; 4680f4b3ec61Sdh 4681f4b3ec61Sdh if ((err = zonecfg_get_iptype(handle, &iptype)) == Z_OK) { 4682f4b3ec61Sdh switch (iptype) { 4683f4b3ec61Sdh case ZS_SHARED: 4684f4b3ec61Sdh (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_IPTYPE), 4685f4b3ec61Sdh "shared"); 4686f4b3ec61Sdh break; 4687f4b3ec61Sdh case ZS_EXCLUSIVE: 4688f4b3ec61Sdh (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_IPTYPE), 4689f4b3ec61Sdh "exclusive"); 4690f4b3ec61Sdh break; 4691f4b3ec61Sdh } 4692f4b3ec61Sdh } else { 4693bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 4694f4b3ec61Sdh } 4695f4b3ec61Sdh } 4696f4b3ec61Sdh 46975679c89fSjv static void 46985679c89fSjv info_hostid(zone_dochandle_t handle, FILE *fp) 46995679c89fSjv { 47005679c89fSjv char hostidp[HW_HOSTID_LEN]; 47015679c89fSjv 47025679c89fSjv /* 47035679c89fSjv * This will display "hostid: " if there isn't a hostid or an 47045679c89fSjv * error occurs while retrieving the hostid from the configuration 47055679c89fSjv * file. 47065679c89fSjv */ 47075679c89fSjv if (zonecfg_get_hostid(handle, hostidp, sizeof (hostidp)) != Z_OK) 47085679c89fSjv hostidp[0] = '\0'; 47095679c89fSjv (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_HOSTID), hostidp); 47105679c89fSjv } 47115679c89fSjv 47127c478bd9Sstevel@tonic-gate static void 47137c478bd9Sstevel@tonic-gate output_fs(FILE *fp, struct zone_fstab *fstab) 47147c478bd9Sstevel@tonic-gate { 47157c478bd9Sstevel@tonic-gate zone_fsopt_t *this; 47167c478bd9Sstevel@tonic-gate 47177c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n", rt_to_str(RT_FS)); 47187c478bd9Sstevel@tonic-gate output_prop(fp, PT_DIR, fstab->zone_fs_dir, B_TRUE); 47197c478bd9Sstevel@tonic-gate output_prop(fp, PT_SPECIAL, fstab->zone_fs_special, B_TRUE); 47207c478bd9Sstevel@tonic-gate output_prop(fp, PT_RAW, fstab->zone_fs_raw, B_TRUE); 47217c478bd9Sstevel@tonic-gate output_prop(fp, PT_TYPE, fstab->zone_fs_type, B_TRUE); 47227c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s: [", pt_to_str(PT_OPTIONS)); 47237c478bd9Sstevel@tonic-gate for (this = fstab->zone_fs_options; this != NULL; 47247c478bd9Sstevel@tonic-gate this = this->zone_fsopt_next) { 47257c478bd9Sstevel@tonic-gate if (strchr(this->zone_fsopt_opt, '=')) 47267c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\"%s\"", this->zone_fsopt_opt); 47277c478bd9Sstevel@tonic-gate else 47287c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s", this->zone_fsopt_opt); 47297c478bd9Sstevel@tonic-gate if (this->zone_fsopt_next != NULL) 47307c478bd9Sstevel@tonic-gate (void) fprintf(fp, ","); 47317c478bd9Sstevel@tonic-gate } 47327c478bd9Sstevel@tonic-gate (void) fprintf(fp, "]\n"); 47337c478bd9Sstevel@tonic-gate } 47347c478bd9Sstevel@tonic-gate 47357c478bd9Sstevel@tonic-gate static void 47367c478bd9Sstevel@tonic-gate output_ipd(FILE *fp, struct zone_fstab *ipdtab) 47377c478bd9Sstevel@tonic-gate { 47387c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n", rt_to_str(RT_IPD)); 47397c478bd9Sstevel@tonic-gate output_prop(fp, PT_DIR, ipdtab->zone_fs_dir, B_TRUE); 47407c478bd9Sstevel@tonic-gate } 47417c478bd9Sstevel@tonic-gate 47427c478bd9Sstevel@tonic-gate static void 47437c478bd9Sstevel@tonic-gate info_fs(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 47447c478bd9Sstevel@tonic-gate { 47457c478bd9Sstevel@tonic-gate struct zone_fstab lookup, user; 4746bbec428eSgjelinek boolean_t output = B_FALSE; 47477c478bd9Sstevel@tonic-gate 47487c478bd9Sstevel@tonic-gate if (zonecfg_setfsent(handle) != Z_OK) 47497c478bd9Sstevel@tonic-gate return; 47507c478bd9Sstevel@tonic-gate while (zonecfg_getfsent(handle, &lookup) == Z_OK) { 47517c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) { 47527c478bd9Sstevel@tonic-gate output_fs(fp, &lookup); 47537c478bd9Sstevel@tonic-gate goto loopend; 47547c478bd9Sstevel@tonic-gate } 4755bbec428eSgjelinek if (fill_in_fstab(cmd, &user, B_TRUE) != Z_OK) 47567c478bd9Sstevel@tonic-gate goto loopend; 47577c478bd9Sstevel@tonic-gate if (strlen(user.zone_fs_dir) > 0 && 47587c478bd9Sstevel@tonic-gate strcmp(user.zone_fs_dir, lookup.zone_fs_dir) != 0) 47597c478bd9Sstevel@tonic-gate goto loopend; /* no match */ 47607c478bd9Sstevel@tonic-gate if (strlen(user.zone_fs_special) > 0 && 47617c478bd9Sstevel@tonic-gate strcmp(user.zone_fs_special, lookup.zone_fs_special) != 0) 47627c478bd9Sstevel@tonic-gate goto loopend; /* no match */ 47637c478bd9Sstevel@tonic-gate if (strlen(user.zone_fs_type) > 0 && 47647c478bd9Sstevel@tonic-gate strcmp(user.zone_fs_type, lookup.zone_fs_type) != 0) 47657c478bd9Sstevel@tonic-gate goto loopend; /* no match */ 47667c478bd9Sstevel@tonic-gate output_fs(fp, &lookup); 4767bbec428eSgjelinek output = B_TRUE; 47687c478bd9Sstevel@tonic-gate loopend: 47697c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(lookup.zone_fs_options); 47707c478bd9Sstevel@tonic-gate } 47717c478bd9Sstevel@tonic-gate (void) zonecfg_endfsent(handle); 47727c478bd9Sstevel@tonic-gate /* 47737c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was 47747c478bd9Sstevel@tonic-gate * nothing to output. 47757c478bd9Sstevel@tonic-gate */ 47767c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0) 47777c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"), 47787c478bd9Sstevel@tonic-gate rt_to_str(RT_FS)); 47797c478bd9Sstevel@tonic-gate } 47807c478bd9Sstevel@tonic-gate 47817c478bd9Sstevel@tonic-gate static void 47827c478bd9Sstevel@tonic-gate info_ipd(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 47837c478bd9Sstevel@tonic-gate { 47847c478bd9Sstevel@tonic-gate struct zone_fstab lookup, user; 4785bbec428eSgjelinek boolean_t output = B_FALSE; 47867c478bd9Sstevel@tonic-gate 47877c478bd9Sstevel@tonic-gate if (zonecfg_setipdent(handle) != Z_OK) 47887c478bd9Sstevel@tonic-gate return; 47897c478bd9Sstevel@tonic-gate while (zonecfg_getipdent(handle, &lookup) == Z_OK) { 47907c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) { 47917c478bd9Sstevel@tonic-gate output_ipd(fp, &lookup); 47927c478bd9Sstevel@tonic-gate continue; 47937c478bd9Sstevel@tonic-gate } 4794bbec428eSgjelinek if (fill_in_ipdtab(cmd, &user, B_TRUE) != Z_OK) 47957c478bd9Sstevel@tonic-gate continue; 47967c478bd9Sstevel@tonic-gate if (strlen(user.zone_fs_dir) > 0 && 47977c478bd9Sstevel@tonic-gate strcmp(user.zone_fs_dir, lookup.zone_fs_dir) != 0) 47987c478bd9Sstevel@tonic-gate continue; /* no match */ 47997c478bd9Sstevel@tonic-gate output_ipd(fp, &lookup); 4800bbec428eSgjelinek output = B_TRUE; 48017c478bd9Sstevel@tonic-gate } 48027c478bd9Sstevel@tonic-gate (void) zonecfg_endipdent(handle); 48037c478bd9Sstevel@tonic-gate /* 48047c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was 48057c478bd9Sstevel@tonic-gate * nothing to output. 48067c478bd9Sstevel@tonic-gate */ 48077c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0) 48087c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"), 48097c478bd9Sstevel@tonic-gate rt_to_str(RT_IPD)); 48107c478bd9Sstevel@tonic-gate } 48117c478bd9Sstevel@tonic-gate 48127c478bd9Sstevel@tonic-gate static void 48137c478bd9Sstevel@tonic-gate output_net(FILE *fp, struct zone_nwiftab *nwiftab) 48147c478bd9Sstevel@tonic-gate { 48157c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n", rt_to_str(RT_NET)); 48167c478bd9Sstevel@tonic-gate output_prop(fp, PT_ADDRESS, nwiftab->zone_nwif_address, B_TRUE); 48177c478bd9Sstevel@tonic-gate output_prop(fp, PT_PHYSICAL, nwiftab->zone_nwif_physical, B_TRUE); 4818de860bd9Sgfaden output_prop(fp, PT_DEFROUTER, nwiftab->zone_nwif_defrouter, B_TRUE); 48197c478bd9Sstevel@tonic-gate } 48207c478bd9Sstevel@tonic-gate 48217c478bd9Sstevel@tonic-gate static void 48227c478bd9Sstevel@tonic-gate info_net(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 48237c478bd9Sstevel@tonic-gate { 48247c478bd9Sstevel@tonic-gate struct zone_nwiftab lookup, user; 4825bbec428eSgjelinek boolean_t output = B_FALSE; 48267c478bd9Sstevel@tonic-gate 48277c478bd9Sstevel@tonic-gate if (zonecfg_setnwifent(handle) != Z_OK) 48287c478bd9Sstevel@tonic-gate return; 48297c478bd9Sstevel@tonic-gate while (zonecfg_getnwifent(handle, &lookup) == Z_OK) { 48307c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) { 48317c478bd9Sstevel@tonic-gate output_net(fp, &lookup); 48327c478bd9Sstevel@tonic-gate continue; 48337c478bd9Sstevel@tonic-gate } 4834bbec428eSgjelinek if (fill_in_nwiftab(cmd, &user, B_TRUE) != Z_OK) 48357c478bd9Sstevel@tonic-gate continue; 48367c478bd9Sstevel@tonic-gate if (strlen(user.zone_nwif_physical) > 0 && 48377c478bd9Sstevel@tonic-gate strcmp(user.zone_nwif_physical, 48387c478bd9Sstevel@tonic-gate lookup.zone_nwif_physical) != 0) 48397c478bd9Sstevel@tonic-gate continue; /* no match */ 4840f4b3ec61Sdh /* If present make sure it matches */ 48417c478bd9Sstevel@tonic-gate if (strlen(user.zone_nwif_address) > 0 && 48427c478bd9Sstevel@tonic-gate !zonecfg_same_net_address(user.zone_nwif_address, 48437c478bd9Sstevel@tonic-gate lookup.zone_nwif_address)) 48447c478bd9Sstevel@tonic-gate continue; /* no match */ 48457c478bd9Sstevel@tonic-gate output_net(fp, &lookup); 4846bbec428eSgjelinek output = B_TRUE; 48477c478bd9Sstevel@tonic-gate } 48487c478bd9Sstevel@tonic-gate (void) zonecfg_endnwifent(handle); 48497c478bd9Sstevel@tonic-gate /* 48507c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was 48517c478bd9Sstevel@tonic-gate * nothing to output. 48527c478bd9Sstevel@tonic-gate */ 48537c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0) 48547c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"), 48557c478bd9Sstevel@tonic-gate rt_to_str(RT_NET)); 48567c478bd9Sstevel@tonic-gate } 48577c478bd9Sstevel@tonic-gate 48587c478bd9Sstevel@tonic-gate static void 48597c478bd9Sstevel@tonic-gate output_dev(FILE *fp, struct zone_devtab *devtab) 48607c478bd9Sstevel@tonic-gate { 486127e6fb21Sdp (void) fprintf(fp, "%s:\n", rt_to_str(RT_DEVICE)); 48627c478bd9Sstevel@tonic-gate output_prop(fp, PT_MATCH, devtab->zone_dev_match, B_TRUE); 48637c478bd9Sstevel@tonic-gate } 48647c478bd9Sstevel@tonic-gate 48657c478bd9Sstevel@tonic-gate static void 48667c478bd9Sstevel@tonic-gate info_dev(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 48677c478bd9Sstevel@tonic-gate { 48687c478bd9Sstevel@tonic-gate struct zone_devtab lookup, user; 4869bbec428eSgjelinek boolean_t output = B_FALSE; 48707c478bd9Sstevel@tonic-gate 48717c478bd9Sstevel@tonic-gate if (zonecfg_setdevent(handle) != Z_OK) 48727c478bd9Sstevel@tonic-gate return; 48737c478bd9Sstevel@tonic-gate while (zonecfg_getdevent(handle, &lookup) == Z_OK) { 48747c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) { 48757c478bd9Sstevel@tonic-gate output_dev(fp, &lookup); 48767c478bd9Sstevel@tonic-gate continue; 48777c478bd9Sstevel@tonic-gate } 4878bbec428eSgjelinek if (fill_in_devtab(cmd, &user, B_TRUE) != Z_OK) 48797c478bd9Sstevel@tonic-gate continue; 48807c478bd9Sstevel@tonic-gate if (strlen(user.zone_dev_match) > 0 && 48817c478bd9Sstevel@tonic-gate strcmp(user.zone_dev_match, lookup.zone_dev_match) != 0) 48827c478bd9Sstevel@tonic-gate continue; /* no match */ 48837c478bd9Sstevel@tonic-gate output_dev(fp, &lookup); 4884bbec428eSgjelinek output = B_TRUE; 48857c478bd9Sstevel@tonic-gate } 48867c478bd9Sstevel@tonic-gate (void) zonecfg_enddevent(handle); 48877c478bd9Sstevel@tonic-gate /* 48887c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was 48897c478bd9Sstevel@tonic-gate * nothing to output. 48907c478bd9Sstevel@tonic-gate */ 48917c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0) 48927c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"), 48937c478bd9Sstevel@tonic-gate rt_to_str(RT_DEVICE)); 48947c478bd9Sstevel@tonic-gate } 48957c478bd9Sstevel@tonic-gate 48967c478bd9Sstevel@tonic-gate static void 48977c478bd9Sstevel@tonic-gate output_rctl(FILE *fp, struct zone_rctltab *rctltab) 48987c478bd9Sstevel@tonic-gate { 48997c478bd9Sstevel@tonic-gate struct zone_rctlvaltab *valptr; 49007c478bd9Sstevel@tonic-gate 49017c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n", rt_to_str(RT_RCTL)); 49027c478bd9Sstevel@tonic-gate output_prop(fp, PT_NAME, rctltab->zone_rctl_name, B_TRUE); 49037c478bd9Sstevel@tonic-gate for (valptr = rctltab->zone_rctl_valptr; valptr != NULL; 49047c478bd9Sstevel@tonic-gate valptr = valptr->zone_rctlval_next) { 49057c478bd9Sstevel@tonic-gate fprintf(fp, "\t%s: (%s=%s,%s=%s,%s=%s)\n", 49067c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE), 49077c478bd9Sstevel@tonic-gate pt_to_str(PT_PRIV), valptr->zone_rctlval_priv, 49087c478bd9Sstevel@tonic-gate pt_to_str(PT_LIMIT), valptr->zone_rctlval_limit, 49097c478bd9Sstevel@tonic-gate pt_to_str(PT_ACTION), valptr->zone_rctlval_action); 49107c478bd9Sstevel@tonic-gate } 49117c478bd9Sstevel@tonic-gate } 49127c478bd9Sstevel@tonic-gate 49137c478bd9Sstevel@tonic-gate static void 49147c478bd9Sstevel@tonic-gate info_rctl(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 49157c478bd9Sstevel@tonic-gate { 49167c478bd9Sstevel@tonic-gate struct zone_rctltab lookup, user; 4917bbec428eSgjelinek boolean_t output = B_FALSE; 49187c478bd9Sstevel@tonic-gate 49197c478bd9Sstevel@tonic-gate if (zonecfg_setrctlent(handle) != Z_OK) 49207c478bd9Sstevel@tonic-gate return; 49217c478bd9Sstevel@tonic-gate while (zonecfg_getrctlent(handle, &lookup) == Z_OK) { 49227c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) { 49237c478bd9Sstevel@tonic-gate output_rctl(fp, &lookup); 4924bbec428eSgjelinek } else if (fill_in_rctltab(cmd, &user, B_TRUE) == Z_OK && 49257c478bd9Sstevel@tonic-gate (strlen(user.zone_rctl_name) == 0 || 49267c478bd9Sstevel@tonic-gate strcmp(user.zone_rctl_name, lookup.zone_rctl_name) == 0)) { 49277c478bd9Sstevel@tonic-gate output_rctl(fp, &lookup); 4928bbec428eSgjelinek output = B_TRUE; 49297c478bd9Sstevel@tonic-gate } 49307c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(lookup.zone_rctl_valptr); 49317c478bd9Sstevel@tonic-gate } 49327c478bd9Sstevel@tonic-gate (void) zonecfg_endrctlent(handle); 49337c478bd9Sstevel@tonic-gate /* 49347c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was 49357c478bd9Sstevel@tonic-gate * nothing to output. 49367c478bd9Sstevel@tonic-gate */ 49377c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0) 49387c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"), 49397c478bd9Sstevel@tonic-gate rt_to_str(RT_RCTL)); 49407c478bd9Sstevel@tonic-gate } 49417c478bd9Sstevel@tonic-gate 49427c478bd9Sstevel@tonic-gate static void 49437c478bd9Sstevel@tonic-gate output_attr(FILE *fp, struct zone_attrtab *attrtab) 49447c478bd9Sstevel@tonic-gate { 49457c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n", rt_to_str(RT_ATTR)); 49467c478bd9Sstevel@tonic-gate output_prop(fp, PT_NAME, attrtab->zone_attr_name, B_TRUE); 49477c478bd9Sstevel@tonic-gate output_prop(fp, PT_TYPE, attrtab->zone_attr_type, B_TRUE); 49487c478bd9Sstevel@tonic-gate output_prop(fp, PT_VALUE, attrtab->zone_attr_value, B_TRUE); 49497c478bd9Sstevel@tonic-gate } 49507c478bd9Sstevel@tonic-gate 49517c478bd9Sstevel@tonic-gate static void 49527c478bd9Sstevel@tonic-gate info_attr(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 49537c478bd9Sstevel@tonic-gate { 49547c478bd9Sstevel@tonic-gate struct zone_attrtab lookup, user; 4955bbec428eSgjelinek boolean_t output = B_FALSE; 49567c478bd9Sstevel@tonic-gate 49577c478bd9Sstevel@tonic-gate if (zonecfg_setattrent(handle) != Z_OK) 49587c478bd9Sstevel@tonic-gate return; 49597c478bd9Sstevel@tonic-gate while (zonecfg_getattrent(handle, &lookup) == Z_OK) { 49607c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) { 49617c478bd9Sstevel@tonic-gate output_attr(fp, &lookup); 49627c478bd9Sstevel@tonic-gate continue; 49637c478bd9Sstevel@tonic-gate } 4964bbec428eSgjelinek if (fill_in_attrtab(cmd, &user, B_TRUE) != Z_OK) 49657c478bd9Sstevel@tonic-gate continue; 49667c478bd9Sstevel@tonic-gate if (strlen(user.zone_attr_name) > 0 && 49677c478bd9Sstevel@tonic-gate strcmp(user.zone_attr_name, lookup.zone_attr_name) != 0) 49687c478bd9Sstevel@tonic-gate continue; /* no match */ 49697c478bd9Sstevel@tonic-gate if (strlen(user.zone_attr_type) > 0 && 49707c478bd9Sstevel@tonic-gate strcmp(user.zone_attr_type, lookup.zone_attr_type) != 0) 49717c478bd9Sstevel@tonic-gate continue; /* no match */ 49727c478bd9Sstevel@tonic-gate if (strlen(user.zone_attr_value) > 0 && 49737c478bd9Sstevel@tonic-gate strcmp(user.zone_attr_value, lookup.zone_attr_value) != 0) 49747c478bd9Sstevel@tonic-gate continue; /* no match */ 49757c478bd9Sstevel@tonic-gate output_attr(fp, &lookup); 4976bbec428eSgjelinek output = B_TRUE; 49777c478bd9Sstevel@tonic-gate } 49787c478bd9Sstevel@tonic-gate (void) zonecfg_endattrent(handle); 49797c478bd9Sstevel@tonic-gate /* 49807c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was 49817c478bd9Sstevel@tonic-gate * nothing to output. 49827c478bd9Sstevel@tonic-gate */ 49837c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0) 49847c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"), 49857c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR)); 49867c478bd9Sstevel@tonic-gate } 49877c478bd9Sstevel@tonic-gate 4988fa9e4066Sahrens static void 4989fa9e4066Sahrens output_ds(FILE *fp, struct zone_dstab *dstab) 4990fa9e4066Sahrens { 4991fa9e4066Sahrens (void) fprintf(fp, "%s:\n", rt_to_str(RT_DATASET)); 4992fa9e4066Sahrens output_prop(fp, PT_NAME, dstab->zone_dataset_name, B_TRUE); 4993fa9e4066Sahrens } 4994fa9e4066Sahrens 4995fa9e4066Sahrens static void 4996fa9e4066Sahrens info_ds(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 4997fa9e4066Sahrens { 4998fa9e4066Sahrens struct zone_dstab lookup, user; 4999bbec428eSgjelinek boolean_t output = B_FALSE; 5000fa9e4066Sahrens 50010209230bSgjelinek if (zonecfg_setdsent(handle) != Z_OK) 5002fa9e4066Sahrens return; 5003fa9e4066Sahrens while (zonecfg_getdsent(handle, &lookup) == Z_OK) { 5004fa9e4066Sahrens if (cmd->cmd_prop_nv_pairs == 0) { 5005fa9e4066Sahrens output_ds(fp, &lookup); 5006fa9e4066Sahrens continue; 5007fa9e4066Sahrens } 5008bbec428eSgjelinek if (fill_in_dstab(cmd, &user, B_TRUE) != Z_OK) 5009fa9e4066Sahrens continue; 5010fa9e4066Sahrens if (strlen(user.zone_dataset_name) > 0 && 5011fa9e4066Sahrens strcmp(user.zone_dataset_name, 5012fa9e4066Sahrens lookup.zone_dataset_name) != 0) 5013fa9e4066Sahrens continue; /* no match */ 5014fa9e4066Sahrens output_ds(fp, &lookup); 5015bbec428eSgjelinek output = B_TRUE; 5016fa9e4066Sahrens } 5017fa9e4066Sahrens (void) zonecfg_enddsent(handle); 5018fa9e4066Sahrens /* 5019fa9e4066Sahrens * If a property n/v pair was specified, warn the user if there was 5020fa9e4066Sahrens * nothing to output. 5021fa9e4066Sahrens */ 5022fa9e4066Sahrens if (!output && cmd->cmd_prop_nv_pairs > 0) 5023fa9e4066Sahrens (void) printf(gettext("No such %s resource.\n"), 5024fa9e4066Sahrens rt_to_str(RT_DATASET)); 5025fa9e4066Sahrens } 5026fa9e4066Sahrens 50270209230bSgjelinek static void 50280209230bSgjelinek output_pset(FILE *fp, struct zone_psettab *psettab) 50290209230bSgjelinek { 50300209230bSgjelinek (void) fprintf(fp, "%s:\n", rt_to_str(RT_DCPU)); 50310209230bSgjelinek if (strcmp(psettab->zone_ncpu_min, psettab->zone_ncpu_max) == 0) 50320209230bSgjelinek (void) fprintf(fp, "\t%s: %s\n", pt_to_str(PT_NCPUS), 50330209230bSgjelinek psettab->zone_ncpu_max); 50340209230bSgjelinek else 50350209230bSgjelinek (void) fprintf(fp, "\t%s: %s-%s\n", pt_to_str(PT_NCPUS), 50360209230bSgjelinek psettab->zone_ncpu_min, psettab->zone_ncpu_max); 50370209230bSgjelinek if (psettab->zone_importance[0] != '\0') 50380209230bSgjelinek (void) fprintf(fp, "\t%s: %s\n", pt_to_str(PT_IMPORTANCE), 50390209230bSgjelinek psettab->zone_importance); 50400209230bSgjelinek } 50410209230bSgjelinek 50420209230bSgjelinek static void 50430209230bSgjelinek info_pset(zone_dochandle_t handle, FILE *fp) 50440209230bSgjelinek { 50450209230bSgjelinek struct zone_psettab lookup; 50460209230bSgjelinek 50470209230bSgjelinek if (zonecfg_getpsetent(handle, &lookup) == Z_OK) 50480209230bSgjelinek output_pset(fp, &lookup); 50490209230bSgjelinek } 50500209230bSgjelinek 5051c97ad5cdSakolb static void 5052c97ad5cdSakolb output_pcap(FILE *fp) 5053c97ad5cdSakolb { 5054c97ad5cdSakolb uint64_t cap; 5055c97ad5cdSakolb 5056c97ad5cdSakolb if (zonecfg_get_aliased_rctl(handle, ALIAS_CPUCAP, &cap) == Z_OK) { 5057c97ad5cdSakolb float scaled = (float)cap / 100; 5058c97ad5cdSakolb (void) fprintf(fp, "%s:\n", rt_to_str(RT_PCAP)); 5059c97ad5cdSakolb (void) fprintf(fp, "\t[%s: %.2f]\n", pt_to_str(PT_NCPUS), 5060c97ad5cdSakolb scaled); 5061c97ad5cdSakolb } 5062c97ad5cdSakolb } 5063c97ad5cdSakolb 5064c97ad5cdSakolb static void 5065c97ad5cdSakolb info_pcap(FILE *fp) 5066c97ad5cdSakolb { 5067c97ad5cdSakolb output_pcap(fp); 5068c97ad5cdSakolb } 5069c97ad5cdSakolb 5070c97ad5cdSakolb 50710209230bSgjelinek static void 50720209230bSgjelinek info_aliased_rctl(zone_dochandle_t handle, FILE *fp, char *alias) 50730209230bSgjelinek { 50740209230bSgjelinek uint64_t limit; 50750209230bSgjelinek 50760209230bSgjelinek if (zonecfg_get_aliased_rctl(handle, alias, &limit) == Z_OK) { 50770209230bSgjelinek /* convert memory based properties */ 50780209230bSgjelinek if (strcmp(alias, ALIAS_MAXSHMMEM) == 0) { 50790209230bSgjelinek char buf[128]; 50800209230bSgjelinek 50810209230bSgjelinek (void) snprintf(buf, sizeof (buf), "%llu", limit); 50820209230bSgjelinek bytes_to_units(buf, buf, sizeof (buf)); 50830209230bSgjelinek (void) fprintf(fp, "[%s: %s]\n", alias, buf); 50840209230bSgjelinek return; 50850209230bSgjelinek } 50860209230bSgjelinek 50870209230bSgjelinek (void) fprintf(fp, "[%s: %llu]\n", alias, limit); 50880209230bSgjelinek } 50890209230bSgjelinek } 50900209230bSgjelinek 50910209230bSgjelinek static void 50920209230bSgjelinek bytes_to_units(char *str, char *buf, int bufsize) 50930209230bSgjelinek { 50940209230bSgjelinek unsigned long long num; 50950209230bSgjelinek unsigned long long save = 0; 50960209230bSgjelinek char *units = "BKMGT"; 50970209230bSgjelinek char *up = units; 50980209230bSgjelinek 50990209230bSgjelinek num = strtoll(str, NULL, 10); 51000209230bSgjelinek 51010209230bSgjelinek if (num < 1024) { 51020209230bSgjelinek (void) snprintf(buf, bufsize, "%llu", num); 51030209230bSgjelinek return; 51040209230bSgjelinek } 51050209230bSgjelinek 51060209230bSgjelinek while ((num >= 1024) && (*up != 'T')) { 51070209230bSgjelinek up++; /* next unit of measurement */ 51080209230bSgjelinek save = num; 51090209230bSgjelinek num = (num + 512) >> 10; 51100209230bSgjelinek } 51110209230bSgjelinek 51120209230bSgjelinek /* check if we should output a fraction. snprintf will round for us */ 51130209230bSgjelinek if (save % 1024 != 0 && ((save >> 10) < 10)) 51140209230bSgjelinek (void) snprintf(buf, bufsize, "%2.1f%c", ((float)save / 1024), 51150209230bSgjelinek *up); 51160209230bSgjelinek else 51170209230bSgjelinek (void) snprintf(buf, bufsize, "%llu%c", num, *up); 51180209230bSgjelinek } 51190209230bSgjelinek 51200209230bSgjelinek static void 51210209230bSgjelinek output_mcap(FILE *fp, struct zone_mcaptab *mcaptab, int showswap, 51220209230bSgjelinek uint64_t maxswap, int showlocked, uint64_t maxlocked) 51230209230bSgjelinek { 51240209230bSgjelinek char buf[128]; 51250209230bSgjelinek 51260209230bSgjelinek (void) fprintf(fp, "%s:\n", rt_to_str(RT_MCAP)); 51270209230bSgjelinek if (mcaptab->zone_physmem_cap[0] != '\0') { 51280209230bSgjelinek bytes_to_units(mcaptab->zone_physmem_cap, buf, sizeof (buf)); 51290209230bSgjelinek output_prop(fp, PT_PHYSICAL, buf, B_TRUE); 51300209230bSgjelinek } 51310209230bSgjelinek 51320209230bSgjelinek if (showswap == Z_OK) { 51330209230bSgjelinek (void) snprintf(buf, sizeof (buf), "%llu", maxswap); 51340209230bSgjelinek bytes_to_units(buf, buf, sizeof (buf)); 51350209230bSgjelinek output_prop(fp, PT_SWAP, buf, B_TRUE); 51360209230bSgjelinek } 51370209230bSgjelinek 51380209230bSgjelinek if (showlocked == Z_OK) { 51390209230bSgjelinek (void) snprintf(buf, sizeof (buf), "%llu", maxlocked); 51400209230bSgjelinek bytes_to_units(buf, buf, sizeof (buf)); 51410209230bSgjelinek output_prop(fp, PT_LOCKED, buf, B_TRUE); 51420209230bSgjelinek } 51430209230bSgjelinek } 51440209230bSgjelinek 51450209230bSgjelinek static void 51460209230bSgjelinek info_mcap(zone_dochandle_t handle, FILE *fp) 51470209230bSgjelinek { 51480209230bSgjelinek int res1, res2, res3; 51490209230bSgjelinek uint64_t swap_limit; 51500209230bSgjelinek uint64_t locked_limit; 51510209230bSgjelinek struct zone_mcaptab lookup; 51520209230bSgjelinek 51530209230bSgjelinek bzero(&lookup, sizeof (lookup)); 51540209230bSgjelinek res1 = zonecfg_getmcapent(handle, &lookup); 51550209230bSgjelinek res2 = zonecfg_get_aliased_rctl(handle, ALIAS_MAXSWAP, &swap_limit); 51560209230bSgjelinek res3 = zonecfg_get_aliased_rctl(handle, ALIAS_MAXLOCKEDMEM, 51570209230bSgjelinek &locked_limit); 51580209230bSgjelinek 51590209230bSgjelinek if (res1 == Z_OK || res2 == Z_OK || res3 == Z_OK) 51600209230bSgjelinek output_mcap(fp, &lookup, res2, swap_limit, res3, locked_limit); 51610209230bSgjelinek } 51620209230bSgjelinek 51637c478bd9Sstevel@tonic-gate void 51647c478bd9Sstevel@tonic-gate info_func(cmd_t *cmd) 51657c478bd9Sstevel@tonic-gate { 51667c478bd9Sstevel@tonic-gate FILE *fp = stdout; 5167bbec428eSgjelinek boolean_t need_to_close = B_FALSE; 51687c478bd9Sstevel@tonic-gate char *pager; 51690209230bSgjelinek int type; 51700209230bSgjelinek int res1, res2; 51710209230bSgjelinek uint64_t swap_limit; 51720209230bSgjelinek uint64_t locked_limit; 51733042b8b5Sbatschul struct stat statbuf; 51747c478bd9Sstevel@tonic-gate 51757c478bd9Sstevel@tonic-gate assert(cmd != NULL); 51767c478bd9Sstevel@tonic-gate 5177bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 51787c478bd9Sstevel@tonic-gate return; 51797c478bd9Sstevel@tonic-gate 51807c478bd9Sstevel@tonic-gate /* don't page error output */ 51817c478bd9Sstevel@tonic-gate if (interactive_mode) { 51827c478bd9Sstevel@tonic-gate if ((pager = getenv("PAGER")) == NULL) 51837c478bd9Sstevel@tonic-gate pager = PAGER; 51843042b8b5Sbatschul 51853042b8b5Sbatschul if (stat(pager, &statbuf) == 0) { 51863042b8b5Sbatschul if ((fp = popen(pager, "w")) != NULL) 51873042b8b5Sbatschul need_to_close = B_TRUE; 51883042b8b5Sbatschul else 51893042b8b5Sbatschul fp = stdout; 51903042b8b5Sbatschul } else { 51913042b8b5Sbatschul zerr(gettext("PAGER %s does not exist (%s)."), 51923042b8b5Sbatschul pager, strerror(errno)); 51933042b8b5Sbatschul } 51943042b8b5Sbatschul 51957c478bd9Sstevel@tonic-gate setbuf(fp, NULL); 51967c478bd9Sstevel@tonic-gate } 51977c478bd9Sstevel@tonic-gate 51987c478bd9Sstevel@tonic-gate if (!global_scope) { 51997c478bd9Sstevel@tonic-gate switch (resource_scope) { 52007c478bd9Sstevel@tonic-gate case RT_FS: 52017c478bd9Sstevel@tonic-gate output_fs(fp, &in_progress_fstab); 52027c478bd9Sstevel@tonic-gate break; 52037c478bd9Sstevel@tonic-gate case RT_IPD: 52047c478bd9Sstevel@tonic-gate output_ipd(fp, &in_progress_ipdtab); 52057c478bd9Sstevel@tonic-gate break; 52067c478bd9Sstevel@tonic-gate case RT_NET: 52077c478bd9Sstevel@tonic-gate output_net(fp, &in_progress_nwiftab); 52087c478bd9Sstevel@tonic-gate break; 52097c478bd9Sstevel@tonic-gate case RT_DEVICE: 52107c478bd9Sstevel@tonic-gate output_dev(fp, &in_progress_devtab); 52117c478bd9Sstevel@tonic-gate break; 52127c478bd9Sstevel@tonic-gate case RT_RCTL: 52137c478bd9Sstevel@tonic-gate output_rctl(fp, &in_progress_rctltab); 52147c478bd9Sstevel@tonic-gate break; 52157c478bd9Sstevel@tonic-gate case RT_ATTR: 52167c478bd9Sstevel@tonic-gate output_attr(fp, &in_progress_attrtab); 52177c478bd9Sstevel@tonic-gate break; 5218fa9e4066Sahrens case RT_DATASET: 5219fa9e4066Sahrens output_ds(fp, &in_progress_dstab); 5220fa9e4066Sahrens break; 52210209230bSgjelinek case RT_DCPU: 52220209230bSgjelinek output_pset(fp, &in_progress_psettab); 52230209230bSgjelinek break; 5224c97ad5cdSakolb case RT_PCAP: 5225c97ad5cdSakolb output_pcap(fp); 5226c97ad5cdSakolb break; 52270209230bSgjelinek case RT_MCAP: 52280209230bSgjelinek res1 = zonecfg_get_aliased_rctl(handle, ALIAS_MAXSWAP, 52290209230bSgjelinek &swap_limit); 52300209230bSgjelinek res2 = zonecfg_get_aliased_rctl(handle, 52310209230bSgjelinek ALIAS_MAXLOCKEDMEM, &locked_limit); 52320209230bSgjelinek output_mcap(fp, &in_progress_mcaptab, res1, swap_limit, 52330209230bSgjelinek res2, locked_limit); 52340209230bSgjelinek break; 52357c478bd9Sstevel@tonic-gate } 52367c478bd9Sstevel@tonic-gate goto cleanup; 52377c478bd9Sstevel@tonic-gate } 52387c478bd9Sstevel@tonic-gate 52390209230bSgjelinek type = cmd->cmd_res_type; 52400209230bSgjelinek 52410209230bSgjelinek if (gz_invalid_rt_property(type)) { 52420209230bSgjelinek zerr(gettext("%s is not a valid property for the global zone."), 52430209230bSgjelinek rt_to_str(type)); 52440209230bSgjelinek goto cleanup; 52450209230bSgjelinek } 52460209230bSgjelinek 52470209230bSgjelinek if (gz_invalid_resource(type)) { 52480209230bSgjelinek zerr(gettext("%s is not a valid resource for the global zone."), 52490209230bSgjelinek rt_to_str(type)); 52500209230bSgjelinek goto cleanup; 52510209230bSgjelinek } 52520209230bSgjelinek 52537c478bd9Sstevel@tonic-gate switch (cmd->cmd_res_type) { 52547c478bd9Sstevel@tonic-gate case RT_UNKNOWN: 5255087719fdSdp info_zonename(handle, fp); 52560209230bSgjelinek if (!global_zone) { 52570209230bSgjelinek info_zonepath(handle, fp); 52580209230bSgjelinek info_brand(handle, fp); 52590209230bSgjelinek info_autoboot(handle, fp); 52600209230bSgjelinek info_bootargs(handle, fp); 52610209230bSgjelinek } 52627c478bd9Sstevel@tonic-gate info_pool(handle, fp); 52630209230bSgjelinek if (!global_zone) { 52640209230bSgjelinek info_limitpriv(handle, fp); 52650209230bSgjelinek info_sched(handle, fp); 5266f4b3ec61Sdh info_iptype(handle, fp); 52675679c89fSjv info_hostid(handle, fp); 52680209230bSgjelinek } 52690209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXLWPS); 52700209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXSHMMEM); 52710209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXSHMIDS); 52720209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXMSGIDS); 52730209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXSEMIDS); 52740209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_SHARES); 52750209230bSgjelinek if (!global_zone) { 52760209230bSgjelinek info_ipd(handle, fp, cmd); 52770209230bSgjelinek info_fs(handle, fp, cmd); 52780209230bSgjelinek info_net(handle, fp, cmd); 52790209230bSgjelinek info_dev(handle, fp, cmd); 52800209230bSgjelinek } 52810209230bSgjelinek info_pset(handle, fp); 5282c97ad5cdSakolb info_pcap(fp); 52830209230bSgjelinek info_mcap(handle, fp); 52840209230bSgjelinek if (!global_zone) { 52850209230bSgjelinek info_attr(handle, fp, cmd); 52860209230bSgjelinek info_ds(handle, fp, cmd); 52870209230bSgjelinek } 52887c478bd9Sstevel@tonic-gate info_rctl(handle, fp, cmd); 52897c478bd9Sstevel@tonic-gate break; 5290087719fdSdp case RT_ZONENAME: 5291087719fdSdp info_zonename(handle, fp); 5292087719fdSdp break; 52937c478bd9Sstevel@tonic-gate case RT_ZONEPATH: 52947c478bd9Sstevel@tonic-gate info_zonepath(handle, fp); 52957c478bd9Sstevel@tonic-gate break; 52969acbbeafSnn case RT_BRAND: 52979acbbeafSnn info_brand(handle, fp); 52989acbbeafSnn break; 52997c478bd9Sstevel@tonic-gate case RT_AUTOBOOT: 53007c478bd9Sstevel@tonic-gate info_autoboot(handle, fp); 53017c478bd9Sstevel@tonic-gate break; 53027c478bd9Sstevel@tonic-gate case RT_POOL: 53037c478bd9Sstevel@tonic-gate info_pool(handle, fp); 53047c478bd9Sstevel@tonic-gate break; 5305ffbafc53Scomay case RT_LIMITPRIV: 5306ffbafc53Scomay info_limitpriv(handle, fp); 5307ffbafc53Scomay break; 53083f2f09c1Sdp case RT_BOOTARGS: 53093f2f09c1Sdp info_bootargs(handle, fp); 53103f2f09c1Sdp break; 53110209230bSgjelinek case RT_SCHED: 53120209230bSgjelinek info_sched(handle, fp); 53130209230bSgjelinek break; 5314f4b3ec61Sdh case RT_IPTYPE: 5315f4b3ec61Sdh info_iptype(handle, fp); 5316f4b3ec61Sdh break; 53170209230bSgjelinek case RT_MAXLWPS: 53180209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXLWPS); 53190209230bSgjelinek break; 53200209230bSgjelinek case RT_MAXSHMMEM: 53210209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXSHMMEM); 53220209230bSgjelinek break; 53230209230bSgjelinek case RT_MAXSHMIDS: 53240209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXSHMIDS); 53250209230bSgjelinek break; 53260209230bSgjelinek case RT_MAXMSGIDS: 53270209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXMSGIDS); 53280209230bSgjelinek break; 53290209230bSgjelinek case RT_MAXSEMIDS: 53300209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXSEMIDS); 53310209230bSgjelinek break; 53320209230bSgjelinek case RT_SHARES: 53330209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_SHARES); 53340209230bSgjelinek break; 53357c478bd9Sstevel@tonic-gate case RT_FS: 53367c478bd9Sstevel@tonic-gate info_fs(handle, fp, cmd); 53377c478bd9Sstevel@tonic-gate break; 53387c478bd9Sstevel@tonic-gate case RT_IPD: 53397c478bd9Sstevel@tonic-gate info_ipd(handle, fp, cmd); 53407c478bd9Sstevel@tonic-gate break; 53417c478bd9Sstevel@tonic-gate case RT_NET: 53427c478bd9Sstevel@tonic-gate info_net(handle, fp, cmd); 53437c478bd9Sstevel@tonic-gate break; 53447c478bd9Sstevel@tonic-gate case RT_DEVICE: 53457c478bd9Sstevel@tonic-gate info_dev(handle, fp, cmd); 53467c478bd9Sstevel@tonic-gate break; 53477c478bd9Sstevel@tonic-gate case RT_RCTL: 53487c478bd9Sstevel@tonic-gate info_rctl(handle, fp, cmd); 53497c478bd9Sstevel@tonic-gate break; 53507c478bd9Sstevel@tonic-gate case RT_ATTR: 53517c478bd9Sstevel@tonic-gate info_attr(handle, fp, cmd); 53527c478bd9Sstevel@tonic-gate break; 5353fa9e4066Sahrens case RT_DATASET: 5354fa9e4066Sahrens info_ds(handle, fp, cmd); 5355fa9e4066Sahrens break; 53560209230bSgjelinek case RT_DCPU: 53570209230bSgjelinek info_pset(handle, fp); 53580209230bSgjelinek break; 5359c97ad5cdSakolb case RT_PCAP: 5360c97ad5cdSakolb info_pcap(fp); 5361c97ad5cdSakolb break; 53620209230bSgjelinek case RT_MCAP: 53630209230bSgjelinek info_mcap(handle, fp); 53640209230bSgjelinek break; 53655679c89fSjv case RT_HOSTID: 53665679c89fSjv info_hostid(handle, fp); 53675679c89fSjv break; 53687c478bd9Sstevel@tonic-gate default: 53697c478bd9Sstevel@tonic-gate zone_perror(rt_to_str(cmd->cmd_res_type), Z_NO_RESOURCE_TYPE, 5370bbec428eSgjelinek B_TRUE); 53717c478bd9Sstevel@tonic-gate } 53727c478bd9Sstevel@tonic-gate 53737c478bd9Sstevel@tonic-gate cleanup: 53747c478bd9Sstevel@tonic-gate if (need_to_close) 53757c478bd9Sstevel@tonic-gate (void) pclose(fp); 53767c478bd9Sstevel@tonic-gate } 53777c478bd9Sstevel@tonic-gate 5378087719fdSdp /* 5379087719fdSdp * Helper function for verify-- checks that a required string property 5380087719fdSdp * exists. 5381087719fdSdp */ 5382087719fdSdp static void 5383087719fdSdp check_reqd_prop(char *attr, int rt, int pt, int *ret_val) 53847c478bd9Sstevel@tonic-gate { 5385087719fdSdp if (strlen(attr) == 0) { 5386087719fdSdp zerr(gettext("%s: %s not specified"), rt_to_str(rt), 5387087719fdSdp pt_to_str(pt)); 5388bbec428eSgjelinek saw_error = B_TRUE; 5389087719fdSdp if (*ret_val == Z_OK) 5390087719fdSdp *ret_val = Z_REQD_PROPERTY_MISSING; 53917c478bd9Sstevel@tonic-gate } 53927c478bd9Sstevel@tonic-gate } 53937c478bd9Sstevel@tonic-gate 53949acbbeafSnn static int 53959acbbeafSnn do_subproc(char *cmdbuf) 53969acbbeafSnn { 53979acbbeafSnn char inbuf[MAX_CMD_LEN]; 53989acbbeafSnn FILE *file; 53999acbbeafSnn int status; 54009acbbeafSnn 54019acbbeafSnn file = popen(cmdbuf, "r"); 54029acbbeafSnn if (file == NULL) { 54039acbbeafSnn zerr(gettext("Could not launch: %s"), cmdbuf); 54049acbbeafSnn return (-1); 54059acbbeafSnn } 54069acbbeafSnn 54079acbbeafSnn while (fgets(inbuf, sizeof (inbuf), file) != NULL) 54089acbbeafSnn fprintf(stderr, "%s", inbuf); 54099acbbeafSnn status = pclose(file); 54109acbbeafSnn 54119acbbeafSnn if (WIFSIGNALED(status)) { 54129acbbeafSnn zerr(gettext("%s unexpectedly terminated due to signal %d"), 54139acbbeafSnn cmdbuf, WTERMSIG(status)); 54149acbbeafSnn return (-1); 54159acbbeafSnn } 54169acbbeafSnn assert(WIFEXITED(status)); 54179acbbeafSnn return (WEXITSTATUS(status)); 54189acbbeafSnn } 54199acbbeafSnn 54209acbbeafSnn static int 54219acbbeafSnn brand_verify(zone_dochandle_t handle) 54229acbbeafSnn { 54236e65f9afSnn char xml_file[32]; 54249acbbeafSnn char cmdbuf[MAX_CMD_LEN]; 5425123807fbSedp brand_handle_t bh; 54269acbbeafSnn char brand[MAXNAMELEN]; 54279acbbeafSnn int err; 54289acbbeafSnn 54299acbbeafSnn if (zonecfg_get_brand(handle, brand, sizeof (brand)) != Z_OK) { 54309acbbeafSnn zerr("%s: %s\n", zone, gettext("could not get zone brand")); 54319acbbeafSnn return (Z_INVALID_DOCUMENT); 54329acbbeafSnn } 5433123807fbSedp if ((bh = brand_open(brand)) == NULL) { 54349acbbeafSnn zerr("%s: %s\n", zone, gettext("unknown brand.")); 54359acbbeafSnn return (Z_INVALID_DOCUMENT); 54369acbbeafSnn } 54379acbbeafSnn 54389acbbeafSnn /* 54399acbbeafSnn * Fetch the verify command, if any, from the brand configuration 54409acbbeafSnn * and build the command line to execute it. 54419acbbeafSnn */ 54429acbbeafSnn strcpy(cmdbuf, EXEC_PREFIX); 5443123807fbSedp err = brand_get_verify_cfg(bh, cmdbuf + EXEC_LEN, 54449acbbeafSnn sizeof (cmdbuf) - (EXEC_LEN + (strlen(xml_file) + 1))); 5445123807fbSedp brand_close(bh); 54469acbbeafSnn if (err != Z_OK) { 54479acbbeafSnn zerr("%s: %s\n", zone, 54489acbbeafSnn gettext("could not get brand verification command")); 54499acbbeafSnn return (Z_INVALID_DOCUMENT); 54509acbbeafSnn } 54519acbbeafSnn 54529acbbeafSnn /* 54539acbbeafSnn * If the brand doesn't provide a verification routine, we just 54549acbbeafSnn * return success. 54559acbbeafSnn */ 54569acbbeafSnn if (strlen(cmdbuf) == EXEC_LEN) 54579acbbeafSnn return (Z_OK); 54589acbbeafSnn 54599acbbeafSnn /* 54609acbbeafSnn * Dump the current config information for this zone to a file. 54619acbbeafSnn */ 54626e65f9afSnn strcpy(xml_file, "/tmp/zonecfg_verify.XXXXXX"); 54639acbbeafSnn if (mkstemp(xml_file) == NULL) 54649acbbeafSnn return (Z_TEMP_FILE); 54659acbbeafSnn if ((err = zonecfg_verify_save(handle, xml_file)) != Z_OK) { 54669acbbeafSnn (void) unlink(xml_file); 54679acbbeafSnn return (err); 54689acbbeafSnn } 54699acbbeafSnn 54709acbbeafSnn /* 54719acbbeafSnn * Execute the verification command. 54729acbbeafSnn */ 54739acbbeafSnn if ((strlcat(cmdbuf, " ", MAX_CMD_LEN) >= MAX_CMD_LEN) || 54749acbbeafSnn (strlcat(cmdbuf, xml_file, MAX_CMD_LEN) >= MAX_CMD_LEN)) { 54759acbbeafSnn err = Z_BRAND_ERROR; 54769acbbeafSnn } else { 54779acbbeafSnn err = do_subproc(cmdbuf); 54789acbbeafSnn } 54799acbbeafSnn 54809acbbeafSnn (void) unlink(xml_file); 54819acbbeafSnn return ((err == Z_OK) ? Z_OK : Z_BRAND_ERROR); 54829acbbeafSnn } 54839acbbeafSnn 54847c478bd9Sstevel@tonic-gate /* 54857c478bd9Sstevel@tonic-gate * See the DTD for which attributes are required for which resources. 54867c478bd9Sstevel@tonic-gate * 54877c478bd9Sstevel@tonic-gate * This function can be called by commit_func(), which needs to save things, 54887c478bd9Sstevel@tonic-gate * in addition to the general call from parse_and_run(), which doesn't need 54897c478bd9Sstevel@tonic-gate * things saved. Since the parameters are standardized, we distinguish by 54907c478bd9Sstevel@tonic-gate * having commit_func() call here with cmd->cmd_arg set to "save" to indicate 54917c478bd9Sstevel@tonic-gate * that a save is needed. 54927c478bd9Sstevel@tonic-gate */ 54937c478bd9Sstevel@tonic-gate void 54947c478bd9Sstevel@tonic-gate verify_func(cmd_t *cmd) 54957c478bd9Sstevel@tonic-gate { 54967c478bd9Sstevel@tonic-gate struct zone_nwiftab nwiftab; 54977c478bd9Sstevel@tonic-gate struct zone_fstab fstab; 54987c478bd9Sstevel@tonic-gate struct zone_attrtab attrtab; 54997c478bd9Sstevel@tonic-gate struct zone_rctltab rctltab; 5500fa9e4066Sahrens struct zone_dstab dstab; 55010209230bSgjelinek struct zone_psettab psettab; 55027c478bd9Sstevel@tonic-gate char zonepath[MAXPATHLEN]; 55030209230bSgjelinek char sched[MAXNAMELEN]; 55049acbbeafSnn char brand[MAXNAMELEN]; 55055679c89fSjv char hostidp[HW_HOSTID_LEN]; 55067c478bd9Sstevel@tonic-gate int err, ret_val = Z_OK, arg; 5507c97ad5cdSakolb int pset_res; 5508bbec428eSgjelinek boolean_t save = B_FALSE; 5509bbec428eSgjelinek boolean_t arg_err = B_FALSE; 5510f4b3ec61Sdh zone_iptype_t iptype; 55110209230bSgjelinek boolean_t has_cpu_shares = B_FALSE; 5512c97ad5cdSakolb boolean_t has_cpu_cap = B_FALSE; 55137c478bd9Sstevel@tonic-gate 55147c478bd9Sstevel@tonic-gate optind = 0; 55157ec75eb8Sgjelinek while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?")) != EOF) { 55167c478bd9Sstevel@tonic-gate switch (arg) { 55177c478bd9Sstevel@tonic-gate case '?': 55187c478bd9Sstevel@tonic-gate longer_usage(CMD_VERIFY); 5519bbec428eSgjelinek arg_err = B_TRUE; 55207ec75eb8Sgjelinek break; 55217c478bd9Sstevel@tonic-gate default: 55227c478bd9Sstevel@tonic-gate short_usage(CMD_VERIFY); 5523bbec428eSgjelinek arg_err = B_TRUE; 55247ec75eb8Sgjelinek break; 55257c478bd9Sstevel@tonic-gate } 55267c478bd9Sstevel@tonic-gate } 55277ec75eb8Sgjelinek if (arg_err) 55287ec75eb8Sgjelinek return; 55297ec75eb8Sgjelinek 55307c478bd9Sstevel@tonic-gate if (optind > cmd->cmd_argc) { 55317c478bd9Sstevel@tonic-gate short_usage(CMD_VERIFY); 55327c478bd9Sstevel@tonic-gate return; 55337c478bd9Sstevel@tonic-gate } 55347c478bd9Sstevel@tonic-gate 55357c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_VERIFY)) 55367c478bd9Sstevel@tonic-gate return; 55377c478bd9Sstevel@tonic-gate 55387c478bd9Sstevel@tonic-gate assert(cmd != NULL); 55397c478bd9Sstevel@tonic-gate 55407c478bd9Sstevel@tonic-gate if (cmd->cmd_argc > 0 && (strcmp(cmd->cmd_argv[0], "save") == 0)) 5541bbec428eSgjelinek save = B_TRUE; 5542bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 55437c478bd9Sstevel@tonic-gate return; 55447c478bd9Sstevel@tonic-gate 55450209230bSgjelinek if (zonecfg_get_zonepath(handle, zonepath, sizeof (zonepath)) != Z_OK && 55460209230bSgjelinek !global_zone) { 5547087719fdSdp zerr(gettext("%s not specified"), pt_to_str(PT_ZONEPATH)); 55487c478bd9Sstevel@tonic-gate ret_val = Z_REQD_RESOURCE_MISSING; 5549bbec428eSgjelinek saw_error = B_TRUE; 55507c478bd9Sstevel@tonic-gate } 55510209230bSgjelinek if (strlen(zonepath) == 0 && !global_zone) { 5552087719fdSdp zerr(gettext("%s cannot be empty."), pt_to_str(PT_ZONEPATH)); 55537c478bd9Sstevel@tonic-gate ret_val = Z_REQD_RESOURCE_MISSING; 5554bbec428eSgjelinek saw_error = B_TRUE; 55557c478bd9Sstevel@tonic-gate } 55567c478bd9Sstevel@tonic-gate 55579acbbeafSnn if ((err = zonecfg_get_brand(handle, brand, sizeof (brand))) != Z_OK) { 5558bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 55599acbbeafSnn return; 55609acbbeafSnn } 5561a46da47fSEdward Pilatowicz if ((err = brand_verify(handle)) != Z_OK) { 5562a46da47fSEdward Pilatowicz zone_perror(zone, err, B_TRUE); 5563a46da47fSEdward Pilatowicz return; 55649acbbeafSnn } 55659acbbeafSnn 5566f4b3ec61Sdh if (zonecfg_get_iptype(handle, &iptype) != Z_OK) { 5567f4b3ec61Sdh zerr("%s %s", gettext("cannot get"), pt_to_str(PT_IPTYPE)); 5568f4b3ec61Sdh ret_val = Z_REQD_RESOURCE_MISSING; 5569bbec428eSgjelinek saw_error = B_TRUE; 5570f4b3ec61Sdh } 55717c478bd9Sstevel@tonic-gate if ((err = zonecfg_setipdent(handle)) != Z_OK) { 5572bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 55737c478bd9Sstevel@tonic-gate return; 55747c478bd9Sstevel@tonic-gate } 55757c478bd9Sstevel@tonic-gate while (zonecfg_getipdent(handle, &fstab) == Z_OK) { 5576087719fdSdp check_reqd_prop(fstab.zone_fs_dir, RT_IPD, PT_DIR, &ret_val); 55777c478bd9Sstevel@tonic-gate } 55787c478bd9Sstevel@tonic-gate (void) zonecfg_endipdent(handle); 55797c478bd9Sstevel@tonic-gate 55805679c89fSjv if (zonecfg_get_hostid(handle, hostidp, sizeof (hostidp)) == Z_OK && 55815679c89fSjv (err = zonecfg_valid_hostid(hostidp)) != Z_OK) { 55825679c89fSjv zone_perror(zone, err, B_TRUE); 55835679c89fSjv return; 55845679c89fSjv } 55855679c89fSjv 55867c478bd9Sstevel@tonic-gate if ((err = zonecfg_setfsent(handle)) != Z_OK) { 5587bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 55887c478bd9Sstevel@tonic-gate return; 55897c478bd9Sstevel@tonic-gate } 55907c478bd9Sstevel@tonic-gate while (zonecfg_getfsent(handle, &fstab) == Z_OK) { 5591087719fdSdp check_reqd_prop(fstab.zone_fs_dir, RT_FS, PT_DIR, &ret_val); 5592087719fdSdp check_reqd_prop(fstab.zone_fs_special, RT_FS, PT_SPECIAL, 5593087719fdSdp &ret_val); 5594087719fdSdp check_reqd_prop(fstab.zone_fs_type, RT_FS, PT_TYPE, &ret_val); 5595087719fdSdp 55967c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(fstab.zone_fs_options); 55977c478bd9Sstevel@tonic-gate } 55987c478bd9Sstevel@tonic-gate (void) zonecfg_endfsent(handle); 55997c478bd9Sstevel@tonic-gate 56007c478bd9Sstevel@tonic-gate if ((err = zonecfg_setnwifent(handle)) != Z_OK) { 5601bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 56027c478bd9Sstevel@tonic-gate return; 56037c478bd9Sstevel@tonic-gate } 56047c478bd9Sstevel@tonic-gate while (zonecfg_getnwifent(handle, &nwiftab) == Z_OK) { 5605f4b3ec61Sdh /* 5606f4b3ec61Sdh * physical is required in all cases. 5607de860bd9Sgfaden * A shared IP requires an address, 5608de860bd9Sgfaden * and may include a default router, while 5609de860bd9Sgfaden * an exclusive IP must have neither an address 5610de860bd9Sgfaden * nor a default router. 561101b4bc23Sjv * The physical interface name must be valid in all cases. 5612f4b3ec61Sdh */ 5613087719fdSdp check_reqd_prop(nwiftab.zone_nwif_physical, RT_NET, 5614087719fdSdp PT_PHYSICAL, &ret_val); 561501b4bc23Sjv if (validate_net_physical_syntax(nwiftab.zone_nwif_physical) != 561601b4bc23Sjv Z_OK) { 561701b4bc23Sjv saw_error = B_TRUE; 561801b4bc23Sjv if (ret_val == Z_OK) 561901b4bc23Sjv ret_val = Z_INVAL; 562001b4bc23Sjv } 5621f4b3ec61Sdh 5622f4b3ec61Sdh switch (iptype) { 5623f4b3ec61Sdh case ZS_SHARED: 5624f4b3ec61Sdh check_reqd_prop(nwiftab.zone_nwif_address, RT_NET, 5625f4b3ec61Sdh PT_ADDRESS, &ret_val); 5626f4b3ec61Sdh break; 5627f4b3ec61Sdh case ZS_EXCLUSIVE: 5628f4b3ec61Sdh if (strlen(nwiftab.zone_nwif_address) > 0) { 5629f4b3ec61Sdh zerr(gettext("%s: %s cannot be specified " 5630f4b3ec61Sdh "for an exclusive IP type"), 5631f4b3ec61Sdh rt_to_str(RT_NET), pt_to_str(PT_ADDRESS)); 5632bbec428eSgjelinek saw_error = B_TRUE; 5633f4b3ec61Sdh if (ret_val == Z_OK) 5634f4b3ec61Sdh ret_val = Z_INVAL; 5635f4b3ec61Sdh } 5636de860bd9Sgfaden if (strlen(nwiftab.zone_nwif_defrouter) > 0) { 5637de860bd9Sgfaden zerr(gettext("%s: %s cannot be specified " 5638de860bd9Sgfaden "for an exclusive IP type"), 5639de860bd9Sgfaden rt_to_str(RT_NET), pt_to_str(PT_DEFROUTER)); 5640bbec428eSgjelinek saw_error = B_TRUE; 5641de860bd9Sgfaden if (ret_val == Z_OK) 5642de860bd9Sgfaden ret_val = Z_INVAL; 5643de860bd9Sgfaden } 5644f4b3ec61Sdh break; 5645f4b3ec61Sdh } 56467c478bd9Sstevel@tonic-gate } 56477c478bd9Sstevel@tonic-gate (void) zonecfg_endnwifent(handle); 56487c478bd9Sstevel@tonic-gate 56497c478bd9Sstevel@tonic-gate if ((err = zonecfg_setrctlent(handle)) != Z_OK) { 5650bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 56517c478bd9Sstevel@tonic-gate return; 56527c478bd9Sstevel@tonic-gate } 56537c478bd9Sstevel@tonic-gate while (zonecfg_getrctlent(handle, &rctltab) == Z_OK) { 5654087719fdSdp check_reqd_prop(rctltab.zone_rctl_name, RT_RCTL, PT_NAME, 5655087719fdSdp &ret_val); 5656087719fdSdp 56570209230bSgjelinek if (strcmp(rctltab.zone_rctl_name, "zone.cpu-shares") == 0) 56580209230bSgjelinek has_cpu_shares = B_TRUE; 56590209230bSgjelinek 5660c97ad5cdSakolb if (strcmp(rctltab.zone_rctl_name, "zone.cpu-cap") == 0) 5661c97ad5cdSakolb has_cpu_cap = B_TRUE; 5662c97ad5cdSakolb 56637c478bd9Sstevel@tonic-gate if (rctltab.zone_rctl_valptr == NULL) { 56647c478bd9Sstevel@tonic-gate zerr(gettext("%s: no %s specified"), 56657c478bd9Sstevel@tonic-gate rt_to_str(RT_RCTL), pt_to_str(PT_VALUE)); 5666bbec428eSgjelinek saw_error = B_TRUE; 56677c478bd9Sstevel@tonic-gate if (ret_val == Z_OK) 56687c478bd9Sstevel@tonic-gate ret_val = Z_REQD_PROPERTY_MISSING; 56697c478bd9Sstevel@tonic-gate } else { 56707c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctltab.zone_rctl_valptr); 56717c478bd9Sstevel@tonic-gate } 56727c478bd9Sstevel@tonic-gate } 56737c478bd9Sstevel@tonic-gate (void) zonecfg_endrctlent(handle); 56747c478bd9Sstevel@tonic-gate 5675c97ad5cdSakolb if ((pset_res = zonecfg_lookup_pset(handle, &psettab)) == Z_OK && 5676c97ad5cdSakolb has_cpu_shares) { 56770209230bSgjelinek zerr(gettext("%s zone.cpu-shares and %s are incompatible."), 56780209230bSgjelinek rt_to_str(RT_RCTL), rt_to_str(RT_DCPU)); 5679bbec428eSgjelinek saw_error = B_TRUE; 56800209230bSgjelinek if (ret_val == Z_OK) 56810209230bSgjelinek ret_val = Z_INCOMPATIBLE; 56820209230bSgjelinek } 56830209230bSgjelinek 56840209230bSgjelinek if (has_cpu_shares && zonecfg_get_sched_class(handle, sched, 56850209230bSgjelinek sizeof (sched)) == Z_OK && strlen(sched) > 0 && 56860209230bSgjelinek strcmp(sched, "FSS") != 0) { 56870209230bSgjelinek zerr(gettext("WARNING: %s zone.cpu-shares and %s=%s are " 56880209230bSgjelinek "incompatible"), 56890209230bSgjelinek rt_to_str(RT_RCTL), rt_to_str(RT_SCHED), sched); 5690bbec428eSgjelinek saw_error = B_TRUE; 56910209230bSgjelinek if (ret_val == Z_OK) 56920209230bSgjelinek ret_val = Z_INCOMPATIBLE; 56930209230bSgjelinek } 56940209230bSgjelinek 5695c97ad5cdSakolb if (pset_res == Z_OK && has_cpu_cap) { 5696c97ad5cdSakolb zerr(gettext("%s zone.cpu-cap and the %s are incompatible."), 5697c97ad5cdSakolb rt_to_str(RT_RCTL), rt_to_str(RT_DCPU)); 5698bbec428eSgjelinek saw_error = B_TRUE; 5699c97ad5cdSakolb if (ret_val == Z_OK) 5700c97ad5cdSakolb ret_val = Z_INCOMPATIBLE; 5701c97ad5cdSakolb } 5702c97ad5cdSakolb 57037c478bd9Sstevel@tonic-gate if ((err = zonecfg_setattrent(handle)) != Z_OK) { 5704bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 57057c478bd9Sstevel@tonic-gate return; 57067c478bd9Sstevel@tonic-gate } 57077c478bd9Sstevel@tonic-gate while (zonecfg_getattrent(handle, &attrtab) == Z_OK) { 5708087719fdSdp check_reqd_prop(attrtab.zone_attr_name, RT_ATTR, PT_NAME, 5709087719fdSdp &ret_val); 5710087719fdSdp check_reqd_prop(attrtab.zone_attr_type, RT_ATTR, PT_TYPE, 5711087719fdSdp &ret_val); 5712087719fdSdp check_reqd_prop(attrtab.zone_attr_value, RT_ATTR, PT_VALUE, 5713087719fdSdp &ret_val); 57147c478bd9Sstevel@tonic-gate } 57157c478bd9Sstevel@tonic-gate (void) zonecfg_endattrent(handle); 57167c478bd9Sstevel@tonic-gate 5717fa9e4066Sahrens if ((err = zonecfg_setdsent(handle)) != Z_OK) { 5718bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 5719fa9e4066Sahrens return; 5720fa9e4066Sahrens } 5721fa9e4066Sahrens while (zonecfg_getdsent(handle, &dstab) == Z_OK) { 5722fa9e4066Sahrens if (strlen(dstab.zone_dataset_name) == 0) { 5723fa9e4066Sahrens zerr("%s: %s %s", rt_to_str(RT_DATASET), 5724fa9e4066Sahrens pt_to_str(PT_NAME), gettext("not specified")); 5725bbec428eSgjelinek saw_error = B_TRUE; 5726fa9e4066Sahrens if (ret_val == Z_OK) 5727fa9e4066Sahrens ret_val = Z_REQD_PROPERTY_MISSING; 5728fa9e4066Sahrens } else if (!zfs_name_valid(dstab.zone_dataset_name, 5729fa9e4066Sahrens ZFS_TYPE_FILESYSTEM)) { 5730fa9e4066Sahrens zerr("%s: %s %s", rt_to_str(RT_DATASET), 5731fa9e4066Sahrens pt_to_str(PT_NAME), gettext("invalid")); 5732bbec428eSgjelinek saw_error = B_TRUE; 5733fa9e4066Sahrens if (ret_val == Z_OK) 5734fa9e4066Sahrens ret_val = Z_BAD_PROPERTY; 5735fa9e4066Sahrens } 5736fa9e4066Sahrens 5737fa9e4066Sahrens } 5738fa9e4066Sahrens (void) zonecfg_enddsent(handle); 5739fa9e4066Sahrens 57407c478bd9Sstevel@tonic-gate if (!global_scope) { 57417c478bd9Sstevel@tonic-gate zerr(gettext("resource specification incomplete")); 5742bbec428eSgjelinek saw_error = B_TRUE; 57437c478bd9Sstevel@tonic-gate if (ret_val == Z_OK) 57447c478bd9Sstevel@tonic-gate ret_val = Z_INSUFFICIENT_SPEC; 57457c478bd9Sstevel@tonic-gate } 57467c478bd9Sstevel@tonic-gate 57477c478bd9Sstevel@tonic-gate if (save) { 5748087719fdSdp if (ret_val == Z_OK) { 5749087719fdSdp if ((ret_val = zonecfg_save(handle)) == Z_OK) { 5750bbec428eSgjelinek need_to_commit = B_FALSE; 5751087719fdSdp (void) strlcpy(revert_zone, zone, 5752087719fdSdp sizeof (revert_zone)); 5753087719fdSdp } 5754087719fdSdp } else { 5755087719fdSdp zerr(gettext("Zone %s failed to verify"), zone); 5756087719fdSdp } 57577c478bd9Sstevel@tonic-gate } 57587c478bd9Sstevel@tonic-gate if (ret_val != Z_OK) 5759bbec428eSgjelinek zone_perror(zone, ret_val, B_TRUE); 57607c478bd9Sstevel@tonic-gate } 57617c478bd9Sstevel@tonic-gate 57627c478bd9Sstevel@tonic-gate void 57637c478bd9Sstevel@tonic-gate cancel_func(cmd_t *cmd) 57647c478bd9Sstevel@tonic-gate { 57657c478bd9Sstevel@tonic-gate int arg; 5766bbec428eSgjelinek boolean_t arg_err = B_FALSE; 57677c478bd9Sstevel@tonic-gate 57687c478bd9Sstevel@tonic-gate assert(cmd != NULL); 57697c478bd9Sstevel@tonic-gate 57707c478bd9Sstevel@tonic-gate optind = 0; 57717ec75eb8Sgjelinek while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?")) != EOF) { 57727c478bd9Sstevel@tonic-gate switch (arg) { 57737c478bd9Sstevel@tonic-gate case '?': 57747c478bd9Sstevel@tonic-gate longer_usage(CMD_CANCEL); 5775bbec428eSgjelinek arg_err = B_TRUE; 57767ec75eb8Sgjelinek break; 57777c478bd9Sstevel@tonic-gate default: 57787c478bd9Sstevel@tonic-gate short_usage(CMD_CANCEL); 5779bbec428eSgjelinek arg_err = B_TRUE; 57807ec75eb8Sgjelinek break; 57817c478bd9Sstevel@tonic-gate } 57827c478bd9Sstevel@tonic-gate } 57837ec75eb8Sgjelinek if (arg_err) 57847ec75eb8Sgjelinek return; 57857ec75eb8Sgjelinek 57867c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 57877c478bd9Sstevel@tonic-gate short_usage(CMD_CANCEL); 57887c478bd9Sstevel@tonic-gate return; 57897c478bd9Sstevel@tonic-gate } 57907c478bd9Sstevel@tonic-gate 57917c478bd9Sstevel@tonic-gate if (global_scope) 57927c478bd9Sstevel@tonic-gate scope_usage(CMD_CANCEL); 5793bbec428eSgjelinek global_scope = B_TRUE; 57947c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(in_progress_fstab.zone_fs_options); 57957c478bd9Sstevel@tonic-gate bzero(&in_progress_fstab, sizeof (in_progress_fstab)); 57967c478bd9Sstevel@tonic-gate bzero(&in_progress_nwiftab, sizeof (in_progress_nwiftab)); 5797fa9e4066Sahrens bzero(&in_progress_ipdtab, sizeof (in_progress_ipdtab)); 57987c478bd9Sstevel@tonic-gate bzero(&in_progress_devtab, sizeof (in_progress_devtab)); 57997c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(in_progress_rctltab.zone_rctl_valptr); 58007c478bd9Sstevel@tonic-gate bzero(&in_progress_rctltab, sizeof (in_progress_rctltab)); 58017c478bd9Sstevel@tonic-gate bzero(&in_progress_attrtab, sizeof (in_progress_attrtab)); 5802fa9e4066Sahrens bzero(&in_progress_dstab, sizeof (in_progress_dstab)); 58037c478bd9Sstevel@tonic-gate } 58047c478bd9Sstevel@tonic-gate 58057c478bd9Sstevel@tonic-gate static int 58067c478bd9Sstevel@tonic-gate validate_attr_name(char *name) 58077c478bd9Sstevel@tonic-gate { 58087c478bd9Sstevel@tonic-gate int i; 58097c478bd9Sstevel@tonic-gate 58107c478bd9Sstevel@tonic-gate if (!isalnum(name[0])) { 58117c478bd9Sstevel@tonic-gate zerr(gettext("Invalid %s %s %s: must start with an alpha-" 58127c478bd9Sstevel@tonic-gate "numeric character."), rt_to_str(RT_ATTR), 58137c478bd9Sstevel@tonic-gate pt_to_str(PT_NAME), name); 58147c478bd9Sstevel@tonic-gate return (Z_INVAL); 58157c478bd9Sstevel@tonic-gate } 58167c478bd9Sstevel@tonic-gate for (i = 1; name[i]; i++) 58177c478bd9Sstevel@tonic-gate if (!isalnum(name[i]) && name[i] != '-' && name[i] != '.') { 58187c478bd9Sstevel@tonic-gate zerr(gettext("Invalid %s %s %s: can only contain " 58197c478bd9Sstevel@tonic-gate "alpha-numeric characters, plus '-' and '.'."), 58207c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_NAME), name); 58217c478bd9Sstevel@tonic-gate return (Z_INVAL); 58227c478bd9Sstevel@tonic-gate } 58237c478bd9Sstevel@tonic-gate return (Z_OK); 58247c478bd9Sstevel@tonic-gate } 58257c478bd9Sstevel@tonic-gate 58267c478bd9Sstevel@tonic-gate static int 58277c478bd9Sstevel@tonic-gate validate_attr_type_val(struct zone_attrtab *attrtab) 58287c478bd9Sstevel@tonic-gate { 58297c478bd9Sstevel@tonic-gate boolean_t boolval; 58307c478bd9Sstevel@tonic-gate int64_t intval; 58317c478bd9Sstevel@tonic-gate char strval[MAXNAMELEN]; 58327c478bd9Sstevel@tonic-gate uint64_t uintval; 58337c478bd9Sstevel@tonic-gate 58347c478bd9Sstevel@tonic-gate if (strcmp(attrtab->zone_attr_type, "boolean") == 0) { 58357c478bd9Sstevel@tonic-gate if (zonecfg_get_attr_boolean(attrtab, &boolval) == Z_OK) 58367c478bd9Sstevel@tonic-gate return (Z_OK); 58377c478bd9Sstevel@tonic-gate zerr(gettext("invalid %s value for %s=%s"), 58387c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_TYPE), "boolean"); 58397c478bd9Sstevel@tonic-gate return (Z_ERR); 58407c478bd9Sstevel@tonic-gate } 58417c478bd9Sstevel@tonic-gate 58427c478bd9Sstevel@tonic-gate if (strcmp(attrtab->zone_attr_type, "int") == 0) { 58437c478bd9Sstevel@tonic-gate if (zonecfg_get_attr_int(attrtab, &intval) == Z_OK) 58447c478bd9Sstevel@tonic-gate return (Z_OK); 58457c478bd9Sstevel@tonic-gate zerr(gettext("invalid %s value for %s=%s"), 58467c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_TYPE), "int"); 58477c478bd9Sstevel@tonic-gate return (Z_ERR); 58487c478bd9Sstevel@tonic-gate } 58497c478bd9Sstevel@tonic-gate 58507c478bd9Sstevel@tonic-gate if (strcmp(attrtab->zone_attr_type, "string") == 0) { 58517c478bd9Sstevel@tonic-gate if (zonecfg_get_attr_string(attrtab, strval, 58527c478bd9Sstevel@tonic-gate sizeof (strval)) == Z_OK) 58537c478bd9Sstevel@tonic-gate return (Z_OK); 58547c478bd9Sstevel@tonic-gate zerr(gettext("invalid %s value for %s=%s"), 58557c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_TYPE), "string"); 58567c478bd9Sstevel@tonic-gate return (Z_ERR); 58577c478bd9Sstevel@tonic-gate } 58587c478bd9Sstevel@tonic-gate 58597c478bd9Sstevel@tonic-gate if (strcmp(attrtab->zone_attr_type, "uint") == 0) { 58607c478bd9Sstevel@tonic-gate if (zonecfg_get_attr_uint(attrtab, &uintval) == Z_OK) 58617c478bd9Sstevel@tonic-gate return (Z_OK); 58627c478bd9Sstevel@tonic-gate zerr(gettext("invalid %s value for %s=%s"), 58637c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_TYPE), "uint"); 58647c478bd9Sstevel@tonic-gate return (Z_ERR); 58657c478bd9Sstevel@tonic-gate } 58667c478bd9Sstevel@tonic-gate 58677c478bd9Sstevel@tonic-gate zerr(gettext("invalid %s %s '%s'"), rt_to_str(RT_ATTR), 58687c478bd9Sstevel@tonic-gate pt_to_str(PT_TYPE), attrtab->zone_attr_type); 58697c478bd9Sstevel@tonic-gate return (Z_ERR); 58707c478bd9Sstevel@tonic-gate } 58717c478bd9Sstevel@tonic-gate 5872087719fdSdp /* 5873087719fdSdp * Helper function for end_func-- checks the existence of a given property 5874087719fdSdp * and emits a message if not specified. 5875087719fdSdp */ 5876087719fdSdp static int 5877bbec428eSgjelinek end_check_reqd(char *attr, int pt, boolean_t *validation_failed) 5878087719fdSdp { 5879087719fdSdp if (strlen(attr) == 0) { 5880bbec428eSgjelinek *validation_failed = B_TRUE; 5881087719fdSdp zerr(gettext("%s not specified"), pt_to_str(pt)); 5882087719fdSdp return (Z_ERR); 5883087719fdSdp } 5884087719fdSdp return (Z_OK); 5885087719fdSdp } 5886087719fdSdp 58877c478bd9Sstevel@tonic-gate void 58887c478bd9Sstevel@tonic-gate end_func(cmd_t *cmd) 58897c478bd9Sstevel@tonic-gate { 5890bbec428eSgjelinek boolean_t validation_failed = B_FALSE; 5891bbec428eSgjelinek boolean_t arg_err = B_FALSE; 58927c478bd9Sstevel@tonic-gate struct zone_fstab tmp_fstab; 58937c478bd9Sstevel@tonic-gate struct zone_nwiftab tmp_nwiftab; 58947c478bd9Sstevel@tonic-gate struct zone_devtab tmp_devtab; 58957c478bd9Sstevel@tonic-gate struct zone_rctltab tmp_rctltab; 58967c478bd9Sstevel@tonic-gate struct zone_attrtab tmp_attrtab; 5897fa9e4066Sahrens struct zone_dstab tmp_dstab; 58980209230bSgjelinek int err, arg, res1, res2, res3; 58990209230bSgjelinek uint64_t swap_limit; 59000209230bSgjelinek uint64_t locked_limit; 5901c97ad5cdSakolb uint64_t proc_cap; 59027c478bd9Sstevel@tonic-gate 59037c478bd9Sstevel@tonic-gate assert(cmd != NULL); 59047c478bd9Sstevel@tonic-gate 59057c478bd9Sstevel@tonic-gate optind = 0; 59067ec75eb8Sgjelinek while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?")) != EOF) { 59077c478bd9Sstevel@tonic-gate switch (arg) { 59087c478bd9Sstevel@tonic-gate case '?': 59097c478bd9Sstevel@tonic-gate longer_usage(CMD_END); 5910bbec428eSgjelinek arg_err = B_TRUE; 59117ec75eb8Sgjelinek break; 59127c478bd9Sstevel@tonic-gate default: 59137c478bd9Sstevel@tonic-gate short_usage(CMD_END); 5914bbec428eSgjelinek arg_err = B_TRUE; 59157ec75eb8Sgjelinek break; 59167c478bd9Sstevel@tonic-gate } 59177c478bd9Sstevel@tonic-gate } 59187ec75eb8Sgjelinek if (arg_err) 59197ec75eb8Sgjelinek return; 59207ec75eb8Sgjelinek 59217c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 59227c478bd9Sstevel@tonic-gate short_usage(CMD_END); 59237c478bd9Sstevel@tonic-gate return; 59247c478bd9Sstevel@tonic-gate } 59257c478bd9Sstevel@tonic-gate 59267c478bd9Sstevel@tonic-gate if (global_scope) { 59277c478bd9Sstevel@tonic-gate scope_usage(CMD_END); 59287c478bd9Sstevel@tonic-gate return; 59297c478bd9Sstevel@tonic-gate } 59307c478bd9Sstevel@tonic-gate 59317c478bd9Sstevel@tonic-gate assert(end_op == CMD_ADD || end_op == CMD_SELECT); 59327c478bd9Sstevel@tonic-gate 59337c478bd9Sstevel@tonic-gate switch (resource_scope) { 59347c478bd9Sstevel@tonic-gate case RT_FS: 59357c478bd9Sstevel@tonic-gate /* First make sure everything was filled in. */ 5936087719fdSdp if (end_check_reqd(in_progress_fstab.zone_fs_dir, 5937087719fdSdp PT_DIR, &validation_failed) == Z_OK) { 5938087719fdSdp if (in_progress_fstab.zone_fs_dir[0] != '/') { 5939087719fdSdp zerr(gettext("%s %s is not an absolute path."), 5940087719fdSdp pt_to_str(PT_DIR), 5941087719fdSdp in_progress_fstab.zone_fs_dir); 5942bbec428eSgjelinek validation_failed = B_TRUE; 5943087719fdSdp } 59447c478bd9Sstevel@tonic-gate } 5945087719fdSdp 5946087719fdSdp (void) end_check_reqd(in_progress_fstab.zone_fs_special, 5947087719fdSdp PT_SPECIAL, &validation_failed); 5948087719fdSdp 59497c478bd9Sstevel@tonic-gate if (in_progress_fstab.zone_fs_raw[0] != '\0' && 59507c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_raw[0] != '/') { 5951087719fdSdp zerr(gettext("%s %s is not an absolute path."), 5952087719fdSdp pt_to_str(PT_RAW), 5953087719fdSdp in_progress_fstab.zone_fs_raw); 5954bbec428eSgjelinek validation_failed = B_TRUE; 59557c478bd9Sstevel@tonic-gate } 5956087719fdSdp 5957087719fdSdp (void) end_check_reqd(in_progress_fstab.zone_fs_type, PT_TYPE, 5958087719fdSdp &validation_failed); 5959087719fdSdp 5960087719fdSdp if (validation_failed) { 5961bbec428eSgjelinek saw_error = B_TRUE; 59627c478bd9Sstevel@tonic-gate return; 5963087719fdSdp } 5964087719fdSdp 59657c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) { 59667c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */ 59677c478bd9Sstevel@tonic-gate bzero(&tmp_fstab, sizeof (tmp_fstab)); 59687c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_fstab.zone_fs_dir, 59697c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_dir, 59707c478bd9Sstevel@tonic-gate sizeof (tmp_fstab.zone_fs_dir)); 59717c478bd9Sstevel@tonic-gate err = zonecfg_lookup_filesystem(handle, &tmp_fstab); 59727c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(tmp_fstab.zone_fs_options); 59737c478bd9Sstevel@tonic-gate if (err == Z_OK) { 59747c478bd9Sstevel@tonic-gate zerr(gettext("A %s resource " 59757c478bd9Sstevel@tonic-gate "with the %s '%s' already exists."), 59767c478bd9Sstevel@tonic-gate rt_to_str(RT_FS), pt_to_str(PT_DIR), 59777c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_dir); 5978bbec428eSgjelinek saw_error = B_TRUE; 59797c478bd9Sstevel@tonic-gate return; 59807c478bd9Sstevel@tonic-gate } 59817c478bd9Sstevel@tonic-gate err = zonecfg_add_filesystem(handle, 59827c478bd9Sstevel@tonic-gate &in_progress_fstab); 59837c478bd9Sstevel@tonic-gate } else { 59847c478bd9Sstevel@tonic-gate err = zonecfg_modify_filesystem(handle, &old_fstab, 59857c478bd9Sstevel@tonic-gate &in_progress_fstab); 59867c478bd9Sstevel@tonic-gate } 59877c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(in_progress_fstab.zone_fs_options); 59887c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_options = NULL; 59897c478bd9Sstevel@tonic-gate break; 5990087719fdSdp 59917c478bd9Sstevel@tonic-gate case RT_IPD: 59927c478bd9Sstevel@tonic-gate /* First make sure everything was filled in. */ 5993087719fdSdp if (end_check_reqd(in_progress_ipdtab.zone_fs_dir, PT_DIR, 5994087719fdSdp &validation_failed) == Z_OK) { 5995087719fdSdp if (in_progress_ipdtab.zone_fs_dir[0] != '/') { 5996087719fdSdp zerr(gettext("%s %s is not an absolute path."), 5997087719fdSdp pt_to_str(PT_DIR), 5998087719fdSdp in_progress_ipdtab.zone_fs_dir); 5999bbec428eSgjelinek validation_failed = B_TRUE; 6000087719fdSdp } 60017c478bd9Sstevel@tonic-gate } 6002087719fdSdp if (validation_failed) { 6003bbec428eSgjelinek saw_error = B_TRUE; 60047c478bd9Sstevel@tonic-gate return; 6005087719fdSdp } 6006087719fdSdp 60077c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) { 60087c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */ 60097c478bd9Sstevel@tonic-gate bzero(&tmp_fstab, sizeof (tmp_fstab)); 60107c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_fstab.zone_fs_dir, 60117c478bd9Sstevel@tonic-gate in_progress_ipdtab.zone_fs_dir, 60127c478bd9Sstevel@tonic-gate sizeof (tmp_fstab.zone_fs_dir)); 60137c478bd9Sstevel@tonic-gate err = zonecfg_lookup_ipd(handle, &tmp_fstab); 60147c478bd9Sstevel@tonic-gate if (err == Z_OK) { 60157c478bd9Sstevel@tonic-gate zerr(gettext("An %s resource " 60167c478bd9Sstevel@tonic-gate "with the %s '%s' already exists."), 60177c478bd9Sstevel@tonic-gate rt_to_str(RT_IPD), pt_to_str(PT_DIR), 60187c478bd9Sstevel@tonic-gate in_progress_ipdtab.zone_fs_dir); 6019bbec428eSgjelinek saw_error = B_TRUE; 60207c478bd9Sstevel@tonic-gate return; 60217c478bd9Sstevel@tonic-gate } 60227c478bd9Sstevel@tonic-gate err = zonecfg_add_ipd(handle, &in_progress_ipdtab); 60237c478bd9Sstevel@tonic-gate } else { 60247c478bd9Sstevel@tonic-gate err = zonecfg_modify_ipd(handle, &old_ipdtab, 60257c478bd9Sstevel@tonic-gate &in_progress_ipdtab); 60267c478bd9Sstevel@tonic-gate } 60277c478bd9Sstevel@tonic-gate break; 60287c478bd9Sstevel@tonic-gate case RT_NET: 6029f4b3ec61Sdh /* 6030f4b3ec61Sdh * First make sure everything was filled in. 6031f4b3ec61Sdh * Since we don't know whether IP will be shared 6032f4b3ec61Sdh * or exclusive here, some checks are deferred until 6033f4b3ec61Sdh * the verify command. 6034f4b3ec61Sdh */ 6035087719fdSdp (void) end_check_reqd(in_progress_nwiftab.zone_nwif_physical, 6036087719fdSdp PT_PHYSICAL, &validation_failed); 6037087719fdSdp 6038087719fdSdp if (validation_failed) { 6039bbec428eSgjelinek saw_error = B_TRUE; 60407c478bd9Sstevel@tonic-gate return; 6041087719fdSdp } 60427c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) { 60437c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */ 60447c478bd9Sstevel@tonic-gate bzero(&tmp_nwiftab, sizeof (tmp_nwiftab)); 6045f4b3ec61Sdh (void) strlcpy(tmp_nwiftab.zone_nwif_physical, 6046f4b3ec61Sdh in_progress_nwiftab.zone_nwif_physical, 6047f4b3ec61Sdh sizeof (tmp_nwiftab.zone_nwif_physical)); 60487c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_nwiftab.zone_nwif_address, 60497c478bd9Sstevel@tonic-gate in_progress_nwiftab.zone_nwif_address, 60507c478bd9Sstevel@tonic-gate sizeof (tmp_nwiftab.zone_nwif_address)); 60517c478bd9Sstevel@tonic-gate if (zonecfg_lookup_nwif(handle, &tmp_nwiftab) == Z_OK) { 6052f4b3ec61Sdh zerr(gettext("A %s resource with the %s '%s', " 6053f4b3ec61Sdh "and %s '%s' already exists."), 6054f4b3ec61Sdh rt_to_str(RT_NET), 6055f4b3ec61Sdh pt_to_str(PT_PHYSICAL), 6056f4b3ec61Sdh in_progress_nwiftab.zone_nwif_physical, 6057f4b3ec61Sdh pt_to_str(PT_ADDRESS), 60587c478bd9Sstevel@tonic-gate in_progress_nwiftab.zone_nwif_address); 6059bbec428eSgjelinek saw_error = B_TRUE; 60607c478bd9Sstevel@tonic-gate return; 60617c478bd9Sstevel@tonic-gate } 60627c478bd9Sstevel@tonic-gate err = zonecfg_add_nwif(handle, &in_progress_nwiftab); 60637c478bd9Sstevel@tonic-gate } else { 60647c478bd9Sstevel@tonic-gate err = zonecfg_modify_nwif(handle, &old_nwiftab, 60657c478bd9Sstevel@tonic-gate &in_progress_nwiftab); 60667c478bd9Sstevel@tonic-gate } 60677c478bd9Sstevel@tonic-gate break; 6068087719fdSdp 60697c478bd9Sstevel@tonic-gate case RT_DEVICE: 60707c478bd9Sstevel@tonic-gate /* First make sure everything was filled in. */ 6071087719fdSdp (void) end_check_reqd(in_progress_devtab.zone_dev_match, 6072087719fdSdp PT_MATCH, &validation_failed); 6073087719fdSdp 6074087719fdSdp if (validation_failed) { 6075bbec428eSgjelinek saw_error = B_TRUE; 60767c478bd9Sstevel@tonic-gate return; 6077087719fdSdp } 6078087719fdSdp 60797c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) { 60807c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */ 60817c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_devtab.zone_dev_match, 60827c478bd9Sstevel@tonic-gate in_progress_devtab.zone_dev_match, 60837c478bd9Sstevel@tonic-gate sizeof (tmp_devtab.zone_dev_match)); 60847c478bd9Sstevel@tonic-gate if (zonecfg_lookup_dev(handle, &tmp_devtab) == Z_OK) { 60857c478bd9Sstevel@tonic-gate zerr(gettext("A %s resource with the %s '%s' " 60867c478bd9Sstevel@tonic-gate "already exists."), rt_to_str(RT_DEVICE), 60877c478bd9Sstevel@tonic-gate pt_to_str(PT_MATCH), 60887c478bd9Sstevel@tonic-gate in_progress_devtab.zone_dev_match); 6089bbec428eSgjelinek saw_error = B_TRUE; 60907c478bd9Sstevel@tonic-gate return; 60917c478bd9Sstevel@tonic-gate } 60927c478bd9Sstevel@tonic-gate err = zonecfg_add_dev(handle, &in_progress_devtab); 60937c478bd9Sstevel@tonic-gate } else { 60947c478bd9Sstevel@tonic-gate err = zonecfg_modify_dev(handle, &old_devtab, 60957c478bd9Sstevel@tonic-gate &in_progress_devtab); 60967c478bd9Sstevel@tonic-gate } 60977c478bd9Sstevel@tonic-gate break; 6098087719fdSdp 60997c478bd9Sstevel@tonic-gate case RT_RCTL: 61007c478bd9Sstevel@tonic-gate /* First make sure everything was filled in. */ 6101087719fdSdp (void) end_check_reqd(in_progress_rctltab.zone_rctl_name, 6102087719fdSdp PT_NAME, &validation_failed); 6103087719fdSdp 61047c478bd9Sstevel@tonic-gate if (in_progress_rctltab.zone_rctl_valptr == NULL) { 61057c478bd9Sstevel@tonic-gate zerr(gettext("no %s specified"), pt_to_str(PT_VALUE)); 6106bbec428eSgjelinek validation_failed = B_TRUE; 61077c478bd9Sstevel@tonic-gate } 6108087719fdSdp 6109087719fdSdp if (validation_failed) { 6110bbec428eSgjelinek saw_error = B_TRUE; 61117c478bd9Sstevel@tonic-gate return; 6112087719fdSdp } 6113087719fdSdp 61147c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) { 61157c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */ 61167c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_rctltab.zone_rctl_name, 61177c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_name, 61187c478bd9Sstevel@tonic-gate sizeof (tmp_rctltab.zone_rctl_name)); 61197c478bd9Sstevel@tonic-gate tmp_rctltab.zone_rctl_valptr = NULL; 61207c478bd9Sstevel@tonic-gate err = zonecfg_lookup_rctl(handle, &tmp_rctltab); 61217c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list( 61227c478bd9Sstevel@tonic-gate tmp_rctltab.zone_rctl_valptr); 61237c478bd9Sstevel@tonic-gate if (err == Z_OK) { 61247c478bd9Sstevel@tonic-gate zerr(gettext("A %s resource " 61257c478bd9Sstevel@tonic-gate "with the %s '%s' already exists."), 61267c478bd9Sstevel@tonic-gate rt_to_str(RT_RCTL), pt_to_str(PT_NAME), 61277c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_name); 6128bbec428eSgjelinek saw_error = B_TRUE; 61297c478bd9Sstevel@tonic-gate return; 61307c478bd9Sstevel@tonic-gate } 61317c478bd9Sstevel@tonic-gate err = zonecfg_add_rctl(handle, &in_progress_rctltab); 61327c478bd9Sstevel@tonic-gate } else { 61337c478bd9Sstevel@tonic-gate err = zonecfg_modify_rctl(handle, &old_rctltab, 61347c478bd9Sstevel@tonic-gate &in_progress_rctltab); 61357c478bd9Sstevel@tonic-gate } 61367c478bd9Sstevel@tonic-gate if (err == Z_OK) { 61377c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list( 61387c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_valptr); 61397c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_valptr = NULL; 61407c478bd9Sstevel@tonic-gate } 61417c478bd9Sstevel@tonic-gate break; 6142087719fdSdp 61437c478bd9Sstevel@tonic-gate case RT_ATTR: 61447c478bd9Sstevel@tonic-gate /* First make sure everything was filled in. */ 6145087719fdSdp (void) end_check_reqd(in_progress_attrtab.zone_attr_name, 6146087719fdSdp PT_NAME, &validation_failed); 6147087719fdSdp (void) end_check_reqd(in_progress_attrtab.zone_attr_type, 6148087719fdSdp PT_TYPE, &validation_failed); 6149087719fdSdp (void) end_check_reqd(in_progress_attrtab.zone_attr_value, 6150087719fdSdp PT_VALUE, &validation_failed); 6151087719fdSdp 61527c478bd9Sstevel@tonic-gate if (validate_attr_name(in_progress_attrtab.zone_attr_name) != 6153087719fdSdp Z_OK) 6154bbec428eSgjelinek validation_failed = B_TRUE; 6155087719fdSdp 6156087719fdSdp if (validate_attr_type_val(&in_progress_attrtab) != Z_OK) 6157bbec428eSgjelinek validation_failed = B_TRUE; 6158087719fdSdp 6159087719fdSdp if (validation_failed) { 6160bbec428eSgjelinek saw_error = B_TRUE; 61617c478bd9Sstevel@tonic-gate return; 6162087719fdSdp } 61637c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) { 61647c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */ 61657c478bd9Sstevel@tonic-gate bzero(&tmp_attrtab, sizeof (tmp_attrtab)); 61667c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_attrtab.zone_attr_name, 61677c478bd9Sstevel@tonic-gate in_progress_attrtab.zone_attr_name, 61687c478bd9Sstevel@tonic-gate sizeof (tmp_attrtab.zone_attr_name)); 61697c478bd9Sstevel@tonic-gate if (zonecfg_lookup_attr(handle, &tmp_attrtab) == Z_OK) { 61707c478bd9Sstevel@tonic-gate zerr(gettext("An %s resource " 61717c478bd9Sstevel@tonic-gate "with the %s '%s' already exists."), 61727c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_NAME), 61737c478bd9Sstevel@tonic-gate in_progress_attrtab.zone_attr_name); 6174bbec428eSgjelinek saw_error = B_TRUE; 61757c478bd9Sstevel@tonic-gate return; 61767c478bd9Sstevel@tonic-gate } 61777c478bd9Sstevel@tonic-gate err = zonecfg_add_attr(handle, &in_progress_attrtab); 61787c478bd9Sstevel@tonic-gate } else { 61797c478bd9Sstevel@tonic-gate err = zonecfg_modify_attr(handle, &old_attrtab, 61807c478bd9Sstevel@tonic-gate &in_progress_attrtab); 61817c478bd9Sstevel@tonic-gate } 61827c478bd9Sstevel@tonic-gate break; 6183fa9e4066Sahrens case RT_DATASET: 6184fa9e4066Sahrens /* First make sure everything was filled in. */ 6185fa9e4066Sahrens if (strlen(in_progress_dstab.zone_dataset_name) == 0) { 6186fa9e4066Sahrens zerr("%s %s", pt_to_str(PT_NAME), 6187fa9e4066Sahrens gettext("not specified")); 6188bbec428eSgjelinek saw_error = B_TRUE; 6189bbec428eSgjelinek validation_failed = B_TRUE; 6190fa9e4066Sahrens } 6191fa9e4066Sahrens if (validation_failed) 6192fa9e4066Sahrens return; 6193fa9e4066Sahrens if (end_op == CMD_ADD) { 6194fa9e4066Sahrens /* Make sure there isn't already one like this. */ 6195fa9e4066Sahrens bzero(&tmp_dstab, sizeof (tmp_dstab)); 6196fa9e4066Sahrens (void) strlcpy(tmp_dstab.zone_dataset_name, 6197fa9e4066Sahrens in_progress_dstab.zone_dataset_name, 6198fa9e4066Sahrens sizeof (tmp_dstab.zone_dataset_name)); 6199fa9e4066Sahrens err = zonecfg_lookup_ds(handle, &tmp_dstab); 6200fa9e4066Sahrens if (err == Z_OK) { 6201fa9e4066Sahrens zerr(gettext("A %s resource " 6202fa9e4066Sahrens "with the %s '%s' already exists."), 6203fa9e4066Sahrens rt_to_str(RT_DATASET), pt_to_str(PT_NAME), 6204fa9e4066Sahrens in_progress_dstab.zone_dataset_name); 6205bbec428eSgjelinek saw_error = B_TRUE; 6206fa9e4066Sahrens return; 6207fa9e4066Sahrens } 6208fa9e4066Sahrens err = zonecfg_add_ds(handle, &in_progress_dstab); 6209fa9e4066Sahrens } else { 6210fa9e4066Sahrens err = zonecfg_modify_ds(handle, &old_dstab, 6211fa9e4066Sahrens &in_progress_dstab); 6212fa9e4066Sahrens } 6213fa9e4066Sahrens break; 62140209230bSgjelinek case RT_DCPU: 62150209230bSgjelinek /* Make sure everything was filled in. */ 62160209230bSgjelinek if (end_check_reqd(in_progress_psettab.zone_ncpu_min, 62170209230bSgjelinek PT_NCPUS, &validation_failed) != Z_OK) { 6218bbec428eSgjelinek saw_error = B_TRUE; 62190209230bSgjelinek return; 62200209230bSgjelinek } 62210209230bSgjelinek 62220209230bSgjelinek if (end_op == CMD_ADD) { 62230209230bSgjelinek err = zonecfg_add_pset(handle, &in_progress_psettab); 62240209230bSgjelinek } else { 62250209230bSgjelinek err = zonecfg_modify_pset(handle, &in_progress_psettab); 62260209230bSgjelinek } 62270209230bSgjelinek break; 6228c97ad5cdSakolb case RT_PCAP: 6229c97ad5cdSakolb /* Make sure everything was filled in. */ 6230c97ad5cdSakolb if (zonecfg_get_aliased_rctl(handle, ALIAS_CPUCAP, &proc_cap) 6231c97ad5cdSakolb != Z_OK) { 6232c97ad5cdSakolb zerr(gettext("%s not specified"), pt_to_str(PT_NCPUS)); 6233bbec428eSgjelinek saw_error = B_TRUE; 6234bbec428eSgjelinek validation_failed = B_TRUE; 6235c97ad5cdSakolb return; 6236c97ad5cdSakolb } 6237c97ad5cdSakolb err = Z_OK; 6238c97ad5cdSakolb break; 62390209230bSgjelinek case RT_MCAP: 62400209230bSgjelinek /* Make sure everything was filled in. */ 62410209230bSgjelinek res1 = strlen(in_progress_mcaptab.zone_physmem_cap) == 0 ? 62420209230bSgjelinek Z_ERR : Z_OK; 62430209230bSgjelinek res2 = zonecfg_get_aliased_rctl(handle, ALIAS_MAXSWAP, 62440209230bSgjelinek &swap_limit); 62450209230bSgjelinek res3 = zonecfg_get_aliased_rctl(handle, ALIAS_MAXLOCKEDMEM, 62460209230bSgjelinek &locked_limit); 62470209230bSgjelinek 62480209230bSgjelinek if (res1 != Z_OK && res2 != Z_OK && res3 != Z_OK) { 62490209230bSgjelinek zerr(gettext("No property was specified. One of %s, " 62500209230bSgjelinek "%s or %s is required."), pt_to_str(PT_PHYSICAL), 62510209230bSgjelinek pt_to_str(PT_SWAP), pt_to_str(PT_LOCKED)); 6252bbec428eSgjelinek saw_error = B_TRUE; 62530209230bSgjelinek return; 62540209230bSgjelinek } 62550209230bSgjelinek 62560209230bSgjelinek /* if phys & locked are both set, verify locked <= phys */ 62570209230bSgjelinek if (res1 == Z_OK && res3 == Z_OK) { 62580209230bSgjelinek uint64_t phys_limit; 62590209230bSgjelinek char *endp; 62600209230bSgjelinek 62610209230bSgjelinek phys_limit = strtoull( 62620209230bSgjelinek in_progress_mcaptab.zone_physmem_cap, &endp, 10); 62630209230bSgjelinek if (phys_limit < locked_limit) { 62640209230bSgjelinek zerr(gettext("The %s cap must be less than or " 62650209230bSgjelinek "equal to the %s cap."), 62660209230bSgjelinek pt_to_str(PT_LOCKED), 62670209230bSgjelinek pt_to_str(PT_PHYSICAL)); 6268bbec428eSgjelinek saw_error = B_TRUE; 62690209230bSgjelinek return; 62700209230bSgjelinek } 62710209230bSgjelinek } 62720209230bSgjelinek 62730209230bSgjelinek err = Z_OK; 62740209230bSgjelinek if (res1 == Z_OK) { 62750209230bSgjelinek /* 62760209230bSgjelinek * We could be ending from either an add operation 62770209230bSgjelinek * or a select operation. Since all of the properties 62780209230bSgjelinek * within this resource are optional, we always use 62790209230bSgjelinek * modify on the mcap entry. zonecfg_modify_mcap() 62800209230bSgjelinek * will handle both adding and modifying a memory cap. 62810209230bSgjelinek */ 62820209230bSgjelinek err = zonecfg_modify_mcap(handle, &in_progress_mcaptab); 62830209230bSgjelinek } else if (end_op == CMD_SELECT) { 62840209230bSgjelinek /* 62850209230bSgjelinek * If we're ending from a select and the physical 62860209230bSgjelinek * memory cap is empty then the user could have cleared 62870209230bSgjelinek * the physical cap value, so try to delete the entry. 62880209230bSgjelinek */ 62890209230bSgjelinek (void) zonecfg_delete_mcap(handle); 62900209230bSgjelinek } 62910209230bSgjelinek break; 62927c478bd9Sstevel@tonic-gate default: 62937c478bd9Sstevel@tonic-gate zone_perror(rt_to_str(resource_scope), Z_NO_RESOURCE_TYPE, 6294bbec428eSgjelinek B_TRUE); 6295bbec428eSgjelinek saw_error = B_TRUE; 62967c478bd9Sstevel@tonic-gate return; 62977c478bd9Sstevel@tonic-gate } 62987c478bd9Sstevel@tonic-gate 62997c478bd9Sstevel@tonic-gate if (err != Z_OK) { 6300bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 63017c478bd9Sstevel@tonic-gate } else { 6302bbec428eSgjelinek need_to_commit = B_TRUE; 6303bbec428eSgjelinek global_scope = B_TRUE; 63047c478bd9Sstevel@tonic-gate end_op = -1; 63057c478bd9Sstevel@tonic-gate } 63067c478bd9Sstevel@tonic-gate } 63077c478bd9Sstevel@tonic-gate 63087c478bd9Sstevel@tonic-gate void 63097c478bd9Sstevel@tonic-gate commit_func(cmd_t *cmd) 63107c478bd9Sstevel@tonic-gate { 63117c478bd9Sstevel@tonic-gate int arg; 6312bbec428eSgjelinek boolean_t arg_err = B_FALSE; 63137c478bd9Sstevel@tonic-gate 63147c478bd9Sstevel@tonic-gate optind = 0; 63157ec75eb8Sgjelinek while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?")) != EOF) { 63167c478bd9Sstevel@tonic-gate switch (arg) { 63177c478bd9Sstevel@tonic-gate case '?': 63187c478bd9Sstevel@tonic-gate longer_usage(CMD_COMMIT); 6319bbec428eSgjelinek arg_err = B_TRUE; 63207ec75eb8Sgjelinek break; 63217c478bd9Sstevel@tonic-gate default: 63227c478bd9Sstevel@tonic-gate short_usage(CMD_COMMIT); 6323bbec428eSgjelinek arg_err = B_TRUE; 63247ec75eb8Sgjelinek break; 63257c478bd9Sstevel@tonic-gate } 63267c478bd9Sstevel@tonic-gate } 63277ec75eb8Sgjelinek if (arg_err) 63287ec75eb8Sgjelinek return; 63297ec75eb8Sgjelinek 63307c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 63317c478bd9Sstevel@tonic-gate short_usage(CMD_COMMIT); 63327c478bd9Sstevel@tonic-gate return; 63337c478bd9Sstevel@tonic-gate } 63347c478bd9Sstevel@tonic-gate 63357c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_COMMIT)) 63367c478bd9Sstevel@tonic-gate return; 63377c478bd9Sstevel@tonic-gate 63387c478bd9Sstevel@tonic-gate assert(cmd != NULL); 63397c478bd9Sstevel@tonic-gate 63407c478bd9Sstevel@tonic-gate cmd->cmd_argc = 1; 63417c478bd9Sstevel@tonic-gate /* 63427c478bd9Sstevel@tonic-gate * cmd_arg normally comes from a strdup() in the lexer, and the 63437c478bd9Sstevel@tonic-gate * whole cmd structure and its (char *) attributes are freed at 63447c478bd9Sstevel@tonic-gate * the completion of each command, so the strdup() below is needed 63457c478bd9Sstevel@tonic-gate * to match this and prevent a core dump from trying to free() 63467c478bd9Sstevel@tonic-gate * something that can't be. 63477c478bd9Sstevel@tonic-gate */ 63487c478bd9Sstevel@tonic-gate if ((cmd->cmd_argv[0] = strdup("save")) == NULL) { 6349bbec428eSgjelinek zone_perror(zone, Z_NOMEM, B_TRUE); 63507c478bd9Sstevel@tonic-gate exit(Z_ERR); 63517c478bd9Sstevel@tonic-gate } 63527c478bd9Sstevel@tonic-gate cmd->cmd_argv[1] = NULL; 63537c478bd9Sstevel@tonic-gate verify_func(cmd); 63547c478bd9Sstevel@tonic-gate } 63557c478bd9Sstevel@tonic-gate 63567c478bd9Sstevel@tonic-gate void 63577c478bd9Sstevel@tonic-gate revert_func(cmd_t *cmd) 63587c478bd9Sstevel@tonic-gate { 63597c478bd9Sstevel@tonic-gate char line[128]; /* enough to ask a question */ 6360bbec428eSgjelinek boolean_t force = B_FALSE; 6361bbec428eSgjelinek boolean_t arg_err = B_FALSE; 63627c478bd9Sstevel@tonic-gate int err, arg, answer; 63637c478bd9Sstevel@tonic-gate 63647c478bd9Sstevel@tonic-gate optind = 0; 63657c478bd9Sstevel@tonic-gate while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?F")) != EOF) { 63667c478bd9Sstevel@tonic-gate switch (arg) { 63677c478bd9Sstevel@tonic-gate case '?': 63687c478bd9Sstevel@tonic-gate longer_usage(CMD_REVERT); 6369bbec428eSgjelinek arg_err = B_TRUE; 63707ec75eb8Sgjelinek break; 63717c478bd9Sstevel@tonic-gate case 'F': 6372bbec428eSgjelinek force = B_TRUE; 63737c478bd9Sstevel@tonic-gate break; 63747c478bd9Sstevel@tonic-gate default: 63757c478bd9Sstevel@tonic-gate short_usage(CMD_REVERT); 6376bbec428eSgjelinek arg_err = B_TRUE; 63777ec75eb8Sgjelinek break; 63787c478bd9Sstevel@tonic-gate } 63797c478bd9Sstevel@tonic-gate } 63807ec75eb8Sgjelinek if (arg_err) 63817ec75eb8Sgjelinek return; 63827ec75eb8Sgjelinek 63837c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 63847c478bd9Sstevel@tonic-gate short_usage(CMD_REVERT); 63857c478bd9Sstevel@tonic-gate return; 63867c478bd9Sstevel@tonic-gate } 63877c478bd9Sstevel@tonic-gate 63887c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_REVERT)) 63897c478bd9Sstevel@tonic-gate return; 63907c478bd9Sstevel@tonic-gate 63915b418297Sjv if (!global_scope) { 63925b418297Sjv zerr(gettext("You can only use %s in the global scope.\nUse" 63935b418297Sjv " '%s' to cancel changes to a resource specification."), 63945b418297Sjv cmd_to_str(CMD_REVERT), cmd_to_str(CMD_CANCEL)); 63955b418297Sjv saw_error = B_TRUE; 63965b418297Sjv return; 63975b418297Sjv } 63985b418297Sjv 63997c478bd9Sstevel@tonic-gate if (zonecfg_check_handle(handle) != Z_OK) { 64007c478bd9Sstevel@tonic-gate zerr(gettext("No changes to revert.")); 6401bbec428eSgjelinek saw_error = B_TRUE; 64027c478bd9Sstevel@tonic-gate return; 64037c478bd9Sstevel@tonic-gate } 64047c478bd9Sstevel@tonic-gate 64057c478bd9Sstevel@tonic-gate if (!force) { 64067c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), 64077c478bd9Sstevel@tonic-gate gettext("Are you sure you want to revert")); 6408bbec428eSgjelinek if ((answer = ask_yesno(B_FALSE, line)) == -1) { 64097c478bd9Sstevel@tonic-gate zerr(gettext("Input not from terminal and -F not " 64107c478bd9Sstevel@tonic-gate "specified:\n%s command ignored, exiting."), 64117c478bd9Sstevel@tonic-gate cmd_to_str(CMD_REVERT)); 64127c478bd9Sstevel@tonic-gate exit(Z_ERR); 64137c478bd9Sstevel@tonic-gate } 64147c478bd9Sstevel@tonic-gate if (answer != 1) 64157c478bd9Sstevel@tonic-gate return; 64167c478bd9Sstevel@tonic-gate } 64177c478bd9Sstevel@tonic-gate 64187c478bd9Sstevel@tonic-gate /* 64197c478bd9Sstevel@tonic-gate * Time for a new handle: finish the old one off first 64207c478bd9Sstevel@tonic-gate * then get a new one properly to avoid leaks. 64217c478bd9Sstevel@tonic-gate */ 64227c478bd9Sstevel@tonic-gate zonecfg_fini_handle(handle); 64237c478bd9Sstevel@tonic-gate if ((handle = zonecfg_init_handle()) == NULL) { 6424bbec428eSgjelinek zone_perror(execname, Z_NOMEM, B_TRUE); 64257c478bd9Sstevel@tonic-gate exit(Z_ERR); 64267c478bd9Sstevel@tonic-gate } 6427087719fdSdp if ((err = zonecfg_get_handle(revert_zone, handle)) != Z_OK) { 6428bbec428eSgjelinek saw_error = B_TRUE; 6429bbec428eSgjelinek got_handle = B_FALSE; 64307c478bd9Sstevel@tonic-gate if (err == Z_NO_ZONE) 64317c478bd9Sstevel@tonic-gate zerr(gettext("%s: no such saved zone to revert to."), 6432087719fdSdp revert_zone); 64337c478bd9Sstevel@tonic-gate else 6434bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 64357c478bd9Sstevel@tonic-gate } 6436087719fdSdp (void) strlcpy(zone, revert_zone, sizeof (zone)); 64377c478bd9Sstevel@tonic-gate } 64387c478bd9Sstevel@tonic-gate 64397c478bd9Sstevel@tonic-gate void 64407c478bd9Sstevel@tonic-gate help_func(cmd_t *cmd) 64417c478bd9Sstevel@tonic-gate { 64427c478bd9Sstevel@tonic-gate int i; 64437c478bd9Sstevel@tonic-gate 64447c478bd9Sstevel@tonic-gate assert(cmd != NULL); 64457c478bd9Sstevel@tonic-gate 64467c478bd9Sstevel@tonic-gate if (cmd->cmd_argc == 0) { 6447bbec428eSgjelinek usage(B_TRUE, global_scope ? HELP_SUBCMDS : HELP_RES_SCOPE); 64487c478bd9Sstevel@tonic-gate return; 64497c478bd9Sstevel@tonic-gate } 64507c478bd9Sstevel@tonic-gate if (strcmp(cmd->cmd_argv[0], "usage") == 0) { 6451bbec428eSgjelinek usage(B_TRUE, HELP_USAGE); 64527c478bd9Sstevel@tonic-gate return; 64537c478bd9Sstevel@tonic-gate } 64547c478bd9Sstevel@tonic-gate if (strcmp(cmd->cmd_argv[0], "commands") == 0) { 6455bbec428eSgjelinek usage(B_TRUE, HELP_SUBCMDS); 64567c478bd9Sstevel@tonic-gate return; 64577c478bd9Sstevel@tonic-gate } 64587c478bd9Sstevel@tonic-gate if (strcmp(cmd->cmd_argv[0], "syntax") == 0) { 6459bbec428eSgjelinek usage(B_TRUE, HELP_SYNTAX | HELP_RES_PROPS); 64607c478bd9Sstevel@tonic-gate return; 64617c478bd9Sstevel@tonic-gate } 64627c478bd9Sstevel@tonic-gate if (strcmp(cmd->cmd_argv[0], "-?") == 0) { 64637c478bd9Sstevel@tonic-gate longer_usage(CMD_HELP); 64647c478bd9Sstevel@tonic-gate return; 64657c478bd9Sstevel@tonic-gate } 64667c478bd9Sstevel@tonic-gate 64677c478bd9Sstevel@tonic-gate for (i = 0; i <= CMD_MAX; i++) { 64687c478bd9Sstevel@tonic-gate if (strcmp(cmd->cmd_argv[0], cmd_to_str(i)) == 0) { 64697c478bd9Sstevel@tonic-gate longer_usage(i); 64707c478bd9Sstevel@tonic-gate return; 64717c478bd9Sstevel@tonic-gate } 64727c478bd9Sstevel@tonic-gate } 64737c478bd9Sstevel@tonic-gate /* We do not use zerr() here because we do not want its extra \n. */ 64747c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("Unknown help subject %s. "), 64757c478bd9Sstevel@tonic-gate cmd->cmd_argv[0]); 6476bbec428eSgjelinek usage(B_FALSE, HELP_META); 64777c478bd9Sstevel@tonic-gate } 64787c478bd9Sstevel@tonic-gate 64797c478bd9Sstevel@tonic-gate static int 64807c478bd9Sstevel@tonic-gate string_to_yyin(char *string) 64817c478bd9Sstevel@tonic-gate { 64827c478bd9Sstevel@tonic-gate if ((yyin = tmpfile()) == NULL) { 6483bbec428eSgjelinek zone_perror(execname, Z_TEMP_FILE, B_TRUE); 64847c478bd9Sstevel@tonic-gate return (Z_ERR); 64857c478bd9Sstevel@tonic-gate } 64867c478bd9Sstevel@tonic-gate if (fwrite(string, strlen(string), 1, yyin) != 1) { 6487bbec428eSgjelinek zone_perror(execname, Z_TEMP_FILE, B_TRUE); 64887c478bd9Sstevel@tonic-gate return (Z_ERR); 64897c478bd9Sstevel@tonic-gate } 64907c478bd9Sstevel@tonic-gate if (fseek(yyin, 0, SEEK_SET) != 0) { 6491bbec428eSgjelinek zone_perror(execname, Z_TEMP_FILE, B_TRUE); 64927c478bd9Sstevel@tonic-gate return (Z_ERR); 64937c478bd9Sstevel@tonic-gate } 64947c478bd9Sstevel@tonic-gate return (Z_OK); 64957c478bd9Sstevel@tonic-gate } 64967c478bd9Sstevel@tonic-gate 64977c478bd9Sstevel@tonic-gate /* This is the back-end helper function for read_input() below. */ 64987c478bd9Sstevel@tonic-gate 64997c478bd9Sstevel@tonic-gate static int 65007c478bd9Sstevel@tonic-gate cleanup() 65017c478bd9Sstevel@tonic-gate { 65027c478bd9Sstevel@tonic-gate int answer; 65037c478bd9Sstevel@tonic-gate cmd_t *cmd; 65047c478bd9Sstevel@tonic-gate 65057c478bd9Sstevel@tonic-gate if (!interactive_mode && !cmd_file_mode) { 65067c478bd9Sstevel@tonic-gate /* 65077c478bd9Sstevel@tonic-gate * If we're not in interactive mode, and we're not in command 65087c478bd9Sstevel@tonic-gate * file mode, then we must be in commands-from-the-command-line 65097c478bd9Sstevel@tonic-gate * mode. As such, we can't loop back and ask for more input. 65107c478bd9Sstevel@tonic-gate * It was OK to prompt for such things as whether or not to 65117c478bd9Sstevel@tonic-gate * really delete a zone in the command handler called from 65127c478bd9Sstevel@tonic-gate * yyparse() above, but "really quit?" makes no sense in this 65137c478bd9Sstevel@tonic-gate * context. So disable prompting. 65147c478bd9Sstevel@tonic-gate */ 6515bbec428eSgjelinek ok_to_prompt = B_FALSE; 65167c478bd9Sstevel@tonic-gate } 65177c478bd9Sstevel@tonic-gate if (!global_scope) { 65187c478bd9Sstevel@tonic-gate if (!time_to_exit) { 65197c478bd9Sstevel@tonic-gate /* 65207c478bd9Sstevel@tonic-gate * Just print a simple error message in the -1 case, 65217c478bd9Sstevel@tonic-gate * since exit_func() already handles that case, and 65227c478bd9Sstevel@tonic-gate * EOF means we are finished anyway. 65237c478bd9Sstevel@tonic-gate */ 6524bbec428eSgjelinek answer = ask_yesno(B_FALSE, 65257c478bd9Sstevel@tonic-gate gettext("Resource incomplete; really quit")); 65267c478bd9Sstevel@tonic-gate if (answer == -1) { 65277c478bd9Sstevel@tonic-gate zerr(gettext("Resource incomplete.")); 65287c478bd9Sstevel@tonic-gate return (Z_ERR); 65297c478bd9Sstevel@tonic-gate } 65307c478bd9Sstevel@tonic-gate if (answer != 1) { 65317c478bd9Sstevel@tonic-gate yyin = stdin; 65327c478bd9Sstevel@tonic-gate return (Z_REPEAT); 65337c478bd9Sstevel@tonic-gate } 65347c478bd9Sstevel@tonic-gate } else { 6535bbec428eSgjelinek saw_error = B_TRUE; 65367c478bd9Sstevel@tonic-gate } 65377c478bd9Sstevel@tonic-gate } 65387c478bd9Sstevel@tonic-gate /* 65397c478bd9Sstevel@tonic-gate * Make sure we tried something and that the handle checks 65407c478bd9Sstevel@tonic-gate * out, or we would get a false error trying to commit. 65417c478bd9Sstevel@tonic-gate */ 65427c478bd9Sstevel@tonic-gate if (need_to_commit && zonecfg_check_handle(handle) == Z_OK) { 65437c478bd9Sstevel@tonic-gate if ((cmd = alloc_cmd()) == NULL) { 6544bbec428eSgjelinek zone_perror(zone, Z_NOMEM, B_TRUE); 65457c478bd9Sstevel@tonic-gate return (Z_ERR); 65467c478bd9Sstevel@tonic-gate } 65477c478bd9Sstevel@tonic-gate cmd->cmd_argc = 0; 65487c478bd9Sstevel@tonic-gate cmd->cmd_argv[0] = NULL; 65497c478bd9Sstevel@tonic-gate commit_func(cmd); 65507c478bd9Sstevel@tonic-gate free_cmd(cmd); 65517c478bd9Sstevel@tonic-gate /* 65527c478bd9Sstevel@tonic-gate * need_to_commit will get set back to FALSE if the 65537c478bd9Sstevel@tonic-gate * configuration is saved successfully. 65547c478bd9Sstevel@tonic-gate */ 65557c478bd9Sstevel@tonic-gate if (need_to_commit) { 65567c478bd9Sstevel@tonic-gate if (force_exit) { 65577c478bd9Sstevel@tonic-gate zerr(gettext("Configuration not saved.")); 65587c478bd9Sstevel@tonic-gate return (Z_ERR); 65597c478bd9Sstevel@tonic-gate } 6560bbec428eSgjelinek answer = ask_yesno(B_FALSE, 65617c478bd9Sstevel@tonic-gate gettext("Configuration not saved; really quit")); 65627c478bd9Sstevel@tonic-gate if (answer == -1) { 65637c478bd9Sstevel@tonic-gate zerr(gettext("Configuration not saved.")); 65647c478bd9Sstevel@tonic-gate return (Z_ERR); 65657c478bd9Sstevel@tonic-gate } 65667c478bd9Sstevel@tonic-gate if (answer != 1) { 6567bbec428eSgjelinek time_to_exit = B_FALSE; 65687c478bd9Sstevel@tonic-gate yyin = stdin; 65697c478bd9Sstevel@tonic-gate return (Z_REPEAT); 65707c478bd9Sstevel@tonic-gate } 65717c478bd9Sstevel@tonic-gate } 65727c478bd9Sstevel@tonic-gate } 65737c478bd9Sstevel@tonic-gate return ((need_to_commit || saw_error) ? Z_ERR : Z_OK); 65747c478bd9Sstevel@tonic-gate } 65757c478bd9Sstevel@tonic-gate 65767c478bd9Sstevel@tonic-gate /* 65777c478bd9Sstevel@tonic-gate * read_input() is the driver of this program. It is a wrapper around 65787c478bd9Sstevel@tonic-gate * yyparse(), printing appropriate prompts when needed, checking for 65797c478bd9Sstevel@tonic-gate * exit conditions and reacting appropriately [the latter in its cleanup() 65807c478bd9Sstevel@tonic-gate * helper function]. 65817c478bd9Sstevel@tonic-gate * 65827c478bd9Sstevel@tonic-gate * Like most zonecfg functions, it returns Z_OK or Z_ERR, *or* Z_REPEAT 65837c478bd9Sstevel@tonic-gate * so do_interactive() knows that we are not really done (i.e, we asked 65847c478bd9Sstevel@tonic-gate * the user if we should really quit and the user said no). 65857c478bd9Sstevel@tonic-gate */ 65867c478bd9Sstevel@tonic-gate static int 65877c478bd9Sstevel@tonic-gate read_input() 65887c478bd9Sstevel@tonic-gate { 6589bbec428eSgjelinek boolean_t yyin_is_a_tty = isatty(fileno(yyin)); 65907c478bd9Sstevel@tonic-gate /* 65917c478bd9Sstevel@tonic-gate * The prompt is "e:z> " or "e:z:r> " where e is execname, z is zone 65927c478bd9Sstevel@tonic-gate * and r is resource_scope: 5 is for the two ":"s + "> " + terminator. 65937c478bd9Sstevel@tonic-gate */ 65947c478bd9Sstevel@tonic-gate char prompt[MAXPATHLEN + ZONENAME_MAX + MAX_RT_STRLEN + 5], *line; 65957c478bd9Sstevel@tonic-gate 65967c478bd9Sstevel@tonic-gate /* yyin should have been set to the appropriate (FILE *) if not stdin */ 6597bbec428eSgjelinek newline_terminated = B_TRUE; 65987c478bd9Sstevel@tonic-gate for (;;) { 65997c478bd9Sstevel@tonic-gate if (yyin_is_a_tty) { 66007c478bd9Sstevel@tonic-gate if (newline_terminated) { 66017c478bd9Sstevel@tonic-gate if (global_scope) 66027c478bd9Sstevel@tonic-gate (void) snprintf(prompt, sizeof (prompt), 66037c478bd9Sstevel@tonic-gate "%s:%s> ", execname, zone); 66047c478bd9Sstevel@tonic-gate else 66057c478bd9Sstevel@tonic-gate (void) snprintf(prompt, sizeof (prompt), 66067c478bd9Sstevel@tonic-gate "%s:%s:%s> ", execname, zone, 66077c478bd9Sstevel@tonic-gate rt_to_str(resource_scope)); 66087c478bd9Sstevel@tonic-gate } 66097c478bd9Sstevel@tonic-gate /* 66107c478bd9Sstevel@tonic-gate * If the user hits ^C then we want to catch it and 66117c478bd9Sstevel@tonic-gate * start over. If the user hits EOF then we want to 66127c478bd9Sstevel@tonic-gate * bail out. 66137c478bd9Sstevel@tonic-gate */ 66147c478bd9Sstevel@tonic-gate line = gl_get_line(gl, prompt, NULL, -1); 66157c478bd9Sstevel@tonic-gate if (gl_return_status(gl) == GLR_SIGNAL) { 66167c478bd9Sstevel@tonic-gate gl_abandon_line(gl); 66177c478bd9Sstevel@tonic-gate continue; 66187c478bd9Sstevel@tonic-gate } 66197c478bd9Sstevel@tonic-gate if (line == NULL) 66207c478bd9Sstevel@tonic-gate break; 66217c478bd9Sstevel@tonic-gate (void) string_to_yyin(line); 66227c478bd9Sstevel@tonic-gate while (!feof(yyin)) 66237c478bd9Sstevel@tonic-gate yyparse(); 66247c478bd9Sstevel@tonic-gate } else { 66257c478bd9Sstevel@tonic-gate yyparse(); 66267c478bd9Sstevel@tonic-gate } 66277c478bd9Sstevel@tonic-gate /* Bail out on an error in command file mode. */ 66287c478bd9Sstevel@tonic-gate if (saw_error && cmd_file_mode && !interactive_mode) 6629bbec428eSgjelinek time_to_exit = B_TRUE; 66307c478bd9Sstevel@tonic-gate if (time_to_exit || (!yyin_is_a_tty && feof(yyin))) 66317c478bd9Sstevel@tonic-gate break; 66327c478bd9Sstevel@tonic-gate } 66337c478bd9Sstevel@tonic-gate return (cleanup()); 66347c478bd9Sstevel@tonic-gate } 66357c478bd9Sstevel@tonic-gate 66367c478bd9Sstevel@tonic-gate /* 66377c478bd9Sstevel@tonic-gate * This function is used in the zonecfg-interactive-mode scenario: it just 66387c478bd9Sstevel@tonic-gate * calls read_input() until we are done. 66397c478bd9Sstevel@tonic-gate */ 66407c478bd9Sstevel@tonic-gate 66417c478bd9Sstevel@tonic-gate static int 66427c478bd9Sstevel@tonic-gate do_interactive(void) 66437c478bd9Sstevel@tonic-gate { 66447c478bd9Sstevel@tonic-gate int err; 66457c478bd9Sstevel@tonic-gate 6646bbec428eSgjelinek interactive_mode = B_TRUE; 66477c478bd9Sstevel@tonic-gate if (!read_only_mode) { 66487c478bd9Sstevel@tonic-gate /* 66497c478bd9Sstevel@tonic-gate * Try to set things up proactively in interactive mode, so 66507c478bd9Sstevel@tonic-gate * that if the zone in question does not exist yet, we can 66517c478bd9Sstevel@tonic-gate * provide the user with a clue. 66527c478bd9Sstevel@tonic-gate */ 6653bbec428eSgjelinek (void) initialize(B_FALSE); 66547c478bd9Sstevel@tonic-gate } 6655087719fdSdp do { 66567c478bd9Sstevel@tonic-gate err = read_input(); 6657087719fdSdp } while (err == Z_REPEAT); 66587c478bd9Sstevel@tonic-gate return (err); 66597c478bd9Sstevel@tonic-gate } 66607c478bd9Sstevel@tonic-gate 66617c478bd9Sstevel@tonic-gate /* 66627c478bd9Sstevel@tonic-gate * cmd_file is slightly more complicated, as it has to open the command file 66637c478bd9Sstevel@tonic-gate * and set yyin appropriately. Once that is done, though, it just calls 66647c478bd9Sstevel@tonic-gate * read_input(), and only once, since prompting is not possible. 66657c478bd9Sstevel@tonic-gate */ 66667c478bd9Sstevel@tonic-gate 66677c478bd9Sstevel@tonic-gate static int 66687c478bd9Sstevel@tonic-gate cmd_file(char *file) 66697c478bd9Sstevel@tonic-gate { 66707c478bd9Sstevel@tonic-gate FILE *infile; 66717c478bd9Sstevel@tonic-gate int err; 66727c478bd9Sstevel@tonic-gate struct stat statbuf; 6673bbec428eSgjelinek boolean_t using_real_file = (strcmp(file, "-") != 0); 66747c478bd9Sstevel@tonic-gate 66757c478bd9Sstevel@tonic-gate if (using_real_file) { 66767c478bd9Sstevel@tonic-gate /* 66777c478bd9Sstevel@tonic-gate * zerr() prints a line number in cmd_file_mode, which we do 66787c478bd9Sstevel@tonic-gate * not want here, so temporarily unset it. 66797c478bd9Sstevel@tonic-gate */ 6680bbec428eSgjelinek cmd_file_mode = B_FALSE; 66817c478bd9Sstevel@tonic-gate if ((infile = fopen(file, "r")) == NULL) { 66827c478bd9Sstevel@tonic-gate zerr(gettext("could not open file %s: %s"), 66837c478bd9Sstevel@tonic-gate file, strerror(errno)); 66847c478bd9Sstevel@tonic-gate return (Z_ERR); 66857c478bd9Sstevel@tonic-gate } 66867c478bd9Sstevel@tonic-gate if ((err = fstat(fileno(infile), &statbuf)) != 0) { 66877c478bd9Sstevel@tonic-gate zerr(gettext("could not stat file %s: %s"), 66887c478bd9Sstevel@tonic-gate file, strerror(errno)); 66897c478bd9Sstevel@tonic-gate err = Z_ERR; 66907c478bd9Sstevel@tonic-gate goto done; 66917c478bd9Sstevel@tonic-gate } 66927c478bd9Sstevel@tonic-gate if (!S_ISREG(statbuf.st_mode)) { 66937c478bd9Sstevel@tonic-gate zerr(gettext("%s is not a regular file."), file); 66947c478bd9Sstevel@tonic-gate err = Z_ERR; 66957c478bd9Sstevel@tonic-gate goto done; 66967c478bd9Sstevel@tonic-gate } 66977c478bd9Sstevel@tonic-gate yyin = infile; 6698bbec428eSgjelinek cmd_file_mode = B_TRUE; 6699bbec428eSgjelinek ok_to_prompt = B_FALSE; 67007c478bd9Sstevel@tonic-gate } else { 67017c478bd9Sstevel@tonic-gate /* 67027c478bd9Sstevel@tonic-gate * "-f -" is essentially the same as interactive mode, 67037c478bd9Sstevel@tonic-gate * so treat it that way. 67047c478bd9Sstevel@tonic-gate */ 6705bbec428eSgjelinek interactive_mode = B_TRUE; 67067c478bd9Sstevel@tonic-gate } 67077c478bd9Sstevel@tonic-gate /* Z_REPEAT is for interactive mode; treat it like Z_ERR here. */ 67087c478bd9Sstevel@tonic-gate if ((err = read_input()) == Z_REPEAT) 67097c478bd9Sstevel@tonic-gate err = Z_ERR; 67107c478bd9Sstevel@tonic-gate done: 67117c478bd9Sstevel@tonic-gate if (using_real_file) 67127c478bd9Sstevel@tonic-gate (void) fclose(infile); 67137c478bd9Sstevel@tonic-gate return (err); 67147c478bd9Sstevel@tonic-gate } 67157c478bd9Sstevel@tonic-gate 67167c478bd9Sstevel@tonic-gate /* 67177c478bd9Sstevel@tonic-gate * Since yacc is based on reading from a (FILE *) whereas what we get from 67187c478bd9Sstevel@tonic-gate * the command line is in argv format, we need to convert when the user 67197c478bd9Sstevel@tonic-gate * gives us commands directly from the command line. That is done here by 67207c478bd9Sstevel@tonic-gate * concatenating the argv list into a space-separated string, writing it 67217c478bd9Sstevel@tonic-gate * to a temp file, and rewinding the file so yyin can be set to it. Then 67227c478bd9Sstevel@tonic-gate * we call read_input(), and only once, since prompting about whether to 67237c478bd9Sstevel@tonic-gate * continue or quit would make no sense in this context. 67247c478bd9Sstevel@tonic-gate */ 67257c478bd9Sstevel@tonic-gate 67267c478bd9Sstevel@tonic-gate static int 67277c478bd9Sstevel@tonic-gate one_command_at_a_time(int argc, char *argv[]) 67287c478bd9Sstevel@tonic-gate { 67297c478bd9Sstevel@tonic-gate char *command; 67307c478bd9Sstevel@tonic-gate size_t len = 2; /* terminal \n\0 */ 67317c478bd9Sstevel@tonic-gate int i, err; 67327c478bd9Sstevel@tonic-gate 67337c478bd9Sstevel@tonic-gate for (i = 0; i < argc; i++) 67347c478bd9Sstevel@tonic-gate len += strlen(argv[i]) + 1; 67357c478bd9Sstevel@tonic-gate if ((command = malloc(len)) == NULL) { 6736bbec428eSgjelinek zone_perror(execname, Z_NOMEM, B_TRUE); 67377c478bd9Sstevel@tonic-gate return (Z_ERR); 67387c478bd9Sstevel@tonic-gate } 67397c478bd9Sstevel@tonic-gate (void) strlcpy(command, argv[0], len); 67407c478bd9Sstevel@tonic-gate for (i = 1; i < argc; i++) { 67417c478bd9Sstevel@tonic-gate (void) strlcat(command, " ", len); 67427c478bd9Sstevel@tonic-gate (void) strlcat(command, argv[i], len); 67437c478bd9Sstevel@tonic-gate } 67447c478bd9Sstevel@tonic-gate (void) strlcat(command, "\n", len); 67457c478bd9Sstevel@tonic-gate err = string_to_yyin(command); 67467c478bd9Sstevel@tonic-gate free(command); 67477c478bd9Sstevel@tonic-gate if (err != Z_OK) 67487c478bd9Sstevel@tonic-gate return (err); 67497c478bd9Sstevel@tonic-gate while (!feof(yyin)) 67507c478bd9Sstevel@tonic-gate yyparse(); 67517c478bd9Sstevel@tonic-gate return (cleanup()); 67527c478bd9Sstevel@tonic-gate } 67537c478bd9Sstevel@tonic-gate 67547c478bd9Sstevel@tonic-gate static char * 67557c478bd9Sstevel@tonic-gate get_execbasename(char *execfullname) 67567c478bd9Sstevel@tonic-gate { 67577c478bd9Sstevel@tonic-gate char *last_slash, *execbasename; 67587c478bd9Sstevel@tonic-gate 67597c478bd9Sstevel@tonic-gate /* guard against '/' at end of command invocation */ 67607c478bd9Sstevel@tonic-gate for (;;) { 67617c478bd9Sstevel@tonic-gate last_slash = strrchr(execfullname, '/'); 67627c478bd9Sstevel@tonic-gate if (last_slash == NULL) { 67637c478bd9Sstevel@tonic-gate execbasename = execfullname; 67647c478bd9Sstevel@tonic-gate break; 67657c478bd9Sstevel@tonic-gate } else { 67667c478bd9Sstevel@tonic-gate execbasename = last_slash + 1; 67677c478bd9Sstevel@tonic-gate if (*execbasename == '\0') { 67687c478bd9Sstevel@tonic-gate *last_slash = '\0'; 67697c478bd9Sstevel@tonic-gate continue; 67707c478bd9Sstevel@tonic-gate } 67717c478bd9Sstevel@tonic-gate break; 67727c478bd9Sstevel@tonic-gate } 67737c478bd9Sstevel@tonic-gate } 67747c478bd9Sstevel@tonic-gate return (execbasename); 67757c478bd9Sstevel@tonic-gate } 67767c478bd9Sstevel@tonic-gate 67777c478bd9Sstevel@tonic-gate int 67787c478bd9Sstevel@tonic-gate main(int argc, char *argv[]) 67797c478bd9Sstevel@tonic-gate { 67807c478bd9Sstevel@tonic-gate int err, arg; 6781555afedfScarlsonj struct stat st; 67827c478bd9Sstevel@tonic-gate 67837c478bd9Sstevel@tonic-gate /* This must be before anything goes to stdout. */ 67847c478bd9Sstevel@tonic-gate setbuf(stdout, NULL); 67857c478bd9Sstevel@tonic-gate 6786bbec428eSgjelinek saw_error = B_FALSE; 6787bbec428eSgjelinek cmd_file_mode = B_FALSE; 67887c478bd9Sstevel@tonic-gate execname = get_execbasename(argv[0]); 67897c478bd9Sstevel@tonic-gate 67907c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 67917c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 67927c478bd9Sstevel@tonic-gate 67937c478bd9Sstevel@tonic-gate if (getzoneid() != GLOBAL_ZONEID) { 67947c478bd9Sstevel@tonic-gate zerr(gettext("%s can only be run from the global zone."), 67957c478bd9Sstevel@tonic-gate execname); 67967c478bd9Sstevel@tonic-gate exit(Z_ERR); 67977c478bd9Sstevel@tonic-gate } 67987c478bd9Sstevel@tonic-gate 67997c478bd9Sstevel@tonic-gate if (argc < 2) { 6800bbec428eSgjelinek usage(B_FALSE, HELP_USAGE | HELP_SUBCMDS); 68017c478bd9Sstevel@tonic-gate exit(Z_USAGE); 68027c478bd9Sstevel@tonic-gate } 68037c478bd9Sstevel@tonic-gate if (strcmp(argv[1], cmd_to_str(CMD_HELP)) == 0) { 68047c478bd9Sstevel@tonic-gate (void) one_command_at_a_time(argc - 1, &(argv[1])); 68057c478bd9Sstevel@tonic-gate exit(Z_OK); 68067c478bd9Sstevel@tonic-gate } 68077c478bd9Sstevel@tonic-gate 6808555afedfScarlsonj while ((arg = getopt(argc, argv, "?f:R:z:")) != EOF) { 68097c478bd9Sstevel@tonic-gate switch (arg) { 68107c478bd9Sstevel@tonic-gate case '?': 68117c478bd9Sstevel@tonic-gate if (optopt == '?') 6812bbec428eSgjelinek usage(B_TRUE, HELP_USAGE | HELP_SUBCMDS); 68137c478bd9Sstevel@tonic-gate else 6814bbec428eSgjelinek usage(B_FALSE, HELP_USAGE); 68157c478bd9Sstevel@tonic-gate exit(Z_USAGE); 68167c478bd9Sstevel@tonic-gate /* NOTREACHED */ 68177c478bd9Sstevel@tonic-gate case 'f': 68187c478bd9Sstevel@tonic-gate cmd_file_name = optarg; 6819bbec428eSgjelinek cmd_file_mode = B_TRUE; 68207c478bd9Sstevel@tonic-gate break; 6821555afedfScarlsonj case 'R': 6822555afedfScarlsonj if (*optarg != '/') { 6823555afedfScarlsonj zerr(gettext("root path must be absolute: %s"), 6824555afedfScarlsonj optarg); 6825555afedfScarlsonj exit(Z_USAGE); 6826555afedfScarlsonj } 6827555afedfScarlsonj if (stat(optarg, &st) == -1 || !S_ISDIR(st.st_mode)) { 6828555afedfScarlsonj zerr(gettext( 6829555afedfScarlsonj "root path must be a directory: %s"), 6830555afedfScarlsonj optarg); 6831555afedfScarlsonj exit(Z_USAGE); 6832555afedfScarlsonj } 6833555afedfScarlsonj zonecfg_set_root(optarg); 6834555afedfScarlsonj break; 68357c478bd9Sstevel@tonic-gate case 'z': 68360209230bSgjelinek if (strcmp(optarg, GLOBAL_ZONENAME) == 0) { 6837bbec428eSgjelinek global_zone = B_TRUE; 68380209230bSgjelinek } else if (zonecfg_validate_zonename(optarg) != Z_OK) { 6839bbec428eSgjelinek zone_perror(optarg, Z_BOGUS_ZONE_NAME, B_TRUE); 6840bbec428eSgjelinek usage(B_FALSE, HELP_SYNTAX); 6841087719fdSdp exit(Z_USAGE); 6842087719fdSdp } 6843087719fdSdp (void) strlcpy(zone, optarg, sizeof (zone)); 6844087719fdSdp (void) strlcpy(revert_zone, optarg, sizeof (zone)); 68457c478bd9Sstevel@tonic-gate break; 68467c478bd9Sstevel@tonic-gate default: 6847bbec428eSgjelinek usage(B_FALSE, HELP_USAGE); 68487c478bd9Sstevel@tonic-gate exit(Z_USAGE); 68497c478bd9Sstevel@tonic-gate } 68507c478bd9Sstevel@tonic-gate } 68517c478bd9Sstevel@tonic-gate 6852087719fdSdp if (optind > argc || strcmp(zone, "") == 0) { 6853bbec428eSgjelinek usage(B_FALSE, HELP_USAGE); 68547c478bd9Sstevel@tonic-gate exit(Z_USAGE); 68557c478bd9Sstevel@tonic-gate } 68567c478bd9Sstevel@tonic-gate 6857087719fdSdp if ((err = zonecfg_access(zone, W_OK)) == Z_OK) { 6858bbec428eSgjelinek read_only_mode = B_FALSE; 6859087719fdSdp } else if (err == Z_ACCES) { 6860bbec428eSgjelinek read_only_mode = B_TRUE; 68617c478bd9Sstevel@tonic-gate /* skip this message in one-off from command line mode */ 68627c478bd9Sstevel@tonic-gate if (optind == argc) 68637c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("WARNING: you do not " 68647c478bd9Sstevel@tonic-gate "have write access to this zone's configuration " 68657c478bd9Sstevel@tonic-gate "file;\ngoing into read-only mode.\n")); 6866087719fdSdp } else { 6867087719fdSdp fprintf(stderr, "%s: Could not access zone configuration " 6868087719fdSdp "store: %s\n", execname, zonecfg_strerror(err)); 6869087719fdSdp exit(Z_ERR); 68707c478bd9Sstevel@tonic-gate } 68717c478bd9Sstevel@tonic-gate 68727c478bd9Sstevel@tonic-gate if ((handle = zonecfg_init_handle()) == NULL) { 6873bbec428eSgjelinek zone_perror(execname, Z_NOMEM, B_TRUE); 68747c478bd9Sstevel@tonic-gate exit(Z_ERR); 68757c478bd9Sstevel@tonic-gate } 68767c478bd9Sstevel@tonic-gate 68777c478bd9Sstevel@tonic-gate /* 68787c478bd9Sstevel@tonic-gate * This may get set back to FALSE again in cmd_file() if cmd_file_name 68797c478bd9Sstevel@tonic-gate * is a "real" file as opposed to "-" (i.e. meaning use stdin). 68807c478bd9Sstevel@tonic-gate */ 68817c478bd9Sstevel@tonic-gate if (isatty(STDIN_FILENO)) 6882bbec428eSgjelinek ok_to_prompt = B_TRUE; 68837c478bd9Sstevel@tonic-gate if ((gl = new_GetLine(MAX_LINE_LEN, MAX_CMD_HIST)) == NULL) 68847c478bd9Sstevel@tonic-gate exit(Z_ERR); 68857c478bd9Sstevel@tonic-gate if (gl_customize_completion(gl, NULL, cmd_cpl_fn) != 0) 68867c478bd9Sstevel@tonic-gate exit(Z_ERR); 68877c478bd9Sstevel@tonic-gate (void) sigset(SIGINT, SIG_IGN); 68887c478bd9Sstevel@tonic-gate if (optind == argc) { 68897c478bd9Sstevel@tonic-gate if (!cmd_file_mode) 68907c478bd9Sstevel@tonic-gate err = do_interactive(); 68917c478bd9Sstevel@tonic-gate else 68927c478bd9Sstevel@tonic-gate err = cmd_file(cmd_file_name); 68937c478bd9Sstevel@tonic-gate } else { 68947c478bd9Sstevel@tonic-gate err = one_command_at_a_time(argc - optind, &(argv[optind])); 68957c478bd9Sstevel@tonic-gate } 68967c478bd9Sstevel@tonic-gate zonecfg_fini_handle(handle); 68979acbbeafSnn if (brand != NULL) 68989acbbeafSnn brand_close(brand); 68997c478bd9Sstevel@tonic-gate (void) del_GetLine(gl); 69007c478bd9Sstevel@tonic-gate return (err); 69017c478bd9Sstevel@tonic-gate } 6902