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 /* 23de860bd9Sgfaden * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate /* 287c478bd9Sstevel@tonic-gate * zonecfg is a lex/yacc based command interpreter used to manage zone 297c478bd9Sstevel@tonic-gate * configurations. The lexer (see zonecfg_lex.l) builds up tokens, which 307c478bd9Sstevel@tonic-gate * the grammar (see zonecfg_grammar.y) builds up into commands, some of 317c478bd9Sstevel@tonic-gate * which takes resources and/or properties as arguments. See the block 327c478bd9Sstevel@tonic-gate * comments near the end of zonecfg_grammar.y for how the data structures 337c478bd9Sstevel@tonic-gate * which keep track of these resources and properties are built up. 347c478bd9Sstevel@tonic-gate * 357c478bd9Sstevel@tonic-gate * The resource/property data structures are inserted into a command 367c478bd9Sstevel@tonic-gate * structure (see zonecfg.h), which also keeps track of command names, 377c478bd9Sstevel@tonic-gate * miscellaneous arguments, and function handlers. The grammar selects 387c478bd9Sstevel@tonic-gate * the appropriate function handler, each of which takes a pointer to a 397c478bd9Sstevel@tonic-gate * command structure as its sole argument, and invokes it. The grammar 407c478bd9Sstevel@tonic-gate * itself is "entered" (a la the Matrix) by yyparse(), which is called 417c478bd9Sstevel@tonic-gate * from read_input(), our main driving function. That in turn is called 427c478bd9Sstevel@tonic-gate * by one of do_interactive(), cmd_file() or one_command_at_a_time(), each 437c478bd9Sstevel@tonic-gate * of which is called from main() depending on how the program was invoked. 447c478bd9Sstevel@tonic-gate * 457c478bd9Sstevel@tonic-gate * The rest of this module consists of the various function handlers and 467c478bd9Sstevel@tonic-gate * their helper functions. Some of these functions, particularly the 477c478bd9Sstevel@tonic-gate * X_to_str() functions, which maps command, resource and property numbers 487c478bd9Sstevel@tonic-gate * to strings, are used quite liberally, as doing so results in a better 497c478bd9Sstevel@tonic-gate * program w/rt I18N, reducing the need for translation notes. 507c478bd9Sstevel@tonic-gate */ 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate #include <sys/mntent.h> 537c478bd9Sstevel@tonic-gate #include <sys/varargs.h> 547c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate #include <errno.h> 579acbbeafSnn35248 #include <fcntl.h> 587c478bd9Sstevel@tonic-gate #include <strings.h> 597c478bd9Sstevel@tonic-gate #include <unistd.h> 607c478bd9Sstevel@tonic-gate #include <ctype.h> 617c478bd9Sstevel@tonic-gate #include <stdlib.h> 627c478bd9Sstevel@tonic-gate #include <assert.h> 637c478bd9Sstevel@tonic-gate #include <sys/stat.h> 647c478bd9Sstevel@tonic-gate #include <zone.h> 657c478bd9Sstevel@tonic-gate #include <arpa/inet.h> 667c478bd9Sstevel@tonic-gate #include <netdb.h> 677c478bd9Sstevel@tonic-gate #include <locale.h> 687c478bd9Sstevel@tonic-gate #include <libintl.h> 697c478bd9Sstevel@tonic-gate #include <alloca.h> 707c478bd9Sstevel@tonic-gate #include <signal.h> 719acbbeafSnn35248 #include <wait.h> 727c478bd9Sstevel@tonic-gate #include <libtecla.h> 73fa9e4066Sahrens #include <libzfs.h> 749acbbeafSnn35248 #include <sys/brand.h> 759acbbeafSnn35248 #include <libbrand.h> 76*c9f134eaSjv227347 #include <libdladm.h> 77*c9f134eaSjv227347 #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" 879acbbeafSnn35248 #define EXEC_PREFIX "exec " 889acbbeafSnn35248 #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 1029acbbeafSnn35248 #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 */ 1567c478bd9Sstevel@tonic-gate static 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", 1719acbbeafSnn35248 "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", 181f4b3ec61Sdh155122 "ip-type", 182c97ad5cdSakolb "capped-cpu", 1837c478bd9Sstevel@tonic-gate NULL 1847c478bd9Sstevel@tonic-gate }; 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate /* These *must* match the order of the PT_ define's from zonecfg.h */ 1877c478bd9Sstevel@tonic-gate static char *prop_types[] = { 1887c478bd9Sstevel@tonic-gate "unknown", 189087719fdSdp "zonename", 1907c478bd9Sstevel@tonic-gate "zonepath", 1917c478bd9Sstevel@tonic-gate "autoboot", 1927c478bd9Sstevel@tonic-gate "pool", 1937c478bd9Sstevel@tonic-gate "dir", 1947c478bd9Sstevel@tonic-gate "special", 1957c478bd9Sstevel@tonic-gate "type", 1967c478bd9Sstevel@tonic-gate "options", 1977c478bd9Sstevel@tonic-gate "address", 1987c478bd9Sstevel@tonic-gate "physical", 1997c478bd9Sstevel@tonic-gate "name", 2007c478bd9Sstevel@tonic-gate "value", 2017c478bd9Sstevel@tonic-gate "match", 2027c478bd9Sstevel@tonic-gate "priv", 2037c478bd9Sstevel@tonic-gate "limit", 2047c478bd9Sstevel@tonic-gate "action", 2057c478bd9Sstevel@tonic-gate "raw", 206ffbafc53Scomay "limitpriv", 2073f2f09c1Sdp "bootargs", 2089acbbeafSnn35248 "brand", 2090209230bSgjelinek "ncpus", 2100209230bSgjelinek "importance", 2110209230bSgjelinek "swap", 2120209230bSgjelinek "locked", 2130209230bSgjelinek ALIAS_SHARES, 2140209230bSgjelinek ALIAS_MAXLWPS, 2150209230bSgjelinek ALIAS_MAXSHMMEM, 2160209230bSgjelinek ALIAS_MAXSHMIDS, 2170209230bSgjelinek ALIAS_MAXMSGIDS, 2180209230bSgjelinek ALIAS_MAXSEMIDS, 2190209230bSgjelinek ALIAS_MAXLOCKEDMEM, 2200209230bSgjelinek ALIAS_MAXSWAP, 2210209230bSgjelinek "scheduling-class", 222f4b3ec61Sdh155122 "ip-type", 223de860bd9Sgfaden "defrouter", 2247c478bd9Sstevel@tonic-gate NULL 2257c478bd9Sstevel@tonic-gate }; 2267c478bd9Sstevel@tonic-gate 227ffbafc53Scomay /* These *must* match the order of the PROP_VAL_ define's from zonecfg.h */ 2287c478bd9Sstevel@tonic-gate static char *prop_val_types[] = { 2297c478bd9Sstevel@tonic-gate "simple", 2307c478bd9Sstevel@tonic-gate "complex", 2317c478bd9Sstevel@tonic-gate "list", 2327c478bd9Sstevel@tonic-gate }; 2337c478bd9Sstevel@tonic-gate 2347c478bd9Sstevel@tonic-gate /* 2357c478bd9Sstevel@tonic-gate * The various _cmds[] lists below are for command tab-completion. 2367c478bd9Sstevel@tonic-gate */ 2377c478bd9Sstevel@tonic-gate 2387c478bd9Sstevel@tonic-gate /* 2397c478bd9Sstevel@tonic-gate * remove has a space afterwards because it has qualifiers; the other commands 2400209230bSgjelinek * that have qualifiers (add, select, etc.) don't need a space here because 2417c478bd9Sstevel@tonic-gate * they have their own _cmds[] lists below. 2427c478bd9Sstevel@tonic-gate */ 2437c478bd9Sstevel@tonic-gate static const char *global_scope_cmds[] = { 2447c478bd9Sstevel@tonic-gate "add", 2450209230bSgjelinek "clear", 2467c478bd9Sstevel@tonic-gate "commit", 2477c478bd9Sstevel@tonic-gate "create", 2487c478bd9Sstevel@tonic-gate "delete", 2497c478bd9Sstevel@tonic-gate "exit", 2507c478bd9Sstevel@tonic-gate "export", 2517c478bd9Sstevel@tonic-gate "help", 2527c478bd9Sstevel@tonic-gate "info", 2537c478bd9Sstevel@tonic-gate "remove ", 2547c478bd9Sstevel@tonic-gate "revert", 2557c478bd9Sstevel@tonic-gate "select", 2567c478bd9Sstevel@tonic-gate "set", 2577c478bd9Sstevel@tonic-gate "verify", 2587c478bd9Sstevel@tonic-gate NULL 2597c478bd9Sstevel@tonic-gate }; 2607c478bd9Sstevel@tonic-gate 2617c478bd9Sstevel@tonic-gate static const char *add_cmds[] = { 2627c478bd9Sstevel@tonic-gate "add fs", 2637c478bd9Sstevel@tonic-gate "add inherit-pkg-dir", 2647c478bd9Sstevel@tonic-gate "add net", 2657c478bd9Sstevel@tonic-gate "add device", 2667c478bd9Sstevel@tonic-gate "add rctl", 2677c478bd9Sstevel@tonic-gate "add attr", 268fa9e4066Sahrens "add dataset", 2690209230bSgjelinek "add dedicated-cpu", 270c97ad5cdSakolb "add capped-cpu", 2710209230bSgjelinek "add capped-memory", 2720209230bSgjelinek NULL 2730209230bSgjelinek }; 2740209230bSgjelinek 2750209230bSgjelinek static const char *clear_cmds[] = { 2760209230bSgjelinek "clear autoboot", 2770209230bSgjelinek "clear pool", 2780209230bSgjelinek "clear limitpriv", 2790209230bSgjelinek "clear bootargs", 2800209230bSgjelinek "clear scheduling-class", 281f4b3ec61Sdh155122 "clear ip-type", 2820209230bSgjelinek "clear " ALIAS_MAXLWPS, 2830209230bSgjelinek "clear " ALIAS_MAXSHMMEM, 2840209230bSgjelinek "clear " ALIAS_MAXSHMIDS, 2850209230bSgjelinek "clear " ALIAS_MAXMSGIDS, 2860209230bSgjelinek "clear " ALIAS_MAXSEMIDS, 2870209230bSgjelinek "clear " ALIAS_SHARES, 2887c478bd9Sstevel@tonic-gate NULL 2897c478bd9Sstevel@tonic-gate }; 2907c478bd9Sstevel@tonic-gate 2919e7542f4Sdp static const char *remove_cmds[] = { 2929e7542f4Sdp "remove fs ", 2939e7542f4Sdp "remove inherit-pkg-dir ", 2949e7542f4Sdp "remove net ", 2959e7542f4Sdp "remove device ", 2969e7542f4Sdp "remove rctl ", 2979e7542f4Sdp "remove attr ", 2989e7542f4Sdp "remove dataset ", 2990209230bSgjelinek "remove dedicated-cpu ", 300c97ad5cdSakolb "remove capped-cpu ", 3010209230bSgjelinek "remove capped-memory ", 3029e7542f4Sdp NULL 3039e7542f4Sdp }; 3049e7542f4Sdp 3057c478bd9Sstevel@tonic-gate static const char *select_cmds[] = { 3067c478bd9Sstevel@tonic-gate "select fs ", 3077c478bd9Sstevel@tonic-gate "select inherit-pkg-dir ", 3087c478bd9Sstevel@tonic-gate "select net ", 3097c478bd9Sstevel@tonic-gate "select device ", 3107c478bd9Sstevel@tonic-gate "select rctl ", 3117c478bd9Sstevel@tonic-gate "select attr ", 312fa9e4066Sahrens "select dataset ", 3130209230bSgjelinek "select dedicated-cpu", 314c97ad5cdSakolb "select capped-cpu", 3150209230bSgjelinek "select capped-memory", 3167c478bd9Sstevel@tonic-gate NULL 3177c478bd9Sstevel@tonic-gate }; 3187c478bd9Sstevel@tonic-gate 3197c478bd9Sstevel@tonic-gate static const char *set_cmds[] = { 320087719fdSdp "set zonename=", 321087719fdSdp "set zonepath=", 3229acbbeafSnn35248 "set brand=", 323087719fdSdp "set autoboot=", 324087719fdSdp "set pool=", 325ffbafc53Scomay "set limitpriv=", 3263f2f09c1Sdp "set bootargs=", 3270209230bSgjelinek "set scheduling-class=", 328f4b3ec61Sdh155122 "set ip-type=", 3290209230bSgjelinek "set " ALIAS_MAXLWPS "=", 3300209230bSgjelinek "set " ALIAS_MAXSHMMEM "=", 3310209230bSgjelinek "set " ALIAS_MAXSHMIDS "=", 3320209230bSgjelinek "set " ALIAS_MAXMSGIDS "=", 3330209230bSgjelinek "set " ALIAS_MAXSEMIDS "=", 3340209230bSgjelinek "set " ALIAS_SHARES "=", 3357c478bd9Sstevel@tonic-gate NULL 3367c478bd9Sstevel@tonic-gate }; 3377c478bd9Sstevel@tonic-gate 3389e7542f4Sdp static const char *info_cmds[] = { 3399e7542f4Sdp "info fs ", 3409e7542f4Sdp "info inherit-pkg-dir ", 3419e7542f4Sdp "info net ", 3429e7542f4Sdp "info device ", 3439e7542f4Sdp "info rctl ", 3449e7542f4Sdp "info attr ", 3459e7542f4Sdp "info dataset ", 3460209230bSgjelinek "info capped-memory", 3470209230bSgjelinek "info dedicated-cpu", 348c97ad5cdSakolb "info capped-cpu", 3499e7542f4Sdp "info zonename", 3509e7542f4Sdp "info zonepath", 3519e7542f4Sdp "info autoboot", 3529e7542f4Sdp "info pool", 3539e7542f4Sdp "info limitpriv", 3549e7542f4Sdp "info bootargs", 3550209230bSgjelinek "info brand", 3560209230bSgjelinek "info scheduling-class", 357f4b3ec61Sdh155122 "info ip-type", 3580209230bSgjelinek "info max-lwps", 3590209230bSgjelinek "info max-shm-memory", 3600209230bSgjelinek "info max-shm-ids", 3610209230bSgjelinek "info max-msg-ids", 3620209230bSgjelinek "info max-sem-ids", 3630209230bSgjelinek "info cpu-shares", 3649e7542f4Sdp NULL 3659e7542f4Sdp }; 3669e7542f4Sdp 3677c478bd9Sstevel@tonic-gate static const char *fs_res_scope_cmds[] = { 3687c478bd9Sstevel@tonic-gate "add options ", 3697c478bd9Sstevel@tonic-gate "cancel", 3707c478bd9Sstevel@tonic-gate "end", 3717c478bd9Sstevel@tonic-gate "exit", 3727c478bd9Sstevel@tonic-gate "help", 3737c478bd9Sstevel@tonic-gate "info", 374ffbafc53Scomay "remove options ", 3757c478bd9Sstevel@tonic-gate "set dir=", 3767c478bd9Sstevel@tonic-gate "set raw=", 3777c478bd9Sstevel@tonic-gate "set special=", 3787c478bd9Sstevel@tonic-gate "set type=", 3790209230bSgjelinek "clear raw", 3807c478bd9Sstevel@tonic-gate NULL 3817c478bd9Sstevel@tonic-gate }; 3827c478bd9Sstevel@tonic-gate 3837c478bd9Sstevel@tonic-gate static const char *net_res_scope_cmds[] = { 3847c478bd9Sstevel@tonic-gate "cancel", 3857c478bd9Sstevel@tonic-gate "end", 3867c478bd9Sstevel@tonic-gate "exit", 3877c478bd9Sstevel@tonic-gate "help", 3887c478bd9Sstevel@tonic-gate "info", 3897c478bd9Sstevel@tonic-gate "set address=", 3907c478bd9Sstevel@tonic-gate "set physical=", 3917c478bd9Sstevel@tonic-gate NULL 3927c478bd9Sstevel@tonic-gate }; 3937c478bd9Sstevel@tonic-gate 3947c478bd9Sstevel@tonic-gate static const char *ipd_res_scope_cmds[] = { 3957c478bd9Sstevel@tonic-gate "cancel", 3967c478bd9Sstevel@tonic-gate "end", 3977c478bd9Sstevel@tonic-gate "exit", 3987c478bd9Sstevel@tonic-gate "help", 3997c478bd9Sstevel@tonic-gate "info", 4007c478bd9Sstevel@tonic-gate "set dir=", 4017c478bd9Sstevel@tonic-gate NULL 4027c478bd9Sstevel@tonic-gate }; 4037c478bd9Sstevel@tonic-gate 4047c478bd9Sstevel@tonic-gate static const char *device_res_scope_cmds[] = { 4057c478bd9Sstevel@tonic-gate "cancel", 4067c478bd9Sstevel@tonic-gate "end", 4077c478bd9Sstevel@tonic-gate "exit", 4087c478bd9Sstevel@tonic-gate "help", 4097c478bd9Sstevel@tonic-gate "info", 4107c478bd9Sstevel@tonic-gate "set match=", 4117c478bd9Sstevel@tonic-gate NULL 4127c478bd9Sstevel@tonic-gate }; 4137c478bd9Sstevel@tonic-gate 4147c478bd9Sstevel@tonic-gate static const char *attr_res_scope_cmds[] = { 4157c478bd9Sstevel@tonic-gate "cancel", 4167c478bd9Sstevel@tonic-gate "end", 4177c478bd9Sstevel@tonic-gate "exit", 4187c478bd9Sstevel@tonic-gate "help", 4197c478bd9Sstevel@tonic-gate "info", 4207c478bd9Sstevel@tonic-gate "set name=", 4217c478bd9Sstevel@tonic-gate "set type=", 4227c478bd9Sstevel@tonic-gate "set value=", 4237c478bd9Sstevel@tonic-gate NULL 4247c478bd9Sstevel@tonic-gate }; 4257c478bd9Sstevel@tonic-gate 4267c478bd9Sstevel@tonic-gate static const char *rctl_res_scope_cmds[] = { 4277c478bd9Sstevel@tonic-gate "add value ", 4287c478bd9Sstevel@tonic-gate "cancel", 4297c478bd9Sstevel@tonic-gate "end", 4307c478bd9Sstevel@tonic-gate "exit", 4317c478bd9Sstevel@tonic-gate "help", 4327c478bd9Sstevel@tonic-gate "info", 433ffbafc53Scomay "remove value ", 4347c478bd9Sstevel@tonic-gate "set name=", 4357c478bd9Sstevel@tonic-gate NULL 4367c478bd9Sstevel@tonic-gate }; 4377c478bd9Sstevel@tonic-gate 438fa9e4066Sahrens static const char *dataset_res_scope_cmds[] = { 439fa9e4066Sahrens "cancel", 440fa9e4066Sahrens "end", 441fa9e4066Sahrens "exit", 442fa9e4066Sahrens "help", 443fa9e4066Sahrens "info", 444fa9e4066Sahrens "set name=", 445fa9e4066Sahrens NULL 446fa9e4066Sahrens }; 447fa9e4066Sahrens 4480209230bSgjelinek static const char *pset_res_scope_cmds[] = { 4490209230bSgjelinek "cancel", 4500209230bSgjelinek "end", 4510209230bSgjelinek "exit", 4520209230bSgjelinek "help", 4530209230bSgjelinek "info", 4540209230bSgjelinek "set ncpus=", 4550209230bSgjelinek "set importance=", 4560209230bSgjelinek "clear importance", 4570209230bSgjelinek NULL 4580209230bSgjelinek }; 4590209230bSgjelinek 460c97ad5cdSakolb static const char *pcap_res_scope_cmds[] = { 461c97ad5cdSakolb "cancel", 462c97ad5cdSakolb "end", 463c97ad5cdSakolb "exit", 464c97ad5cdSakolb "help", 465c97ad5cdSakolb "info", 466c97ad5cdSakolb "set ncpus=", 467c97ad5cdSakolb NULL 468c97ad5cdSakolb }; 469c97ad5cdSakolb 4700209230bSgjelinek static const char *mcap_res_scope_cmds[] = { 4710209230bSgjelinek "cancel", 4720209230bSgjelinek "end", 4730209230bSgjelinek "exit", 4740209230bSgjelinek "help", 4750209230bSgjelinek "info", 4760209230bSgjelinek "set physical=", 4770209230bSgjelinek "set swap=", 4780209230bSgjelinek "set locked=", 4790209230bSgjelinek "clear physical", 4800209230bSgjelinek "clear swap", 4810209230bSgjelinek "clear locked", 4820209230bSgjelinek NULL 4830209230bSgjelinek }; 4840209230bSgjelinek 4857c478bd9Sstevel@tonic-gate /* Global variables */ 4867c478bd9Sstevel@tonic-gate 4877c478bd9Sstevel@tonic-gate /* set early in main(), never modified thereafter, used all over the place */ 4887c478bd9Sstevel@tonic-gate static char *execname; 4897c478bd9Sstevel@tonic-gate 4907c478bd9Sstevel@tonic-gate /* set in main(), used all over the place */ 4917c478bd9Sstevel@tonic-gate static zone_dochandle_t handle; 4927c478bd9Sstevel@tonic-gate 4937c478bd9Sstevel@tonic-gate /* used all over the place */ 494087719fdSdp static char zone[ZONENAME_MAX]; 495087719fdSdp static char revert_zone[ZONENAME_MAX]; 4967c478bd9Sstevel@tonic-gate 4979acbbeafSnn35248 /* global brand operations */ 498123807fbSedp static brand_handle_t brand; 4999acbbeafSnn35248 5007c478bd9Sstevel@tonic-gate /* set in modifying functions, checked in read_input() */ 501bbec428eSgjelinek static boolean_t need_to_commit = B_FALSE; 502bbec428eSgjelinek boolean_t saw_error; 5037c478bd9Sstevel@tonic-gate 5047c478bd9Sstevel@tonic-gate /* set in yacc parser, checked in read_input() */ 505bbec428eSgjelinek boolean_t newline_terminated; 5067c478bd9Sstevel@tonic-gate 5077c478bd9Sstevel@tonic-gate /* set in main(), checked in lex error handler */ 508bbec428eSgjelinek boolean_t cmd_file_mode; 5097c478bd9Sstevel@tonic-gate 5107c478bd9Sstevel@tonic-gate /* set in exit_func(), checked in read_input() */ 511bbec428eSgjelinek static boolean_t time_to_exit = B_FALSE, force_exit = B_FALSE; 5127c478bd9Sstevel@tonic-gate 5137c478bd9Sstevel@tonic-gate /* used in short_usage() and zerr() */ 5147c478bd9Sstevel@tonic-gate static char *cmd_file_name = NULL; 5157c478bd9Sstevel@tonic-gate 5167c478bd9Sstevel@tonic-gate /* checked in read_input() and other places */ 517bbec428eSgjelinek static boolean_t ok_to_prompt = B_FALSE; 5187c478bd9Sstevel@tonic-gate 5197c478bd9Sstevel@tonic-gate /* set and checked in initialize() */ 520bbec428eSgjelinek static boolean_t got_handle = B_FALSE; 5217c478bd9Sstevel@tonic-gate 5227c478bd9Sstevel@tonic-gate /* initialized in do_interactive(), checked in initialize() */ 523bbec428eSgjelinek static boolean_t interactive_mode; 5247c478bd9Sstevel@tonic-gate 5250209230bSgjelinek /* set if configuring the global zone */ 526bbec428eSgjelinek static boolean_t global_zone = B_FALSE; 5270209230bSgjelinek 5287c478bd9Sstevel@tonic-gate /* set in main(), checked in multiple places */ 529bbec428eSgjelinek static boolean_t read_only_mode; 5307c478bd9Sstevel@tonic-gate 531bbec428eSgjelinek /* scope is outer/global or inner/resource */ 532bbec428eSgjelinek static boolean_t global_scope = B_TRUE; 5337c478bd9Sstevel@tonic-gate static int resource_scope; /* should be in the RT_ list from zonecfg.h */ 5347c478bd9Sstevel@tonic-gate static int end_op = -1; /* operation on end is either add or modify */ 5357c478bd9Sstevel@tonic-gate 5367c478bd9Sstevel@tonic-gate int num_prop_vals; /* for grammar */ 5377c478bd9Sstevel@tonic-gate 5387c478bd9Sstevel@tonic-gate /* 5397c478bd9Sstevel@tonic-gate * These are for keeping track of resources as they are specified as part of 5407c478bd9Sstevel@tonic-gate * the multi-step process. They should be initialized by add_resource() or 5417c478bd9Sstevel@tonic-gate * select_func() and filled in by add_property() or set_func(). 5427c478bd9Sstevel@tonic-gate */ 5437c478bd9Sstevel@tonic-gate static struct zone_fstab old_fstab, in_progress_fstab; 5447c478bd9Sstevel@tonic-gate static struct zone_fstab old_ipdtab, in_progress_ipdtab; 5457c478bd9Sstevel@tonic-gate static struct zone_nwiftab old_nwiftab, in_progress_nwiftab; 5467c478bd9Sstevel@tonic-gate static struct zone_devtab old_devtab, in_progress_devtab; 5477c478bd9Sstevel@tonic-gate static struct zone_rctltab old_rctltab, in_progress_rctltab; 5487c478bd9Sstevel@tonic-gate static struct zone_attrtab old_attrtab, in_progress_attrtab; 549fa9e4066Sahrens static struct zone_dstab old_dstab, in_progress_dstab; 5500209230bSgjelinek static struct zone_psettab old_psettab, in_progress_psettab; 5510209230bSgjelinek static struct zone_mcaptab old_mcaptab, in_progress_mcaptab; 5527c478bd9Sstevel@tonic-gate 5537c478bd9Sstevel@tonic-gate static GetLine *gl; /* The gl_get_line() resource object */ 5547c478bd9Sstevel@tonic-gate 5550209230bSgjelinek static void bytes_to_units(char *str, char *buf, int bufsize); 5560209230bSgjelinek 5577c478bd9Sstevel@tonic-gate /* Functions begin here */ 5587c478bd9Sstevel@tonic-gate 559bbec428eSgjelinek static boolean_t 5607c478bd9Sstevel@tonic-gate initial_match(const char *line1, const char *line2, int word_end) 5617c478bd9Sstevel@tonic-gate { 5627c478bd9Sstevel@tonic-gate if (word_end <= 0) 563bbec428eSgjelinek return (B_TRUE); 5647c478bd9Sstevel@tonic-gate return (strncmp(line1, line2, word_end) == 0); 5657c478bd9Sstevel@tonic-gate } 5667c478bd9Sstevel@tonic-gate 5677c478bd9Sstevel@tonic-gate static int 5687c478bd9Sstevel@tonic-gate add_stuff(WordCompletion *cpl, const char *line1, const char **list, 5697c478bd9Sstevel@tonic-gate int word_end) 5707c478bd9Sstevel@tonic-gate { 5717c478bd9Sstevel@tonic-gate int i, err; 5727c478bd9Sstevel@tonic-gate 5737c478bd9Sstevel@tonic-gate for (i = 0; list[i] != NULL; i++) { 5747c478bd9Sstevel@tonic-gate if (initial_match(line1, list[i], word_end)) { 5757c478bd9Sstevel@tonic-gate err = cpl_add_completion(cpl, line1, 0, word_end, 5767c478bd9Sstevel@tonic-gate list[i] + word_end, "", ""); 5777c478bd9Sstevel@tonic-gate if (err != 0) 5787c478bd9Sstevel@tonic-gate return (err); 5797c478bd9Sstevel@tonic-gate } 5807c478bd9Sstevel@tonic-gate } 5817c478bd9Sstevel@tonic-gate return (0); 5827c478bd9Sstevel@tonic-gate } 5837c478bd9Sstevel@tonic-gate 5847c478bd9Sstevel@tonic-gate static 5857c478bd9Sstevel@tonic-gate /* ARGSUSED */ 5867c478bd9Sstevel@tonic-gate CPL_MATCH_FN(cmd_cpl_fn) 5877c478bd9Sstevel@tonic-gate { 5887c478bd9Sstevel@tonic-gate if (global_scope) { 5897c478bd9Sstevel@tonic-gate /* 5907c478bd9Sstevel@tonic-gate * The MAX/MIN tests below are to make sure we have at least 5917c478bd9Sstevel@tonic-gate * enough characters to distinguish from other prefixes (MAX) 5927c478bd9Sstevel@tonic-gate * but only check MIN(what we have, what we're checking). 5937c478bd9Sstevel@tonic-gate */ 5947c478bd9Sstevel@tonic-gate if (strncmp(line, "add ", MAX(MIN(word_end, 4), 1)) == 0) 5957c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, add_cmds, word_end)); 5960209230bSgjelinek if (strncmp(line, "clear ", MAX(MIN(word_end, 6), 2)) == 0) 5970209230bSgjelinek return (add_stuff(cpl, line, clear_cmds, word_end)); 5987c478bd9Sstevel@tonic-gate if (strncmp(line, "select ", MAX(MIN(word_end, 7), 3)) == 0) 5997c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, select_cmds, word_end)); 6007c478bd9Sstevel@tonic-gate if (strncmp(line, "set ", MAX(MIN(word_end, 4), 3)) == 0) 6017c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, set_cmds, word_end)); 6029e7542f4Sdp if (strncmp(line, "remove ", MAX(MIN(word_end, 7), 1)) == 0) 6039e7542f4Sdp return (add_stuff(cpl, line, remove_cmds, word_end)); 6049e7542f4Sdp if (strncmp(line, "info ", MAX(MIN(word_end, 5), 1)) == 0) 6059e7542f4Sdp return (add_stuff(cpl, line, info_cmds, word_end)); 6067c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, global_scope_cmds, word_end)); 6077c478bd9Sstevel@tonic-gate } 6087c478bd9Sstevel@tonic-gate switch (resource_scope) { 6097c478bd9Sstevel@tonic-gate case RT_FS: 6107c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, fs_res_scope_cmds, word_end)); 6117c478bd9Sstevel@tonic-gate case RT_IPD: 6127c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, ipd_res_scope_cmds, word_end)); 6137c478bd9Sstevel@tonic-gate case RT_NET: 6147c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, net_res_scope_cmds, word_end)); 6157c478bd9Sstevel@tonic-gate case RT_DEVICE: 6167c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, device_res_scope_cmds, word_end)); 6177c478bd9Sstevel@tonic-gate case RT_RCTL: 6187c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, rctl_res_scope_cmds, word_end)); 6197c478bd9Sstevel@tonic-gate case RT_ATTR: 6207c478bd9Sstevel@tonic-gate return (add_stuff(cpl, line, attr_res_scope_cmds, word_end)); 621fa9e4066Sahrens case RT_DATASET: 622fa9e4066Sahrens return (add_stuff(cpl, line, dataset_res_scope_cmds, word_end)); 6230209230bSgjelinek case RT_DCPU: 6240209230bSgjelinek return (add_stuff(cpl, line, pset_res_scope_cmds, word_end)); 625c97ad5cdSakolb case RT_PCAP: 626c97ad5cdSakolb return (add_stuff(cpl, line, pcap_res_scope_cmds, word_end)); 6270209230bSgjelinek case RT_MCAP: 6280209230bSgjelinek return (add_stuff(cpl, line, mcap_res_scope_cmds, word_end)); 6297c478bd9Sstevel@tonic-gate } 6307c478bd9Sstevel@tonic-gate return (0); 6317c478bd9Sstevel@tonic-gate } 6327c478bd9Sstevel@tonic-gate 6337c478bd9Sstevel@tonic-gate /* 6347c478bd9Sstevel@tonic-gate * For the main CMD_func() functions below, several of them call getopt() 6357c478bd9Sstevel@tonic-gate * then check optind against argc to make sure an extra parameter was not 6367c478bd9Sstevel@tonic-gate * passed in. The reason this is not caught in the grammar is that the 6377c478bd9Sstevel@tonic-gate * grammar just checks for a miscellaneous TOKEN, which is *expected* to 6387c478bd9Sstevel@tonic-gate * be "-F" (for example), but could be anything. So (for example) this 6397c478bd9Sstevel@tonic-gate * check will prevent "create bogus". 6407c478bd9Sstevel@tonic-gate */ 6417c478bd9Sstevel@tonic-gate 6427c478bd9Sstevel@tonic-gate cmd_t * 6437c478bd9Sstevel@tonic-gate alloc_cmd(void) 6447c478bd9Sstevel@tonic-gate { 6457c478bd9Sstevel@tonic-gate return (calloc(1, sizeof (cmd_t))); 6467c478bd9Sstevel@tonic-gate } 6477c478bd9Sstevel@tonic-gate 6487c478bd9Sstevel@tonic-gate void 6497c478bd9Sstevel@tonic-gate free_cmd(cmd_t *cmd) 6507c478bd9Sstevel@tonic-gate { 6517c478bd9Sstevel@tonic-gate int i; 6527c478bd9Sstevel@tonic-gate 6537c478bd9Sstevel@tonic-gate for (i = 0; i < MAX_EQ_PROP_PAIRS; i++) 6547c478bd9Sstevel@tonic-gate if (cmd->cmd_property_ptr[i] != NULL) { 6557c478bd9Sstevel@tonic-gate property_value_ptr_t pp = cmd->cmd_property_ptr[i]; 6567c478bd9Sstevel@tonic-gate 6577c478bd9Sstevel@tonic-gate switch (pp->pv_type) { 6587c478bd9Sstevel@tonic-gate case PROP_VAL_SIMPLE: 6597c478bd9Sstevel@tonic-gate free(pp->pv_simple); 6607c478bd9Sstevel@tonic-gate break; 6617c478bd9Sstevel@tonic-gate case PROP_VAL_COMPLEX: 6627c478bd9Sstevel@tonic-gate free_complex(pp->pv_complex); 6637c478bd9Sstevel@tonic-gate break; 6647c478bd9Sstevel@tonic-gate case PROP_VAL_LIST: 6657c478bd9Sstevel@tonic-gate free_list(pp->pv_list); 6667c478bd9Sstevel@tonic-gate break; 6677c478bd9Sstevel@tonic-gate } 6687c478bd9Sstevel@tonic-gate } 6697c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_argc; i++) 6707c478bd9Sstevel@tonic-gate free(cmd->cmd_argv[i]); 6717c478bd9Sstevel@tonic-gate free(cmd); 6727c478bd9Sstevel@tonic-gate } 6737c478bd9Sstevel@tonic-gate 6747c478bd9Sstevel@tonic-gate complex_property_ptr_t 6757c478bd9Sstevel@tonic-gate alloc_complex(void) 6767c478bd9Sstevel@tonic-gate { 6777c478bd9Sstevel@tonic-gate return (calloc(1, sizeof (complex_property_t))); 6787c478bd9Sstevel@tonic-gate } 6797c478bd9Sstevel@tonic-gate 6807c478bd9Sstevel@tonic-gate void 6817c478bd9Sstevel@tonic-gate free_complex(complex_property_ptr_t complex) 6827c478bd9Sstevel@tonic-gate { 6837c478bd9Sstevel@tonic-gate if (complex == NULL) 6847c478bd9Sstevel@tonic-gate return; 6857c478bd9Sstevel@tonic-gate free_complex(complex->cp_next); 6867c478bd9Sstevel@tonic-gate if (complex->cp_value != NULL) 6877c478bd9Sstevel@tonic-gate free(complex->cp_value); 6887c478bd9Sstevel@tonic-gate free(complex); 6897c478bd9Sstevel@tonic-gate } 6907c478bd9Sstevel@tonic-gate 6917c478bd9Sstevel@tonic-gate list_property_ptr_t 6927c478bd9Sstevel@tonic-gate alloc_list(void) 6937c478bd9Sstevel@tonic-gate { 6947c478bd9Sstevel@tonic-gate return (calloc(1, sizeof (list_property_t))); 6957c478bd9Sstevel@tonic-gate } 6967c478bd9Sstevel@tonic-gate 6977c478bd9Sstevel@tonic-gate void 6987c478bd9Sstevel@tonic-gate free_list(list_property_ptr_t list) 6997c478bd9Sstevel@tonic-gate { 7007c478bd9Sstevel@tonic-gate if (list == NULL) 7017c478bd9Sstevel@tonic-gate return; 7027c478bd9Sstevel@tonic-gate if (list->lp_simple != NULL) 7037c478bd9Sstevel@tonic-gate free(list->lp_simple); 7047c478bd9Sstevel@tonic-gate free_complex(list->lp_complex); 7057c478bd9Sstevel@tonic-gate free_list(list->lp_next); 7067c478bd9Sstevel@tonic-gate free(list); 7077c478bd9Sstevel@tonic-gate } 7087c478bd9Sstevel@tonic-gate 7097c478bd9Sstevel@tonic-gate void 7107c478bd9Sstevel@tonic-gate free_outer_list(list_property_ptr_t list) 7117c478bd9Sstevel@tonic-gate { 7127c478bd9Sstevel@tonic-gate if (list == NULL) 7137c478bd9Sstevel@tonic-gate return; 7147c478bd9Sstevel@tonic-gate free_outer_list(list->lp_next); 7157c478bd9Sstevel@tonic-gate free(list); 7167c478bd9Sstevel@tonic-gate } 7177c478bd9Sstevel@tonic-gate 7187c478bd9Sstevel@tonic-gate static struct zone_rctlvaltab * 7197c478bd9Sstevel@tonic-gate alloc_rctlvaltab(void) 7207c478bd9Sstevel@tonic-gate { 7217c478bd9Sstevel@tonic-gate return (calloc(1, sizeof (struct zone_rctlvaltab))); 7227c478bd9Sstevel@tonic-gate } 7237c478bd9Sstevel@tonic-gate 7247c478bd9Sstevel@tonic-gate static char * 7257c478bd9Sstevel@tonic-gate rt_to_str(int res_type) 7267c478bd9Sstevel@tonic-gate { 7277c478bd9Sstevel@tonic-gate assert(res_type >= RT_MIN && res_type <= RT_MAX); 7287c478bd9Sstevel@tonic-gate return (res_types[res_type]); 7297c478bd9Sstevel@tonic-gate } 7307c478bd9Sstevel@tonic-gate 7317c478bd9Sstevel@tonic-gate static char * 7327c478bd9Sstevel@tonic-gate pt_to_str(int prop_type) 7337c478bd9Sstevel@tonic-gate { 7347c478bd9Sstevel@tonic-gate assert(prop_type >= PT_MIN && prop_type <= PT_MAX); 7357c478bd9Sstevel@tonic-gate return (prop_types[prop_type]); 7367c478bd9Sstevel@tonic-gate } 7377c478bd9Sstevel@tonic-gate 7387c478bd9Sstevel@tonic-gate static char * 7397c478bd9Sstevel@tonic-gate pvt_to_str(int pv_type) 7407c478bd9Sstevel@tonic-gate { 7417c478bd9Sstevel@tonic-gate assert(pv_type >= PROP_VAL_MIN && pv_type <= PROP_VAL_MAX); 7427c478bd9Sstevel@tonic-gate return (prop_val_types[pv_type]); 7437c478bd9Sstevel@tonic-gate } 7447c478bd9Sstevel@tonic-gate 7457c478bd9Sstevel@tonic-gate static char * 7467c478bd9Sstevel@tonic-gate cmd_to_str(int cmd_num) 7477c478bd9Sstevel@tonic-gate { 7487c478bd9Sstevel@tonic-gate assert(cmd_num >= CMD_MIN && cmd_num <= CMD_MAX); 7497c478bd9Sstevel@tonic-gate return (helptab[cmd_num].cmd_name); 7507c478bd9Sstevel@tonic-gate } 7517c478bd9Sstevel@tonic-gate 7527c478bd9Sstevel@tonic-gate /* 7537c478bd9Sstevel@tonic-gate * This is a separate function rather than a set of define's because of the 7547c478bd9Sstevel@tonic-gate * gettext() wrapping. 7557c478bd9Sstevel@tonic-gate */ 7567c478bd9Sstevel@tonic-gate 7577c478bd9Sstevel@tonic-gate /* 7587c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE 7597c478bd9Sstevel@tonic-gate * Each string below should have \t follow \n whenever needed; the 7607c478bd9Sstevel@tonic-gate * initial \t and the terminal \n will be provided by the calling function. 7617c478bd9Sstevel@tonic-gate */ 7627c478bd9Sstevel@tonic-gate 7637c478bd9Sstevel@tonic-gate static char * 7647c478bd9Sstevel@tonic-gate long_help(int cmd_num) 7657c478bd9Sstevel@tonic-gate { 7667c478bd9Sstevel@tonic-gate static char line[1024]; /* arbitrary large amount */ 7677c478bd9Sstevel@tonic-gate 7687c478bd9Sstevel@tonic-gate assert(cmd_num >= CMD_MIN && cmd_num <= CMD_MAX); 7697c478bd9Sstevel@tonic-gate switch (cmd_num) { 7707c478bd9Sstevel@tonic-gate case CMD_HELP: 7717c478bd9Sstevel@tonic-gate return (gettext("Prints help message.")); 7727c478bd9Sstevel@tonic-gate case CMD_CREATE: 7737c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), 7747c478bd9Sstevel@tonic-gate gettext("Creates a configuration for the " 7757c478bd9Sstevel@tonic-gate "specified zone. %s should be\n\tused to " 7767c478bd9Sstevel@tonic-gate "begin configuring a new zone. If overwriting an " 7777c478bd9Sstevel@tonic-gate "existing\n\tconfiguration, the -F flag can be " 7787c478bd9Sstevel@tonic-gate "used to force the action. If\n\t-t template is " 7797c478bd9Sstevel@tonic-gate "given, creates a configuration identical to the\n" 7807c478bd9Sstevel@tonic-gate "\tspecified template, except that the zone name " 7819e518655Sgjelinek "is changed from\n\ttemplate to zonename. '%s -a' " 7829e518655Sgjelinek "creates a configuration from a\n\tdetached " 7839e518655Sgjelinek "zonepath. '%s -b' results in a blank " 7849e518655Sgjelinek "configuration.\n\t'%s' with no arguments applies " 7859e518655Sgjelinek "the Sun default settings."), 7867c478bd9Sstevel@tonic-gate cmd_to_str(CMD_CREATE), cmd_to_str(CMD_CREATE), 7879e518655Sgjelinek cmd_to_str(CMD_CREATE), cmd_to_str(CMD_CREATE)); 7887c478bd9Sstevel@tonic-gate return (line); 7897c478bd9Sstevel@tonic-gate case CMD_EXIT: 7907c478bd9Sstevel@tonic-gate return (gettext("Exits the program. The -F flag can " 7917c478bd9Sstevel@tonic-gate "be used to force the action.")); 7927c478bd9Sstevel@tonic-gate case CMD_EXPORT: 7937c478bd9Sstevel@tonic-gate return (gettext("Prints configuration to standard " 7947c478bd9Sstevel@tonic-gate "output, or to output-file if\n\tspecified, in " 7957c478bd9Sstevel@tonic-gate "a form suitable for use in a command-file.")); 7967c478bd9Sstevel@tonic-gate case CMD_ADD: 7977c478bd9Sstevel@tonic-gate return (gettext("Add specified resource to " 7987c478bd9Sstevel@tonic-gate "configuration.")); 7997c478bd9Sstevel@tonic-gate case CMD_DELETE: 8007c478bd9Sstevel@tonic-gate return (gettext("Deletes the specified zone. The -F " 8017c478bd9Sstevel@tonic-gate "flag can be used to force the\n\taction.")); 8027c478bd9Sstevel@tonic-gate case CMD_REMOVE: 8037c478bd9Sstevel@tonic-gate return (gettext("Remove specified resource from " 8040209230bSgjelinek "configuration. The -F flag can be used\n\tto " 8050209230bSgjelinek "force the action.")); 8067c478bd9Sstevel@tonic-gate case CMD_SELECT: 8077c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), 8087c478bd9Sstevel@tonic-gate gettext("Selects a resource to modify. " 8097c478bd9Sstevel@tonic-gate "Resource modification is completed\n\twith the " 8107c478bd9Sstevel@tonic-gate "command \"%s\". The property name/value pairs " 8117c478bd9Sstevel@tonic-gate "must uniquely\n\tidentify a resource. Note that " 8127c478bd9Sstevel@tonic-gate "the curly braces ('{', '}') mean one\n\tor more " 8137c478bd9Sstevel@tonic-gate "of whatever is between them."), 8147c478bd9Sstevel@tonic-gate cmd_to_str(CMD_END)); 8157c478bd9Sstevel@tonic-gate return (line); 8167c478bd9Sstevel@tonic-gate case CMD_SET: 8177c478bd9Sstevel@tonic-gate return (gettext("Sets property values.")); 8180209230bSgjelinek case CMD_CLEAR: 8190209230bSgjelinek return (gettext("Clears property values.")); 8207c478bd9Sstevel@tonic-gate case CMD_INFO: 8217c478bd9Sstevel@tonic-gate return (gettext("Displays information about the " 8227c478bd9Sstevel@tonic-gate "current configuration. If resource\n\ttype is " 8237c478bd9Sstevel@tonic-gate "specified, displays only information about " 8247c478bd9Sstevel@tonic-gate "resources of\n\tthe relevant type. If resource " 8257c478bd9Sstevel@tonic-gate "id is specified, displays only\n\tinformation " 8267c478bd9Sstevel@tonic-gate "about that resource.")); 8277c478bd9Sstevel@tonic-gate case CMD_VERIFY: 8287c478bd9Sstevel@tonic-gate return (gettext("Verifies current configuration " 8297c478bd9Sstevel@tonic-gate "for correctness (some resource types\n\thave " 8307c478bd9Sstevel@tonic-gate "required properties).")); 8317c478bd9Sstevel@tonic-gate case CMD_COMMIT: 8327c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), 8337c478bd9Sstevel@tonic-gate gettext("Commits current configuration. " 8347c478bd9Sstevel@tonic-gate "Configuration must be committed to\n\tbe used by " 8357c478bd9Sstevel@tonic-gate "%s. Until the configuration is committed, " 8367c478bd9Sstevel@tonic-gate "changes \n\tcan be removed with the %s " 8377c478bd9Sstevel@tonic-gate "command. This operation is\n\tattempted " 8387c478bd9Sstevel@tonic-gate "automatically upon completion of a %s " 8397c478bd9Sstevel@tonic-gate "session."), "zoneadm", cmd_to_str(CMD_REVERT), 8407c478bd9Sstevel@tonic-gate "zonecfg"); 8417c478bd9Sstevel@tonic-gate return (line); 8427c478bd9Sstevel@tonic-gate case CMD_REVERT: 8437c478bd9Sstevel@tonic-gate return (gettext("Reverts configuration back to the " 8447c478bd9Sstevel@tonic-gate "last committed state. The -F flag\n\tcan be " 8457c478bd9Sstevel@tonic-gate "used to force the action.")); 8467c478bd9Sstevel@tonic-gate case CMD_CANCEL: 8477c478bd9Sstevel@tonic-gate return (gettext("Cancels resource/property " 8487c478bd9Sstevel@tonic-gate "specification.")); 8497c478bd9Sstevel@tonic-gate case CMD_END: 8507c478bd9Sstevel@tonic-gate return (gettext("Ends resource/property " 8517c478bd9Sstevel@tonic-gate "specification.")); 8527c478bd9Sstevel@tonic-gate } 8537c478bd9Sstevel@tonic-gate /* NOTREACHED */ 8547e362f58Scomay return (NULL); 8557c478bd9Sstevel@tonic-gate } 8567c478bd9Sstevel@tonic-gate 8577c478bd9Sstevel@tonic-gate /* 8587c478bd9Sstevel@tonic-gate * Called with verbose TRUE when help is explicitly requested, FALSE for 8597c478bd9Sstevel@tonic-gate * unexpected errors. 8607c478bd9Sstevel@tonic-gate */ 8617c478bd9Sstevel@tonic-gate 8627c478bd9Sstevel@tonic-gate void 863bbec428eSgjelinek usage(boolean_t verbose, uint_t flags) 8647c478bd9Sstevel@tonic-gate { 8657c478bd9Sstevel@tonic-gate FILE *fp = verbose ? stdout : stderr, *newfp; 866bbec428eSgjelinek boolean_t need_to_close = B_FALSE; 8677c478bd9Sstevel@tonic-gate char *pager; 8687c478bd9Sstevel@tonic-gate int i; 8697c478bd9Sstevel@tonic-gate 8707c478bd9Sstevel@tonic-gate /* don't page error output */ 8717c478bd9Sstevel@tonic-gate if (verbose && interactive_mode) { 8727c478bd9Sstevel@tonic-gate if ((pager = getenv("PAGER")) == NULL) 8737c478bd9Sstevel@tonic-gate pager = PAGER; 8747c478bd9Sstevel@tonic-gate if ((newfp = popen(pager, "w")) != NULL) { 875bbec428eSgjelinek need_to_close = B_TRUE; 8767c478bd9Sstevel@tonic-gate fp = newfp; 8777c478bd9Sstevel@tonic-gate } 8787c478bd9Sstevel@tonic-gate } 8797c478bd9Sstevel@tonic-gate if (flags & HELP_META) { 8807c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("More help is available for the " 8817c478bd9Sstevel@tonic-gate "following:\n")); 8827c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\n\tcommands ('%s commands')\n", 8837c478bd9Sstevel@tonic-gate cmd_to_str(CMD_HELP)); 8847c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\tsyntax ('%s syntax')\n", 8857c478bd9Sstevel@tonic-gate cmd_to_str(CMD_HELP)); 8867c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\tusage ('%s usage')\n\n", 8877c478bd9Sstevel@tonic-gate cmd_to_str(CMD_HELP)); 8887c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("You may also obtain help on any " 8897c478bd9Sstevel@tonic-gate "command by typing '%s <command-name>.'\n"), 8907c478bd9Sstevel@tonic-gate cmd_to_str(CMD_HELP)); 8917c478bd9Sstevel@tonic-gate } 8927c478bd9Sstevel@tonic-gate if (flags & HELP_RES_SCOPE) { 8937c478bd9Sstevel@tonic-gate switch (resource_scope) { 8947c478bd9Sstevel@tonic-gate case RT_FS: 8957c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is " 8967c478bd9Sstevel@tonic-gate "used to configure a file-system.\n"), 8977c478bd9Sstevel@tonic-gate rt_to_str(resource_scope)); 8987c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n")); 8997c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 9007c478bd9Sstevel@tonic-gate pt_to_str(PT_DIR), gettext("<path>")); 9017c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 9027c478bd9Sstevel@tonic-gate pt_to_str(PT_SPECIAL), gettext("<path>")); 9037c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 9047c478bd9Sstevel@tonic-gate pt_to_str(PT_RAW), gettext("<raw-device>")); 9057c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 9067c478bd9Sstevel@tonic-gate pt_to_str(PT_TYPE), gettext("<file-system type>")); 9077c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s %s\n", cmd_to_str(CMD_ADD), 9087c478bd9Sstevel@tonic-gate pt_to_str(PT_OPTIONS), 9097c478bd9Sstevel@tonic-gate gettext("<file-system options>")); 910ffbafc53Scomay (void) fprintf(fp, "\t%s %s %s\n", 911ffbafc53Scomay cmd_to_str(CMD_REMOVE), pt_to_str(PT_OPTIONS), 912ffbafc53Scomay gettext("<file-system options>")); 9137c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Consult the file-system " 9147c478bd9Sstevel@tonic-gate "specific manual page, such as mount_ufs(1M), " 9157c478bd9Sstevel@tonic-gate "for\ndetails about file-system options. Note " 9167c478bd9Sstevel@tonic-gate "that any file-system options with an\nembedded " 9177c478bd9Sstevel@tonic-gate "'=' character must be enclosed in double quotes, " 9187c478bd9Sstevel@tonic-gate /*CSTYLED*/ 9197c478bd9Sstevel@tonic-gate "such as \"%s=5\".\n"), MNTOPT_RETRY); 9207c478bd9Sstevel@tonic-gate break; 9217c478bd9Sstevel@tonic-gate case RT_IPD: 9227c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is " 9237c478bd9Sstevel@tonic-gate "used to configure a directory\ninherited from the " 9247c478bd9Sstevel@tonic-gate "global zone into a non-global zone in read-only " 9257c478bd9Sstevel@tonic-gate "mode.\n"), rt_to_str(resource_scope)); 9267c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n")); 9277c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 9287c478bd9Sstevel@tonic-gate pt_to_str(PT_DIR), gettext("<path>")); 9297c478bd9Sstevel@tonic-gate break; 9307c478bd9Sstevel@tonic-gate case RT_NET: 9317c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is " 9327c478bd9Sstevel@tonic-gate "used to configure a network interface.\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_ADDRESS), gettext("<IP-address>")); 9377c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 9387c478bd9Sstevel@tonic-gate pt_to_str(PT_PHYSICAL), gettext("<interface>")); 9397c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("See ifconfig(1M) for " 9407c478bd9Sstevel@tonic-gate "details of the <interface> string.\n")); 941de860bd9Sgfaden (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 942de860bd9Sgfaden pt_to_str(PT_DEFROUTER), gettext("<IP-address>")); 943de860bd9Sgfaden (void) fprintf(fp, gettext("%s %s and %s %s are valid " 944de860bd9Sgfaden "if the %s property is set to %s, otherwise they " 945de860bd9Sgfaden "must not be set.\n"), 946f4b3ec61Sdh155122 cmd_to_str(CMD_SET), pt_to_str(PT_ADDRESS), 947de860bd9Sgfaden cmd_to_str(CMD_SET), pt_to_str(PT_DEFROUTER), 948f4b3ec61Sdh155122 pt_to_str(PT_IPTYPE), "shared"); 9497c478bd9Sstevel@tonic-gate break; 9507c478bd9Sstevel@tonic-gate case RT_DEVICE: 9517c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is " 9527c478bd9Sstevel@tonic-gate "used to configure a device node.\n"), 9537c478bd9Sstevel@tonic-gate rt_to_str(resource_scope)); 9547c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n")); 9557c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 9567c478bd9Sstevel@tonic-gate pt_to_str(PT_MATCH), gettext("<device-path>")); 9577c478bd9Sstevel@tonic-gate break; 9587c478bd9Sstevel@tonic-gate case RT_RCTL: 9597c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is " 9607c478bd9Sstevel@tonic-gate "used to configure a resource control.\n"), 9617c478bd9Sstevel@tonic-gate 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_NAME), gettext("<string>")); 9657c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s (%s=%s,%s=%s,%s=%s)\n", 9667c478bd9Sstevel@tonic-gate cmd_to_str(CMD_ADD), pt_to_str(PT_VALUE), 9677c478bd9Sstevel@tonic-gate pt_to_str(PT_PRIV), gettext("<priv-value>"), 9687c478bd9Sstevel@tonic-gate pt_to_str(PT_LIMIT), gettext("<number>"), 9697c478bd9Sstevel@tonic-gate pt_to_str(PT_ACTION), gettext("<action-value>")); 970ffbafc53Scomay (void) fprintf(fp, "\t%s %s (%s=%s,%s=%s,%s=%s)\n", 971ffbafc53Scomay cmd_to_str(CMD_REMOVE), pt_to_str(PT_VALUE), 972ffbafc53Scomay pt_to_str(PT_PRIV), gettext("<priv-value>"), 973ffbafc53Scomay pt_to_str(PT_LIMIT), gettext("<number>"), 974ffbafc53Scomay pt_to_str(PT_ACTION), gettext("<action-value>")); 9757c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s\n\t%s := privileged\n" 9767c478bd9Sstevel@tonic-gate "\t%s := none | deny\n", gettext("Where"), 9777c478bd9Sstevel@tonic-gate gettext("<priv-value>"), gettext("<action-value>")); 9787c478bd9Sstevel@tonic-gate break; 9797c478bd9Sstevel@tonic-gate case RT_ATTR: 9807c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("The '%s' resource scope is " 9817c478bd9Sstevel@tonic-gate "used to configure a generic attribute.\n"), 9827c478bd9Sstevel@tonic-gate rt_to_str(resource_scope)); 9837c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("Valid commands:\n")); 9847c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 9857c478bd9Sstevel@tonic-gate pt_to_str(PT_NAME), gettext("<name>")); 9867c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=boolean\n", 9877c478bd9Sstevel@tonic-gate cmd_to_str(CMD_SET), pt_to_str(PT_TYPE)); 9887c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=true | false\n", 9897c478bd9Sstevel@tonic-gate cmd_to_str(CMD_SET), pt_to_str(PT_VALUE)); 9907c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("or\n")); 9917c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=int\n", cmd_to_str(CMD_SET), 9927c478bd9Sstevel@tonic-gate pt_to_str(PT_TYPE)); 9937c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 9947c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE), gettext("<integer>")); 9957c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("or\n")); 9967c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=string\n", 9977c478bd9Sstevel@tonic-gate cmd_to_str(CMD_SET), pt_to_str(PT_TYPE)); 9987c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 9997c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE), gettext("<string>")); 10007c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("or\n")); 10017c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=uint\n", 10027c478bd9Sstevel@tonic-gate cmd_to_str(CMD_SET), pt_to_str(PT_TYPE)); 10037c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 10047c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE), gettext("<unsigned integer>")); 10057c478bd9Sstevel@tonic-gate break; 1006fa9e4066Sahrens case RT_DATASET: 1007fa9e4066Sahrens (void) fprintf(fp, gettext("The '%s' resource scope is " 1008fa9e4066Sahrens "used to export ZFS datasets.\n"), 1009fa9e4066Sahrens rt_to_str(resource_scope)); 1010fa9e4066Sahrens (void) fprintf(fp, gettext("Valid commands:\n")); 1011fa9e4066Sahrens (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 1012fa9e4066Sahrens pt_to_str(PT_NAME), gettext("<name>")); 1013fa9e4066Sahrens break; 10140209230bSgjelinek case RT_DCPU: 10150209230bSgjelinek (void) fprintf(fp, gettext("The '%s' resource scope " 10160209230bSgjelinek "configures the 'pools' facility to dedicate\na " 10170209230bSgjelinek "subset of the system's processors to this zone " 10180209230bSgjelinek "while it is running.\n"), 10190209230bSgjelinek rt_to_str(resource_scope)); 10200209230bSgjelinek (void) fprintf(fp, gettext("Valid commands:\n")); 10210209230bSgjelinek (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 10220209230bSgjelinek pt_to_str(PT_NCPUS), 10230209230bSgjelinek gettext("<unsigned integer | range>")); 10240209230bSgjelinek (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 10250209230bSgjelinek pt_to_str(PT_IMPORTANCE), 10260209230bSgjelinek gettext("<unsigned integer>")); 10270209230bSgjelinek break; 1028c97ad5cdSakolb case RT_PCAP: 1029c97ad5cdSakolb (void) fprintf(fp, gettext("The '%s' resource scope is " 1030c97ad5cdSakolb "used to set an upper limit (a cap) on the\n" 1031c97ad5cdSakolb "percentage of CPU that can be used by this zone. " 1032c97ad5cdSakolb "A '%s' value of 1\ncorresponds to one cpu. The " 1033c97ad5cdSakolb "value can be set higher than 1, up to the total\n" 1034c97ad5cdSakolb "number of CPUs on the system. The value can " 1035c97ad5cdSakolb "also be less than 1,\nrepresenting a fraction of " 1036c97ad5cdSakolb "a cpu.\n"), 1037c97ad5cdSakolb rt_to_str(resource_scope), pt_to_str(PT_NCPUS)); 1038c97ad5cdSakolb (void) fprintf(fp, gettext("Valid commands:\n")); 1039c97ad5cdSakolb (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 1040c97ad5cdSakolb pt_to_str(PT_NCPUS), gettext("<unsigned decimal>")); 1041c97ad5cdSakolb break; 10420209230bSgjelinek case RT_MCAP: 10430209230bSgjelinek (void) fprintf(fp, gettext("The '%s' resource scope is " 10440209230bSgjelinek "used to set an upper limit (a cap) on the\n" 10450209230bSgjelinek "amount of physical memory, swap space and locked " 10460209230bSgjelinek "memory that can be used by\nthis zone.\n"), 10470209230bSgjelinek rt_to_str(resource_scope)); 10480209230bSgjelinek (void) fprintf(fp, gettext("Valid commands:\n")); 10490209230bSgjelinek (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 10500209230bSgjelinek pt_to_str(PT_PHYSICAL), 10510209230bSgjelinek gettext("<qualified unsigned decimal>")); 10520209230bSgjelinek (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 10530209230bSgjelinek pt_to_str(PT_SWAP), 10540209230bSgjelinek gettext("<qualified unsigned decimal>")); 10550209230bSgjelinek (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET), 10560209230bSgjelinek pt_to_str(PT_LOCKED), 10570209230bSgjelinek gettext("<qualified unsigned decimal>")); 10580209230bSgjelinek break; 10597c478bd9Sstevel@tonic-gate } 10607c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("And from any resource scope, you " 10617c478bd9Sstevel@tonic-gate "can:\n")); 10627c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", cmd_to_str(CMD_END), 10637c478bd9Sstevel@tonic-gate gettext("(to conclude this operation)")); 10647c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", cmd_to_str(CMD_CANCEL), 10657c478bd9Sstevel@tonic-gate gettext("(to cancel this operation)")); 10667c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", cmd_to_str(CMD_EXIT), 10677c478bd9Sstevel@tonic-gate gettext("(to exit the zonecfg utility)")); 10687c478bd9Sstevel@tonic-gate } 10697c478bd9Sstevel@tonic-gate if (flags & HELP_USAGE) { 10707c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\t%s %s\n", gettext("usage"), 10717c478bd9Sstevel@tonic-gate execname, cmd_to_str(CMD_HELP)); 10727c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s -z <zone>\t\t\t(%s)\n", 10737c478bd9Sstevel@tonic-gate execname, gettext("interactive")); 10747c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s -z <zone> <command>\n", execname); 10757c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s -z <zone> -f <command-file>\n", 10767c478bd9Sstevel@tonic-gate execname); 10777c478bd9Sstevel@tonic-gate } 10787c478bd9Sstevel@tonic-gate if (flags & HELP_SUBCMDS) { 10797c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n\n", gettext("Commands")); 10807c478bd9Sstevel@tonic-gate for (i = 0; i <= CMD_MAX; i++) { 10817c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s\n", helptab[i].short_usage); 10827c478bd9Sstevel@tonic-gate if (verbose) 10837c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\n\n", long_help(i)); 10847c478bd9Sstevel@tonic-gate } 10857c478bd9Sstevel@tonic-gate } 10867c478bd9Sstevel@tonic-gate if (flags & HELP_SYNTAX) { 10877c478bd9Sstevel@tonic-gate if (!verbose) 10887c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\n"); 10897c478bd9Sstevel@tonic-gate (void) fprintf(fp, "<zone> := [A-Za-z0-9][A-Za-z0-9_.-]*\n"); 10907c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("\t(except the reserved words " 10917c478bd9Sstevel@tonic-gate "'%s' and anything starting with '%s')\n"), "global", 10927c478bd9Sstevel@tonic-gate "SUNW"); 10937c478bd9Sstevel@tonic-gate (void) fprintf(fp, 10947c478bd9Sstevel@tonic-gate gettext("\tName must be less than %d characters.\n"), 10957c478bd9Sstevel@tonic-gate ZONENAME_MAX); 10967c478bd9Sstevel@tonic-gate if (verbose) 10977c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\n"); 10987c478bd9Sstevel@tonic-gate } 10997c478bd9Sstevel@tonic-gate if (flags & HELP_NETADDR) { 11007c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("\n<net-addr> :=")); 11017c478bd9Sstevel@tonic-gate (void) fprintf(fp, 11027c478bd9Sstevel@tonic-gate gettext("\t<IPv4-address>[/<IPv4-prefix-length>] |\n")); 11037c478bd9Sstevel@tonic-gate (void) fprintf(fp, 11047c478bd9Sstevel@tonic-gate gettext("\t\t<IPv6-address>/<IPv6-prefix-length> |\n")); 11057c478bd9Sstevel@tonic-gate (void) fprintf(fp, 11067c478bd9Sstevel@tonic-gate gettext("\t\t<hostname>[/<IPv4-prefix-length>]\n")); 11077c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("See inet(3SOCKET) for IPv4 and " 11087c478bd9Sstevel@tonic-gate "IPv6 address syntax.\n")); 11097c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("<IPv4-prefix-length> := [0-32]\n")); 11107c478bd9Sstevel@tonic-gate (void) fprintf(fp, 11117c478bd9Sstevel@tonic-gate gettext("<IPv6-prefix-length> := [0-128]\n")); 11127c478bd9Sstevel@tonic-gate (void) fprintf(fp, 11137c478bd9Sstevel@tonic-gate gettext("<hostname> := [A-Za-z0-9][A-Za-z0-9-.]*\n")); 11147c478bd9Sstevel@tonic-gate } 11157c478bd9Sstevel@tonic-gate if (flags & HELP_RESOURCES) { 11169e7542f4Sdp (void) fprintf(fp, "<%s> := %s | %s | %s | %s | %s | %s |\n\t" 1117c97ad5cdSakolb "%s | %s | %s | %s\n\n", 11187c478bd9Sstevel@tonic-gate gettext("resource type"), rt_to_str(RT_FS), 11197c478bd9Sstevel@tonic-gate rt_to_str(RT_IPD), rt_to_str(RT_NET), rt_to_str(RT_DEVICE), 11209e7542f4Sdp rt_to_str(RT_RCTL), rt_to_str(RT_ATTR), 11210209230bSgjelinek rt_to_str(RT_DATASET), rt_to_str(RT_DCPU), 1122c97ad5cdSakolb rt_to_str(RT_PCAP), rt_to_str(RT_MCAP)); 11237c478bd9Sstevel@tonic-gate } 11247c478bd9Sstevel@tonic-gate if (flags & HELP_PROPS) { 11257c478bd9Sstevel@tonic-gate (void) fprintf(fp, gettext("For resource type ... there are " 11267c478bd9Sstevel@tonic-gate "property types ...:\n")); 11277c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 1128087719fdSdp pt_to_str(PT_ZONENAME)); 1129087719fdSdp (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11307c478bd9Sstevel@tonic-gate pt_to_str(PT_ZONEPATH)); 11317c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11329acbbeafSnn35248 pt_to_str(PT_BRAND)); 11339acbbeafSnn35248 (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11347c478bd9Sstevel@tonic-gate pt_to_str(PT_AUTOBOOT)); 11357c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11363f2f09c1Sdp pt_to_str(PT_BOOTARGS)); 11373f2f09c1Sdp (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11387c478bd9Sstevel@tonic-gate pt_to_str(PT_POOL)); 1139ffbafc53Scomay (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 1140ffbafc53Scomay pt_to_str(PT_LIMITPRIV)); 11410209230bSgjelinek (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11420209230bSgjelinek pt_to_str(PT_SCHED)); 11430209230bSgjelinek (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 1144f4b3ec61Sdh155122 pt_to_str(PT_IPTYPE)); 1145f4b3ec61Sdh155122 (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11460209230bSgjelinek pt_to_str(PT_MAXLWPS)); 11470209230bSgjelinek (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11480209230bSgjelinek pt_to_str(PT_MAXSHMMEM)); 11490209230bSgjelinek (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11500209230bSgjelinek pt_to_str(PT_MAXSHMIDS)); 11510209230bSgjelinek (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11520209230bSgjelinek pt_to_str(PT_MAXMSGIDS)); 11530209230bSgjelinek (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11540209230bSgjelinek pt_to_str(PT_MAXSEMIDS)); 11550209230bSgjelinek (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"), 11560209230bSgjelinek pt_to_str(PT_SHARES)); 11577c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t\t%s, %s, %s, %s\n", rt_to_str(RT_FS), 11587c478bd9Sstevel@tonic-gate pt_to_str(PT_DIR), pt_to_str(PT_SPECIAL), 11597c478bd9Sstevel@tonic-gate pt_to_str(PT_RAW), pt_to_str(PT_TYPE), 11607c478bd9Sstevel@tonic-gate pt_to_str(PT_OPTIONS)); 11617c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t%s\n", rt_to_str(RT_IPD), 11627c478bd9Sstevel@tonic-gate pt_to_str(PT_DIR)); 1163de860bd9Sgfaden (void) fprintf(fp, "\t%s\t\t%s, %s, %s\n", rt_to_str(RT_NET), 1164de860bd9Sgfaden pt_to_str(PT_ADDRESS), pt_to_str(PT_PHYSICAL), 1165de860bd9Sgfaden pt_to_str(PT_DEFROUTER)); 11667c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t\t%s\n", rt_to_str(RT_DEVICE), 11677c478bd9Sstevel@tonic-gate pt_to_str(PT_MATCH)); 11687c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t\t%s, %s\n", rt_to_str(RT_RCTL), 11697c478bd9Sstevel@tonic-gate pt_to_str(PT_NAME), pt_to_str(PT_VALUE)); 11707c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s\t\t%s, %s, %s\n", rt_to_str(RT_ATTR), 11717c478bd9Sstevel@tonic-gate pt_to_str(PT_NAME), pt_to_str(PT_TYPE), 11727c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE)); 1173fa9e4066Sahrens (void) fprintf(fp, "\t%s\t\t%s\n", rt_to_str(RT_DATASET), 1174fa9e4066Sahrens pt_to_str(PT_NAME)); 11750209230bSgjelinek (void) fprintf(fp, "\t%s\t%s, %s\n", rt_to_str(RT_DCPU), 11760209230bSgjelinek pt_to_str(PT_NCPUS), pt_to_str(PT_IMPORTANCE)); 1177c97ad5cdSakolb (void) fprintf(fp, "\t%s\t%s\n", rt_to_str(RT_PCAP), 1178c97ad5cdSakolb pt_to_str(PT_NCPUS)); 11790209230bSgjelinek (void) fprintf(fp, "\t%s\t%s, %s, %s\n", rt_to_str(RT_MCAP), 11800209230bSgjelinek pt_to_str(PT_PHYSICAL), pt_to_str(PT_SWAP), 11810209230bSgjelinek pt_to_str(PT_LOCKED)); 11827c478bd9Sstevel@tonic-gate } 11837c478bd9Sstevel@tonic-gate if (need_to_close) 11847c478bd9Sstevel@tonic-gate (void) pclose(fp); 11857c478bd9Sstevel@tonic-gate } 11867c478bd9Sstevel@tonic-gate 11877c478bd9Sstevel@tonic-gate /* PRINTFLIKE1 */ 11887c478bd9Sstevel@tonic-gate static void 11897c478bd9Sstevel@tonic-gate zerr(const char *fmt, ...) 11907c478bd9Sstevel@tonic-gate { 11917c478bd9Sstevel@tonic-gate va_list alist; 11927c478bd9Sstevel@tonic-gate static int last_lineno; 11937c478bd9Sstevel@tonic-gate 11947c478bd9Sstevel@tonic-gate /* lex_lineno has already been incremented in the lexer; compensate */ 11957c478bd9Sstevel@tonic-gate if (cmd_file_mode && lex_lineno > last_lineno) { 11967c478bd9Sstevel@tonic-gate if (strcmp(cmd_file_name, "-") == 0) 11977c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("On line %d:\n"), 11987c478bd9Sstevel@tonic-gate lex_lineno - 1); 11997c478bd9Sstevel@tonic-gate else 12007c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("On line %d of %s:\n"), 12017c478bd9Sstevel@tonic-gate lex_lineno - 1, cmd_file_name); 12027c478bd9Sstevel@tonic-gate last_lineno = lex_lineno; 12037c478bd9Sstevel@tonic-gate } 12047c478bd9Sstevel@tonic-gate va_start(alist, fmt); 12057c478bd9Sstevel@tonic-gate (void) vfprintf(stderr, fmt, alist); 12067c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "\n"); 12077c478bd9Sstevel@tonic-gate va_end(alist); 12087c478bd9Sstevel@tonic-gate } 12097c478bd9Sstevel@tonic-gate 12107c478bd9Sstevel@tonic-gate static void 1211bbec428eSgjelinek zone_perror(char *prefix, int err, boolean_t set_saw) 12127c478bd9Sstevel@tonic-gate { 12137c478bd9Sstevel@tonic-gate zerr("%s: %s", prefix, zonecfg_strerror(err)); 12147c478bd9Sstevel@tonic-gate if (set_saw) 1215bbec428eSgjelinek saw_error = B_TRUE; 12167c478bd9Sstevel@tonic-gate } 12177c478bd9Sstevel@tonic-gate 12187c478bd9Sstevel@tonic-gate /* 12197c478bd9Sstevel@tonic-gate * zone_perror() expects a single string, but for remove and select 12207c478bd9Sstevel@tonic-gate * we have both the command and the resource type, so this wrapper 12217c478bd9Sstevel@tonic-gate * function serves the same purpose in a slightly different way. 12227c478bd9Sstevel@tonic-gate */ 12237c478bd9Sstevel@tonic-gate 12247c478bd9Sstevel@tonic-gate static void 1225bbec428eSgjelinek z_cmd_rt_perror(int cmd_num, int res_num, int err, boolean_t set_saw) 12267c478bd9Sstevel@tonic-gate { 12277c478bd9Sstevel@tonic-gate zerr("%s %s: %s", cmd_to_str(cmd_num), rt_to_str(res_num), 12287c478bd9Sstevel@tonic-gate zonecfg_strerror(err)); 12297c478bd9Sstevel@tonic-gate if (set_saw) 1230bbec428eSgjelinek saw_error = B_TRUE; 12317c478bd9Sstevel@tonic-gate } 12327c478bd9Sstevel@tonic-gate 12337c478bd9Sstevel@tonic-gate /* returns Z_OK if successful, Z_foo from <libzonecfg.h> otherwise */ 12347c478bd9Sstevel@tonic-gate static int 1235bbec428eSgjelinek initialize(boolean_t handle_expected) 12367c478bd9Sstevel@tonic-gate { 12377c478bd9Sstevel@tonic-gate int err; 12389acbbeafSnn35248 char brandname[MAXNAMELEN]; 12397c478bd9Sstevel@tonic-gate 12407c478bd9Sstevel@tonic-gate if (zonecfg_check_handle(handle) != Z_OK) { 12417c478bd9Sstevel@tonic-gate if ((err = zonecfg_get_handle(zone, handle)) == Z_OK) { 1242bbec428eSgjelinek got_handle = B_TRUE; 12439acbbeafSnn35248 if (zonecfg_get_brand(handle, brandname, 12449acbbeafSnn35248 sizeof (brandname)) != Z_OK) { 12459acbbeafSnn35248 zerr("Zone %s is inconsistent: missing " 12469acbbeafSnn35248 "brand attribute", zone); 12479acbbeafSnn35248 exit(Z_ERR); 12489acbbeafSnn35248 } 12499acbbeafSnn35248 if ((brand = brand_open(brandname)) == NULL) { 12509acbbeafSnn35248 zerr("Zone %s uses non-existent brand \"%s\"." 12519acbbeafSnn35248 " Unable to continue", zone, brandname); 12529acbbeafSnn35248 exit(Z_ERR); 12539acbbeafSnn35248 } 12540209230bSgjelinek } else if (global_zone && err == Z_NO_ZONE && !got_handle && 12550209230bSgjelinek !read_only_mode) { 12560209230bSgjelinek /* 12570209230bSgjelinek * We implicitly create the global zone config if it 12580209230bSgjelinek * doesn't exist. 12590209230bSgjelinek */ 12600209230bSgjelinek zone_dochandle_t tmphandle; 12610209230bSgjelinek 12620209230bSgjelinek if ((tmphandle = zonecfg_init_handle()) == NULL) { 1263bbec428eSgjelinek zone_perror(execname, Z_NOMEM, B_TRUE); 12640209230bSgjelinek exit(Z_ERR); 12650209230bSgjelinek } 12660209230bSgjelinek 12670209230bSgjelinek err = zonecfg_get_template_handle("SUNWblank", zone, 12680209230bSgjelinek tmphandle); 12690209230bSgjelinek 12700209230bSgjelinek if (err != Z_OK) { 12710209230bSgjelinek zonecfg_fini_handle(tmphandle); 1272bbec428eSgjelinek zone_perror("SUNWblank", err, B_TRUE); 12730209230bSgjelinek return (err); 12740209230bSgjelinek } 12750209230bSgjelinek 1276bbec428eSgjelinek need_to_commit = B_TRUE; 12770209230bSgjelinek zonecfg_fini_handle(handle); 12780209230bSgjelinek handle = tmphandle; 1279bbec428eSgjelinek got_handle = B_TRUE; 12800209230bSgjelinek 12817c478bd9Sstevel@tonic-gate } else { 12827c478bd9Sstevel@tonic-gate zone_perror(zone, err, handle_expected || got_handle); 12837c478bd9Sstevel@tonic-gate if (err == Z_NO_ZONE && !got_handle && 12847c478bd9Sstevel@tonic-gate interactive_mode && !read_only_mode) 12857c478bd9Sstevel@tonic-gate (void) printf(gettext("Use '%s' to begin " 12867c478bd9Sstevel@tonic-gate "configuring a new zone.\n"), 12877c478bd9Sstevel@tonic-gate cmd_to_str(CMD_CREATE)); 12887c478bd9Sstevel@tonic-gate return (err); 12897c478bd9Sstevel@tonic-gate } 12907c478bd9Sstevel@tonic-gate } 12917c478bd9Sstevel@tonic-gate return (Z_OK); 12927c478bd9Sstevel@tonic-gate } 12937c478bd9Sstevel@tonic-gate 1294bbec428eSgjelinek static boolean_t 1295087719fdSdp state_atleast(zone_state_t state) 1296087719fdSdp { 1297087719fdSdp zone_state_t state_num; 1298087719fdSdp int err; 1299087719fdSdp 1300087719fdSdp if ((err = zone_get_state(zone, &state_num)) != Z_OK) { 1301087719fdSdp /* all states are greater than "non-existent" */ 1302087719fdSdp if (err == Z_NO_ZONE) 1303087719fdSdp return (B_FALSE); 1304087719fdSdp zerr(gettext("Unexpectedly failed to determine state " 1305087719fdSdp "of zone %s: %s"), zone, zonecfg_strerror(err)); 1306087719fdSdp exit(Z_ERR); 1307087719fdSdp } 1308087719fdSdp return (state_num >= state); 1309087719fdSdp } 1310087719fdSdp 13117c478bd9Sstevel@tonic-gate /* 13127c478bd9Sstevel@tonic-gate * short_usage() is for bad syntax: getopt() issues, too many arguments, etc. 13137c478bd9Sstevel@tonic-gate */ 13147c478bd9Sstevel@tonic-gate 13157c478bd9Sstevel@tonic-gate void 13167c478bd9Sstevel@tonic-gate short_usage(int command) 13177c478bd9Sstevel@tonic-gate { 13187c478bd9Sstevel@tonic-gate /* lex_lineno has already been incremented in the lexer; compensate */ 13197c478bd9Sstevel@tonic-gate if (cmd_file_mode) { 13207c478bd9Sstevel@tonic-gate if (strcmp(cmd_file_name, "-") == 0) 13217c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 13227c478bd9Sstevel@tonic-gate gettext("syntax error on line %d\n"), 13237c478bd9Sstevel@tonic-gate lex_lineno - 1); 13247c478bd9Sstevel@tonic-gate else 13257c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 13267c478bd9Sstevel@tonic-gate gettext("syntax error on line %d of %s\n"), 13277c478bd9Sstevel@tonic-gate lex_lineno - 1, cmd_file_name); 13287c478bd9Sstevel@tonic-gate } 13297c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s:\n%s\n", gettext("usage"), 13307c478bd9Sstevel@tonic-gate helptab[command].short_usage); 1331bbec428eSgjelinek saw_error = B_TRUE; 13327c478bd9Sstevel@tonic-gate } 13337c478bd9Sstevel@tonic-gate 13347c478bd9Sstevel@tonic-gate /* 13357c478bd9Sstevel@tonic-gate * long_usage() is for bad semantics: e.g., wrong property type for a given 13367c478bd9Sstevel@tonic-gate * resource type. It is also used by longer_usage() below. 13377c478bd9Sstevel@tonic-gate */ 13387c478bd9Sstevel@tonic-gate 13397c478bd9Sstevel@tonic-gate void 1340bbec428eSgjelinek long_usage(uint_t cmd_num, boolean_t set_saw) 13417c478bd9Sstevel@tonic-gate { 13427c478bd9Sstevel@tonic-gate (void) fprintf(set_saw ? stderr : stdout, "%s:\n%s\n", gettext("usage"), 13437c478bd9Sstevel@tonic-gate helptab[cmd_num].short_usage); 13447c478bd9Sstevel@tonic-gate (void) fprintf(set_saw ? stderr : stdout, "\t%s\n", long_help(cmd_num)); 13457c478bd9Sstevel@tonic-gate if (set_saw) 1346bbec428eSgjelinek saw_error = B_TRUE; 13477c478bd9Sstevel@tonic-gate } 13487c478bd9Sstevel@tonic-gate 13497c478bd9Sstevel@tonic-gate /* 13507c478bd9Sstevel@tonic-gate * longer_usage() is for 'help foo' and 'foo -?': call long_usage() and also 13517c478bd9Sstevel@tonic-gate * any extra usage() flags as appropriate for whatever command. 13527c478bd9Sstevel@tonic-gate */ 13537c478bd9Sstevel@tonic-gate 13547c478bd9Sstevel@tonic-gate void 13557c478bd9Sstevel@tonic-gate longer_usage(uint_t cmd_num) 13567c478bd9Sstevel@tonic-gate { 1357bbec428eSgjelinek long_usage(cmd_num, B_FALSE); 13587c478bd9Sstevel@tonic-gate if (helptab[cmd_num].flags != 0) { 13597c478bd9Sstevel@tonic-gate (void) printf("\n"); 1360bbec428eSgjelinek usage(B_TRUE, helptab[cmd_num].flags); 13617c478bd9Sstevel@tonic-gate } 13627c478bd9Sstevel@tonic-gate } 13637c478bd9Sstevel@tonic-gate 13647c478bd9Sstevel@tonic-gate /* 13657c478bd9Sstevel@tonic-gate * scope_usage() is simply used when a command is called from the wrong scope. 13667c478bd9Sstevel@tonic-gate */ 13677c478bd9Sstevel@tonic-gate 13687c478bd9Sstevel@tonic-gate static void 13697c478bd9Sstevel@tonic-gate scope_usage(uint_t cmd_num) 13707c478bd9Sstevel@tonic-gate { 13717c478bd9Sstevel@tonic-gate zerr(gettext("The %s command only makes sense in the %s scope."), 13727c478bd9Sstevel@tonic-gate cmd_to_str(cmd_num), 13737c478bd9Sstevel@tonic-gate global_scope ? gettext("resource") : gettext("global")); 1374bbec428eSgjelinek saw_error = B_TRUE; 13757c478bd9Sstevel@tonic-gate } 13767c478bd9Sstevel@tonic-gate 13777c478bd9Sstevel@tonic-gate /* 1378bbec428eSgjelinek * On input, B_TRUE => yes, B_FALSE => no. 1379bbec428eSgjelinek * On return, B_TRUE => 1, B_FALSE => no, could not ask => -1. 13807c478bd9Sstevel@tonic-gate */ 13817c478bd9Sstevel@tonic-gate 13827c478bd9Sstevel@tonic-gate static int 1383bbec428eSgjelinek ask_yesno(boolean_t default_answer, const char *question) 13847c478bd9Sstevel@tonic-gate { 13857c478bd9Sstevel@tonic-gate char line[64]; /* should be enough to answer yes or no */ 13867c478bd9Sstevel@tonic-gate 13877c478bd9Sstevel@tonic-gate if (!ok_to_prompt) { 1388bbec428eSgjelinek saw_error = B_TRUE; 13897c478bd9Sstevel@tonic-gate return (-1); 13907c478bd9Sstevel@tonic-gate } 13917c478bd9Sstevel@tonic-gate for (;;) { 1392087719fdSdp if (printf("%s (%s)? ", question, 1393087719fdSdp default_answer ? "[y]/n" : "y/[n]") < 0) 1394087719fdSdp return (-1); 1395087719fdSdp if (fgets(line, sizeof (line), stdin) == NULL) 1396087719fdSdp return (-1); 1397087719fdSdp 1398087719fdSdp if (line[0] == '\n') 13997c478bd9Sstevel@tonic-gate return (default_answer ? 1 : 0); 14007c478bd9Sstevel@tonic-gate if (tolower(line[0]) == 'y') 14017c478bd9Sstevel@tonic-gate return (1); 14027c478bd9Sstevel@tonic-gate if (tolower(line[0]) == 'n') 14037c478bd9Sstevel@tonic-gate return (0); 14047c478bd9Sstevel@tonic-gate } 14057c478bd9Sstevel@tonic-gate } 14067c478bd9Sstevel@tonic-gate 14077c478bd9Sstevel@tonic-gate /* 14087c478bd9Sstevel@tonic-gate * Prints warning if zone already exists. 14097c478bd9Sstevel@tonic-gate * In interactive mode, prompts if we should continue anyway and returns Z_OK 14107c478bd9Sstevel@tonic-gate * if so, Z_ERR if not. In non-interactive mode, exits with Z_ERR. 14117c478bd9Sstevel@tonic-gate * 14127c478bd9Sstevel@tonic-gate * Note that if a zone exists and its state is >= INSTALLED, an error message 14137c478bd9Sstevel@tonic-gate * will be printed and this function will return Z_ERR regardless of mode. 14147c478bd9Sstevel@tonic-gate */ 14157c478bd9Sstevel@tonic-gate 14167c478bd9Sstevel@tonic-gate static int 1417bbec428eSgjelinek check_if_zone_already_exists(boolean_t force) 14187c478bd9Sstevel@tonic-gate { 14197c478bd9Sstevel@tonic-gate char line[ZONENAME_MAX + 128]; /* enough to ask a question */ 14207c478bd9Sstevel@tonic-gate zone_dochandle_t tmphandle; 14217c478bd9Sstevel@tonic-gate int res, answer; 14227c478bd9Sstevel@tonic-gate 14237c478bd9Sstevel@tonic-gate if ((tmphandle = zonecfg_init_handle()) == NULL) { 1424bbec428eSgjelinek zone_perror(execname, Z_NOMEM, B_TRUE); 14257c478bd9Sstevel@tonic-gate exit(Z_ERR); 14267c478bd9Sstevel@tonic-gate } 14277c478bd9Sstevel@tonic-gate res = zonecfg_get_handle(zone, tmphandle); 14287c478bd9Sstevel@tonic-gate zonecfg_fini_handle(tmphandle); 1429087719fdSdp if (res != Z_OK) 14307c478bd9Sstevel@tonic-gate return (Z_OK); 1431087719fdSdp 1432087719fdSdp if (state_atleast(ZONE_STATE_INSTALLED)) { 14337c478bd9Sstevel@tonic-gate zerr(gettext("Zone %s already installed; %s not allowed."), 14347c478bd9Sstevel@tonic-gate zone, cmd_to_str(CMD_CREATE)); 14357c478bd9Sstevel@tonic-gate return (Z_ERR); 14367c478bd9Sstevel@tonic-gate } 14377c478bd9Sstevel@tonic-gate 14387c478bd9Sstevel@tonic-gate if (force) { 14397c478bd9Sstevel@tonic-gate (void) printf(gettext("Zone %s already exists; overwriting.\n"), 14407c478bd9Sstevel@tonic-gate zone); 14417c478bd9Sstevel@tonic-gate return (Z_OK); 14427c478bd9Sstevel@tonic-gate } 14437c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), 14447c478bd9Sstevel@tonic-gate gettext("Zone %s already exists; %s anyway"), zone, 14457c478bd9Sstevel@tonic-gate cmd_to_str(CMD_CREATE)); 1446bbec428eSgjelinek if ((answer = ask_yesno(B_FALSE, line)) == -1) { 14477c478bd9Sstevel@tonic-gate zerr(gettext("Zone exists, input not from terminal and -F not " 14487c478bd9Sstevel@tonic-gate "specified:\n%s command ignored, exiting."), 14497c478bd9Sstevel@tonic-gate cmd_to_str(CMD_CREATE)); 14507c478bd9Sstevel@tonic-gate exit(Z_ERR); 14517c478bd9Sstevel@tonic-gate } 14527c478bd9Sstevel@tonic-gate return (answer == 1 ? Z_OK : Z_ERR); 14537c478bd9Sstevel@tonic-gate } 14547c478bd9Sstevel@tonic-gate 1455bbec428eSgjelinek static boolean_t 14567c478bd9Sstevel@tonic-gate zone_is_read_only(int cmd_num) 14577c478bd9Sstevel@tonic-gate { 14587c478bd9Sstevel@tonic-gate if (strncmp(zone, "SUNW", 4) == 0) { 14597c478bd9Sstevel@tonic-gate zerr(gettext("%s: zones beginning with SUNW are read-only."), 14607c478bd9Sstevel@tonic-gate zone); 1461bbec428eSgjelinek saw_error = B_TRUE; 1462bbec428eSgjelinek return (B_TRUE); 14637c478bd9Sstevel@tonic-gate } 14647c478bd9Sstevel@tonic-gate if (read_only_mode) { 14657c478bd9Sstevel@tonic-gate zerr(gettext("%s: cannot %s in read-only mode."), zone, 14667c478bd9Sstevel@tonic-gate cmd_to_str(cmd_num)); 1467bbec428eSgjelinek saw_error = B_TRUE; 1468bbec428eSgjelinek return (B_TRUE); 14697c478bd9Sstevel@tonic-gate } 1470bbec428eSgjelinek return (B_FALSE); 14717c478bd9Sstevel@tonic-gate } 14727c478bd9Sstevel@tonic-gate 14737c478bd9Sstevel@tonic-gate /* 14747c478bd9Sstevel@tonic-gate * Create a new configuration. 14757c478bd9Sstevel@tonic-gate */ 14767c478bd9Sstevel@tonic-gate void 14777c478bd9Sstevel@tonic-gate create_func(cmd_t *cmd) 14787c478bd9Sstevel@tonic-gate { 14797c478bd9Sstevel@tonic-gate int err, arg; 14807c478bd9Sstevel@tonic-gate char zone_template[ZONENAME_MAX]; 1481ee519a1fSgjelinek char attach_path[MAXPATHLEN]; 14827c478bd9Sstevel@tonic-gate zone_dochandle_t tmphandle; 1483bbec428eSgjelinek boolean_t force = B_FALSE; 1484bbec428eSgjelinek boolean_t attach = B_FALSE; 1485bbec428eSgjelinek boolean_t arg_err = B_FALSE; 14867c478bd9Sstevel@tonic-gate 14877c478bd9Sstevel@tonic-gate assert(cmd != NULL); 14887c478bd9Sstevel@tonic-gate 14897c478bd9Sstevel@tonic-gate /* This is the default if no arguments are given. */ 14907c478bd9Sstevel@tonic-gate (void) strlcpy(zone_template, "SUNWdefault", sizeof (zone_template)); 14917c478bd9Sstevel@tonic-gate 14927c478bd9Sstevel@tonic-gate optind = 0; 14939acbbeafSnn35248 while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?a:bFt:")) 14949acbbeafSnn35248 != EOF) { 14957c478bd9Sstevel@tonic-gate switch (arg) { 14967c478bd9Sstevel@tonic-gate case '?': 14977c478bd9Sstevel@tonic-gate if (optopt == '?') 14987c478bd9Sstevel@tonic-gate longer_usage(CMD_CREATE); 14997c478bd9Sstevel@tonic-gate else 15007c478bd9Sstevel@tonic-gate short_usage(CMD_CREATE); 1501bbec428eSgjelinek arg_err = B_TRUE; 15027ec75eb8Sgjelinek break; 1503ee519a1fSgjelinek case 'a': 1504ee519a1fSgjelinek (void) strlcpy(attach_path, optarg, 1505ee519a1fSgjelinek sizeof (attach_path)); 1506bbec428eSgjelinek attach = B_TRUE; 1507ee519a1fSgjelinek break; 15087c478bd9Sstevel@tonic-gate case 'b': 15097c478bd9Sstevel@tonic-gate (void) strlcpy(zone_template, "SUNWblank", 15107c478bd9Sstevel@tonic-gate sizeof (zone_template)); 15117c478bd9Sstevel@tonic-gate break; 15127c478bd9Sstevel@tonic-gate case 'F': 1513bbec428eSgjelinek force = B_TRUE; 15147c478bd9Sstevel@tonic-gate break; 15157c478bd9Sstevel@tonic-gate case 't': 15167c478bd9Sstevel@tonic-gate (void) strlcpy(zone_template, optarg, 15177c478bd9Sstevel@tonic-gate sizeof (zone_template)); 15187c478bd9Sstevel@tonic-gate break; 15197c478bd9Sstevel@tonic-gate default: 15207c478bd9Sstevel@tonic-gate short_usage(CMD_CREATE); 1521bbec428eSgjelinek arg_err = B_TRUE; 15227ec75eb8Sgjelinek break; 15237ec75eb8Sgjelinek } 15247ec75eb8Sgjelinek } 15257ec75eb8Sgjelinek if (arg_err) 15267c478bd9Sstevel@tonic-gate return; 15277ec75eb8Sgjelinek 15287c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 15297c478bd9Sstevel@tonic-gate short_usage(CMD_CREATE); 15307c478bd9Sstevel@tonic-gate return; 15317c478bd9Sstevel@tonic-gate } 15327c478bd9Sstevel@tonic-gate 15337c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_CREATE)) 15347c478bd9Sstevel@tonic-gate return; 15357c478bd9Sstevel@tonic-gate 15367c478bd9Sstevel@tonic-gate if (check_if_zone_already_exists(force) != Z_OK) 15377c478bd9Sstevel@tonic-gate return; 15387c478bd9Sstevel@tonic-gate 15397c478bd9Sstevel@tonic-gate /* 15407c478bd9Sstevel@tonic-gate * Get a temporary handle first. If that fails, the old handle 15417c478bd9Sstevel@tonic-gate * will not be lost. Then finish whichever one we don't need, 15427c478bd9Sstevel@tonic-gate * to avoid leaks. Then get the handle for zone_template, and 15437c478bd9Sstevel@tonic-gate * set the name to zone: this "copy, rename" method is how 15447c478bd9Sstevel@tonic-gate * create -[b|t] works. 15457c478bd9Sstevel@tonic-gate */ 15467c478bd9Sstevel@tonic-gate if ((tmphandle = zonecfg_init_handle()) == NULL) { 1547bbec428eSgjelinek zone_perror(execname, Z_NOMEM, B_TRUE); 15487c478bd9Sstevel@tonic-gate exit(Z_ERR); 15497c478bd9Sstevel@tonic-gate } 1550ee519a1fSgjelinek 1551ee519a1fSgjelinek if (attach) 155216ab8c7bSgjelinek err = zonecfg_get_attach_handle(attach_path, ZONE_DETACHED, 155316ab8c7bSgjelinek zone, B_FALSE, tmphandle); 1554ee519a1fSgjelinek else 1555ee519a1fSgjelinek err = zonecfg_get_template_handle(zone_template, zone, 1556ee519a1fSgjelinek tmphandle); 1557ee519a1fSgjelinek 1558ee519a1fSgjelinek if (err != Z_OK) { 15597c478bd9Sstevel@tonic-gate zonecfg_fini_handle(tmphandle); 1560ee519a1fSgjelinek if (attach && err == Z_NO_ZONE) 1561ee519a1fSgjelinek (void) fprintf(stderr, gettext("invalid path to " 1562ee519a1fSgjelinek "detached zone\n")); 1563ee519a1fSgjelinek else if (attach && err == Z_INVALID_DOCUMENT) 1564ee519a1fSgjelinek (void) fprintf(stderr, gettext("Cannot attach to an " 1565ee519a1fSgjelinek "earlier release of the operating system\n")); 1566ee519a1fSgjelinek else 1567bbec428eSgjelinek zone_perror(zone_template, err, B_TRUE); 15687c478bd9Sstevel@tonic-gate return; 15697c478bd9Sstevel@tonic-gate } 1570087719fdSdp 1571bbec428eSgjelinek need_to_commit = B_TRUE; 15727c478bd9Sstevel@tonic-gate zonecfg_fini_handle(handle); 15737c478bd9Sstevel@tonic-gate handle = tmphandle; 1574bbec428eSgjelinek got_handle = B_TRUE; 15757c478bd9Sstevel@tonic-gate } 15767c478bd9Sstevel@tonic-gate 15777c478bd9Sstevel@tonic-gate /* 15787c478bd9Sstevel@tonic-gate * This malloc()'s memory, which must be freed by the caller. 15797c478bd9Sstevel@tonic-gate */ 15807c478bd9Sstevel@tonic-gate static char * 15817c478bd9Sstevel@tonic-gate quoteit(char *instr) 15827c478bd9Sstevel@tonic-gate { 15837c478bd9Sstevel@tonic-gate char *outstr; 15847c478bd9Sstevel@tonic-gate size_t outstrsize = strlen(instr) + 3; /* 2 quotes + '\0' */ 15857c478bd9Sstevel@tonic-gate 15867c478bd9Sstevel@tonic-gate if ((outstr = malloc(outstrsize)) == NULL) { 1587bbec428eSgjelinek zone_perror(zone, Z_NOMEM, B_FALSE); 15887c478bd9Sstevel@tonic-gate exit(Z_ERR); 15897c478bd9Sstevel@tonic-gate } 15907c478bd9Sstevel@tonic-gate if (strchr(instr, ' ') == NULL) { 15917c478bd9Sstevel@tonic-gate (void) strlcpy(outstr, instr, outstrsize); 15927c478bd9Sstevel@tonic-gate return (outstr); 15937c478bd9Sstevel@tonic-gate } 15947c478bd9Sstevel@tonic-gate (void) snprintf(outstr, outstrsize, "\"%s\"", instr); 15957c478bd9Sstevel@tonic-gate return (outstr); 15967c478bd9Sstevel@tonic-gate } 15977c478bd9Sstevel@tonic-gate 15987c478bd9Sstevel@tonic-gate static void 15997c478bd9Sstevel@tonic-gate export_prop(FILE *of, int prop_num, char *prop_id) 16007c478bd9Sstevel@tonic-gate { 16017c478bd9Sstevel@tonic-gate char *quote_str; 16027c478bd9Sstevel@tonic-gate 16037c478bd9Sstevel@tonic-gate if (strlen(prop_id) == 0) 16047c478bd9Sstevel@tonic-gate return; 16057c478bd9Sstevel@tonic-gate quote_str = quoteit(prop_id); 16067c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 16077c478bd9Sstevel@tonic-gate pt_to_str(prop_num), quote_str); 16087c478bd9Sstevel@tonic-gate free(quote_str); 16097c478bd9Sstevel@tonic-gate } 16107c478bd9Sstevel@tonic-gate 16117c478bd9Sstevel@tonic-gate void 16127c478bd9Sstevel@tonic-gate export_func(cmd_t *cmd) 16137c478bd9Sstevel@tonic-gate { 16147c478bd9Sstevel@tonic-gate struct zone_nwiftab nwiftab; 16157c478bd9Sstevel@tonic-gate struct zone_fstab fstab; 16167c478bd9Sstevel@tonic-gate struct zone_devtab devtab; 16177c478bd9Sstevel@tonic-gate struct zone_attrtab attrtab; 16187c478bd9Sstevel@tonic-gate struct zone_rctltab rctltab; 1619fa9e4066Sahrens struct zone_dstab dstab; 16200209230bSgjelinek struct zone_psettab psettab; 16210209230bSgjelinek struct zone_mcaptab mcaptab; 16227c478bd9Sstevel@tonic-gate struct zone_rctlvaltab *valptr; 16237c478bd9Sstevel@tonic-gate int err, arg; 16247c478bd9Sstevel@tonic-gate char zonepath[MAXPATHLEN], outfile[MAXPATHLEN], pool[MAXNAMELEN]; 16253f2f09c1Sdp char bootargs[BOOTARGS_MAX]; 16260209230bSgjelinek char sched[MAXNAMELEN]; 16279acbbeafSnn35248 char brand[MAXNAMELEN]; 1628ffbafc53Scomay char *limitpriv; 16297c478bd9Sstevel@tonic-gate FILE *of; 16307c478bd9Sstevel@tonic-gate boolean_t autoboot; 1631f4b3ec61Sdh155122 zone_iptype_t iptype; 1632bbec428eSgjelinek boolean_t need_to_close = B_FALSE; 1633bbec428eSgjelinek boolean_t arg_err = B_FALSE; 16347c478bd9Sstevel@tonic-gate 16357c478bd9Sstevel@tonic-gate assert(cmd != NULL); 16367c478bd9Sstevel@tonic-gate 16377c478bd9Sstevel@tonic-gate outfile[0] = '\0'; 16387c478bd9Sstevel@tonic-gate optind = 0; 16397c478bd9Sstevel@tonic-gate while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?f:")) != EOF) { 16407c478bd9Sstevel@tonic-gate switch (arg) { 16417c478bd9Sstevel@tonic-gate case '?': 16427c478bd9Sstevel@tonic-gate if (optopt == '?') 16437c478bd9Sstevel@tonic-gate longer_usage(CMD_EXPORT); 16447c478bd9Sstevel@tonic-gate else 16457c478bd9Sstevel@tonic-gate short_usage(CMD_EXPORT); 1646bbec428eSgjelinek arg_err = B_TRUE; 16477ec75eb8Sgjelinek break; 16487c478bd9Sstevel@tonic-gate case 'f': 16497c478bd9Sstevel@tonic-gate (void) strlcpy(outfile, optarg, sizeof (outfile)); 16507c478bd9Sstevel@tonic-gate break; 16517c478bd9Sstevel@tonic-gate default: 16527c478bd9Sstevel@tonic-gate short_usage(CMD_EXPORT); 1653bbec428eSgjelinek arg_err = B_TRUE; 16547ec75eb8Sgjelinek break; 16557ec75eb8Sgjelinek } 16567ec75eb8Sgjelinek } 16577ec75eb8Sgjelinek if (arg_err) 16587c478bd9Sstevel@tonic-gate return; 16597ec75eb8Sgjelinek 16607c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 16617c478bd9Sstevel@tonic-gate short_usage(CMD_EXPORT); 16627c478bd9Sstevel@tonic-gate return; 16637c478bd9Sstevel@tonic-gate } 16647c478bd9Sstevel@tonic-gate if (strlen(outfile) == 0) { 16657c478bd9Sstevel@tonic-gate of = stdout; 16667c478bd9Sstevel@tonic-gate } else { 16677c478bd9Sstevel@tonic-gate if ((of = fopen(outfile, "w")) == NULL) { 16687c478bd9Sstevel@tonic-gate zerr(gettext("opening file %s: %s"), 16697c478bd9Sstevel@tonic-gate outfile, strerror(errno)); 16707c478bd9Sstevel@tonic-gate goto done; 16717c478bd9Sstevel@tonic-gate } 16727c478bd9Sstevel@tonic-gate setbuf(of, NULL); 1673bbec428eSgjelinek need_to_close = B_TRUE; 16747c478bd9Sstevel@tonic-gate } 16757c478bd9Sstevel@tonic-gate 1676bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK) 16777c478bd9Sstevel@tonic-gate goto done; 16787c478bd9Sstevel@tonic-gate 16797c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s -b\n", cmd_to_str(CMD_CREATE)); 16807c478bd9Sstevel@tonic-gate 16817c478bd9Sstevel@tonic-gate if (zonecfg_get_zonepath(handle, zonepath, sizeof (zonepath)) == Z_OK && 16827c478bd9Sstevel@tonic-gate strlen(zonepath) > 0) 16837c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 16847c478bd9Sstevel@tonic-gate pt_to_str(PT_ZONEPATH), zonepath); 16857c478bd9Sstevel@tonic-gate 16869acbbeafSnn35248 if ((zone_get_brand(zone, brand, sizeof (brand)) == Z_OK) && 16879acbbeafSnn35248 (strcmp(brand, NATIVE_BRAND_NAME) != 0)) 16889acbbeafSnn35248 (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 16899acbbeafSnn35248 pt_to_str(PT_BRAND), brand); 16909acbbeafSnn35248 16917c478bd9Sstevel@tonic-gate if (zonecfg_get_autoboot(handle, &autoboot) == Z_OK) 16927c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 16937c478bd9Sstevel@tonic-gate pt_to_str(PT_AUTOBOOT), autoboot ? "true" : "false"); 16947c478bd9Sstevel@tonic-gate 16953f2f09c1Sdp if (zonecfg_get_bootargs(handle, bootargs, sizeof (bootargs)) == Z_OK && 16963f2f09c1Sdp strlen(bootargs) > 0) { 16973f2f09c1Sdp (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 16983f2f09c1Sdp pt_to_str(PT_BOOTARGS), bootargs); 16993f2f09c1Sdp } 17003f2f09c1Sdp 17017c478bd9Sstevel@tonic-gate if (zonecfg_get_pool(handle, pool, sizeof (pool)) == Z_OK && 17027c478bd9Sstevel@tonic-gate strlen(pool) > 0) 17037c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 17047c478bd9Sstevel@tonic-gate pt_to_str(PT_POOL), pool); 17057c478bd9Sstevel@tonic-gate 1706ffbafc53Scomay if (zonecfg_get_limitpriv(handle, &limitpriv) == Z_OK && 1707ffbafc53Scomay strlen(limitpriv) > 0) { 1708ffbafc53Scomay (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 1709ffbafc53Scomay pt_to_str(PT_LIMITPRIV), limitpriv); 1710ffbafc53Scomay free(limitpriv); 1711ffbafc53Scomay } 1712ffbafc53Scomay 17130209230bSgjelinek if (zonecfg_get_sched_class(handle, sched, sizeof (sched)) == Z_OK && 17140209230bSgjelinek strlen(sched) > 0) 17150209230bSgjelinek (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 17160209230bSgjelinek pt_to_str(PT_SCHED), sched); 17173f2f09c1Sdp 1718f4b3ec61Sdh155122 if (zonecfg_get_iptype(handle, &iptype) == Z_OK) { 1719f4b3ec61Sdh155122 switch (iptype) { 1720f4b3ec61Sdh155122 case ZS_SHARED: 1721f4b3ec61Sdh155122 (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 1722f4b3ec61Sdh155122 pt_to_str(PT_IPTYPE), "shared"); 1723f4b3ec61Sdh155122 break; 1724f4b3ec61Sdh155122 case ZS_EXCLUSIVE: 1725f4b3ec61Sdh155122 (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 1726f4b3ec61Sdh155122 pt_to_str(PT_IPTYPE), "exclusive"); 1727f4b3ec61Sdh155122 break; 1728f4b3ec61Sdh155122 } 1729f4b3ec61Sdh155122 } 1730f4b3ec61Sdh155122 17317c478bd9Sstevel@tonic-gate if ((err = zonecfg_setipdent(handle)) != Z_OK) { 1732bbec428eSgjelinek zone_perror(zone, err, B_FALSE); 17337c478bd9Sstevel@tonic-gate goto done; 17347c478bd9Sstevel@tonic-gate } 17357c478bd9Sstevel@tonic-gate while (zonecfg_getipdent(handle, &fstab) == Z_OK) { 17367c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 17377c478bd9Sstevel@tonic-gate rt_to_str(RT_IPD)); 17387c478bd9Sstevel@tonic-gate export_prop(of, PT_DIR, fstab.zone_fs_dir); 17397c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 17407c478bd9Sstevel@tonic-gate } 17417c478bd9Sstevel@tonic-gate (void) zonecfg_endipdent(handle); 17427c478bd9Sstevel@tonic-gate 17437c478bd9Sstevel@tonic-gate if ((err = zonecfg_setfsent(handle)) != Z_OK) { 1744bbec428eSgjelinek zone_perror(zone, err, B_FALSE); 17457c478bd9Sstevel@tonic-gate goto done; 17467c478bd9Sstevel@tonic-gate } 17477c478bd9Sstevel@tonic-gate while (zonecfg_getfsent(handle, &fstab) == Z_OK) { 17487c478bd9Sstevel@tonic-gate zone_fsopt_t *optptr; 17497c478bd9Sstevel@tonic-gate 17507c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 17517c478bd9Sstevel@tonic-gate rt_to_str(RT_FS)); 17527c478bd9Sstevel@tonic-gate export_prop(of, PT_DIR, fstab.zone_fs_dir); 17537c478bd9Sstevel@tonic-gate export_prop(of, PT_SPECIAL, fstab.zone_fs_special); 17547c478bd9Sstevel@tonic-gate export_prop(of, PT_RAW, fstab.zone_fs_raw); 17557c478bd9Sstevel@tonic-gate export_prop(of, PT_TYPE, fstab.zone_fs_type); 17567c478bd9Sstevel@tonic-gate for (optptr = fstab.zone_fs_options; optptr != NULL; 17577c478bd9Sstevel@tonic-gate optptr = optptr->zone_fsopt_next) { 17587c478bd9Sstevel@tonic-gate /* 17597c478bd9Sstevel@tonic-gate * Simple property values with embedded equal signs 17607c478bd9Sstevel@tonic-gate * need to be quoted to prevent the lexer from 17617c478bd9Sstevel@tonic-gate * mis-parsing them as complex name=value pairs. 17627c478bd9Sstevel@tonic-gate */ 17637c478bd9Sstevel@tonic-gate if (strchr(optptr->zone_fsopt_opt, '=')) 17647c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s \"%s\"\n", 17657c478bd9Sstevel@tonic-gate cmd_to_str(CMD_ADD), 17667c478bd9Sstevel@tonic-gate pt_to_str(PT_OPTIONS), 17677c478bd9Sstevel@tonic-gate optptr->zone_fsopt_opt); 17687c478bd9Sstevel@tonic-gate else 17697c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s %s\n", 17707c478bd9Sstevel@tonic-gate cmd_to_str(CMD_ADD), 17717c478bd9Sstevel@tonic-gate pt_to_str(PT_OPTIONS), 17727c478bd9Sstevel@tonic-gate optptr->zone_fsopt_opt); 17737c478bd9Sstevel@tonic-gate } 17747c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 17757c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(fstab.zone_fs_options); 17767c478bd9Sstevel@tonic-gate } 17777c478bd9Sstevel@tonic-gate (void) zonecfg_endfsent(handle); 17787c478bd9Sstevel@tonic-gate 17797c478bd9Sstevel@tonic-gate if ((err = zonecfg_setnwifent(handle)) != Z_OK) { 1780bbec428eSgjelinek zone_perror(zone, err, B_FALSE); 17817c478bd9Sstevel@tonic-gate goto done; 17827c478bd9Sstevel@tonic-gate } 17837c478bd9Sstevel@tonic-gate while (zonecfg_getnwifent(handle, &nwiftab) == Z_OK) { 17847c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 17857c478bd9Sstevel@tonic-gate rt_to_str(RT_NET)); 17867c478bd9Sstevel@tonic-gate export_prop(of, PT_ADDRESS, nwiftab.zone_nwif_address); 17877c478bd9Sstevel@tonic-gate export_prop(of, PT_PHYSICAL, nwiftab.zone_nwif_physical); 1788de860bd9Sgfaden export_prop(of, PT_DEFROUTER, nwiftab.zone_nwif_defrouter); 17897c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 17907c478bd9Sstevel@tonic-gate } 17917c478bd9Sstevel@tonic-gate (void) zonecfg_endnwifent(handle); 17927c478bd9Sstevel@tonic-gate 17937c478bd9Sstevel@tonic-gate if ((err = zonecfg_setdevent(handle)) != Z_OK) { 1794bbec428eSgjelinek zone_perror(zone, err, B_FALSE); 17957c478bd9Sstevel@tonic-gate goto done; 17967c478bd9Sstevel@tonic-gate } 17977c478bd9Sstevel@tonic-gate while (zonecfg_getdevent(handle, &devtab) == Z_OK) { 17987c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 17997c478bd9Sstevel@tonic-gate rt_to_str(RT_DEVICE)); 18007c478bd9Sstevel@tonic-gate export_prop(of, PT_MATCH, devtab.zone_dev_match); 18017c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 18027c478bd9Sstevel@tonic-gate } 18037c478bd9Sstevel@tonic-gate (void) zonecfg_enddevent(handle); 18047c478bd9Sstevel@tonic-gate 18057c478bd9Sstevel@tonic-gate if ((err = zonecfg_setrctlent(handle)) != Z_OK) { 1806bbec428eSgjelinek zone_perror(zone, err, B_FALSE); 18077c478bd9Sstevel@tonic-gate goto done; 18087c478bd9Sstevel@tonic-gate } 18097c478bd9Sstevel@tonic-gate while (zonecfg_getrctlent(handle, &rctltab) == Z_OK) { 18107c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s rctl\n", cmd_to_str(CMD_ADD)); 18117c478bd9Sstevel@tonic-gate export_prop(of, PT_NAME, rctltab.zone_rctl_name); 18127c478bd9Sstevel@tonic-gate for (valptr = rctltab.zone_rctl_valptr; valptr != NULL; 18137c478bd9Sstevel@tonic-gate valptr = valptr->zone_rctlval_next) { 18147c478bd9Sstevel@tonic-gate fprintf(of, "%s %s (%s=%s,%s=%s,%s=%s)\n", 18157c478bd9Sstevel@tonic-gate cmd_to_str(CMD_ADD), pt_to_str(PT_VALUE), 18167c478bd9Sstevel@tonic-gate pt_to_str(PT_PRIV), valptr->zone_rctlval_priv, 18177c478bd9Sstevel@tonic-gate pt_to_str(PT_LIMIT), valptr->zone_rctlval_limit, 18187c478bd9Sstevel@tonic-gate pt_to_str(PT_ACTION), valptr->zone_rctlval_action); 18197c478bd9Sstevel@tonic-gate } 18207c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 18217c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctltab.zone_rctl_valptr); 18227c478bd9Sstevel@tonic-gate } 18237c478bd9Sstevel@tonic-gate (void) zonecfg_endrctlent(handle); 18247c478bd9Sstevel@tonic-gate 18257c478bd9Sstevel@tonic-gate if ((err = zonecfg_setattrent(handle)) != Z_OK) { 1826bbec428eSgjelinek zone_perror(zone, err, B_FALSE); 18277c478bd9Sstevel@tonic-gate goto done; 18287c478bd9Sstevel@tonic-gate } 18297c478bd9Sstevel@tonic-gate while (zonecfg_getattrent(handle, &attrtab) == Z_OK) { 18307c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 18317c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR)); 18327c478bd9Sstevel@tonic-gate export_prop(of, PT_NAME, attrtab.zone_attr_name); 18337c478bd9Sstevel@tonic-gate export_prop(of, PT_TYPE, attrtab.zone_attr_type); 18347c478bd9Sstevel@tonic-gate export_prop(of, PT_VALUE, attrtab.zone_attr_value); 18357c478bd9Sstevel@tonic-gate (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 18367c478bd9Sstevel@tonic-gate } 18377c478bd9Sstevel@tonic-gate (void) zonecfg_endattrent(handle); 18387c478bd9Sstevel@tonic-gate 1839fa9e4066Sahrens if ((err = zonecfg_setdsent(handle)) != Z_OK) { 1840bbec428eSgjelinek zone_perror(zone, err, B_FALSE); 1841fa9e4066Sahrens goto done; 1842fa9e4066Sahrens } 1843fa9e4066Sahrens while (zonecfg_getdsent(handle, &dstab) == Z_OK) { 1844fa9e4066Sahrens (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 1845fa9e4066Sahrens rt_to_str(RT_DATASET)); 1846fa9e4066Sahrens export_prop(of, PT_NAME, dstab.zone_dataset_name); 1847fa9e4066Sahrens (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 1848fa9e4066Sahrens } 1849fa9e4066Sahrens (void) zonecfg_enddsent(handle); 1850fa9e4066Sahrens 18510209230bSgjelinek if (zonecfg_getpsetent(handle, &psettab) == Z_OK) { 18520209230bSgjelinek (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 18530209230bSgjelinek rt_to_str(RT_DCPU)); 18540209230bSgjelinek if (strcmp(psettab.zone_ncpu_min, psettab.zone_ncpu_max) == 0) 18550209230bSgjelinek (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 18560209230bSgjelinek pt_to_str(PT_NCPUS), psettab.zone_ncpu_max); 18570209230bSgjelinek else 18580209230bSgjelinek (void) fprintf(of, "%s %s=%s-%s\n", cmd_to_str(CMD_SET), 18590209230bSgjelinek pt_to_str(PT_NCPUS), psettab.zone_ncpu_min, 18600209230bSgjelinek psettab.zone_ncpu_max); 18610209230bSgjelinek if (psettab.zone_importance[0] != '\0') 18620209230bSgjelinek (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 18630209230bSgjelinek pt_to_str(PT_IMPORTANCE), psettab.zone_importance); 18640209230bSgjelinek (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 18650209230bSgjelinek } 18660209230bSgjelinek 18670209230bSgjelinek if (zonecfg_getmcapent(handle, &mcaptab) == Z_OK) { 18680209230bSgjelinek char buf[128]; 18690209230bSgjelinek 18700209230bSgjelinek (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD), 18710209230bSgjelinek rt_to_str(RT_MCAP)); 18720209230bSgjelinek bytes_to_units(mcaptab.zone_physmem_cap, buf, sizeof (buf)); 18730209230bSgjelinek (void) fprintf(of, "%s %s=%s\n", cmd_to_str(CMD_SET), 18740209230bSgjelinek pt_to_str(PT_PHYSICAL), buf); 18750209230bSgjelinek (void) fprintf(of, "%s\n", cmd_to_str(CMD_END)); 18760209230bSgjelinek } 18770209230bSgjelinek 1878c97ad5cdSakolb /* 1879c97ad5cdSakolb * There is nothing to export for pcap since this resource is just 1880c97ad5cdSakolb * a container for an rctl alias. 1881c97ad5cdSakolb */ 1882c97ad5cdSakolb 18837c478bd9Sstevel@tonic-gate done: 18847c478bd9Sstevel@tonic-gate if (need_to_close) 18857c478bd9Sstevel@tonic-gate (void) fclose(of); 18867c478bd9Sstevel@tonic-gate } 18877c478bd9Sstevel@tonic-gate 18887c478bd9Sstevel@tonic-gate void 18897c478bd9Sstevel@tonic-gate exit_func(cmd_t *cmd) 18907c478bd9Sstevel@tonic-gate { 18917c478bd9Sstevel@tonic-gate int arg, answer; 1892bbec428eSgjelinek boolean_t arg_err = B_FALSE; 18937c478bd9Sstevel@tonic-gate 18947c478bd9Sstevel@tonic-gate optind = 0; 18957c478bd9Sstevel@tonic-gate while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?F")) != EOF) { 18967c478bd9Sstevel@tonic-gate switch (arg) { 18977c478bd9Sstevel@tonic-gate case '?': 18987c478bd9Sstevel@tonic-gate longer_usage(CMD_EXIT); 1899bbec428eSgjelinek arg_err = B_TRUE; 19007ec75eb8Sgjelinek break; 19017c478bd9Sstevel@tonic-gate case 'F': 1902bbec428eSgjelinek force_exit = B_TRUE; 19037c478bd9Sstevel@tonic-gate break; 19047c478bd9Sstevel@tonic-gate default: 19057c478bd9Sstevel@tonic-gate short_usage(CMD_EXIT); 1906bbec428eSgjelinek arg_err = B_TRUE; 19077ec75eb8Sgjelinek break; 19087ec75eb8Sgjelinek } 19097ec75eb8Sgjelinek } 19107ec75eb8Sgjelinek if (arg_err) 19117c478bd9Sstevel@tonic-gate return; 19127ec75eb8Sgjelinek 19137c478bd9Sstevel@tonic-gate if (optind < cmd->cmd_argc) { 19147c478bd9Sstevel@tonic-gate short_usage(CMD_EXIT); 19157c478bd9Sstevel@tonic-gate return; 19167c478bd9Sstevel@tonic-gate } 19177c478bd9Sstevel@tonic-gate 19187c478bd9Sstevel@tonic-gate if (global_scope || force_exit) { 1919bbec428eSgjelinek time_to_exit = B_TRUE; 19207c478bd9Sstevel@tonic-gate return; 19217c478bd9Sstevel@tonic-gate } 19227c478bd9Sstevel@tonic-gate 1923bbec428eSgjelinek answer = ask_yesno(B_FALSE, "Resource incomplete; really quit"); 19247c478bd9Sstevel@tonic-gate if (answer == -1) { 19257c478bd9Sstevel@tonic-gate zerr(gettext("Resource incomplete, input " 19267c478bd9Sstevel@tonic-gate "not from terminal and -F not specified:\n%s command " 19277c478bd9Sstevel@tonic-gate "ignored, but exiting anyway."), cmd_to_str(CMD_EXIT)); 19287c478bd9Sstevel@tonic-gate exit(Z_ERR); 19297c478bd9Sstevel@tonic-gate } else if (answer == 1) { 1930bbec428eSgjelinek time_to_exit = B_TRUE; 19317c478bd9Sstevel@tonic-gate } 19327c478bd9Sstevel@tonic-gate /* (answer == 0) => just return */ 19337c478bd9Sstevel@tonic-gate } 19347c478bd9Sstevel@tonic-gate 19357c478bd9Sstevel@tonic-gate static int 19367c478bd9Sstevel@tonic-gate validate_zonepath_syntax(char *path) 19377c478bd9Sstevel@tonic-gate { 19387c478bd9Sstevel@tonic-gate if (path[0] != '/') { 19397c478bd9Sstevel@tonic-gate zerr(gettext("%s is not an absolute path."), path); 19407c478bd9Sstevel@tonic-gate return (Z_ERR); 19417c478bd9Sstevel@tonic-gate } 19427c478bd9Sstevel@tonic-gate if (strcmp(path, "/") == 0) { 19437c478bd9Sstevel@tonic-gate zerr(gettext("/ is not allowed as a %s."), 19447c478bd9Sstevel@tonic-gate pt_to_str(PT_ZONEPATH)); 19457c478bd9Sstevel@tonic-gate return (Z_ERR); 19467c478bd9Sstevel@tonic-gate } 19477c478bd9Sstevel@tonic-gate return (Z_OK); 19487c478bd9Sstevel@tonic-gate } 19497c478bd9Sstevel@tonic-gate 19507c478bd9Sstevel@tonic-gate static void 19517c478bd9Sstevel@tonic-gate add_resource(cmd_t *cmd) 19527c478bd9Sstevel@tonic-gate { 19537c478bd9Sstevel@tonic-gate int type; 19540209230bSgjelinek struct zone_psettab tmp_psettab; 19550209230bSgjelinek struct zone_mcaptab tmp_mcaptab; 1956c97ad5cdSakolb uint64_t tmp; 19570209230bSgjelinek uint64_t tmp_mcap; 19580209230bSgjelinek char pool[MAXNAMELEN]; 19597c478bd9Sstevel@tonic-gate 19607c478bd9Sstevel@tonic-gate if ((type = cmd->cmd_res_type) == RT_UNKNOWN) { 1961bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 19627c478bd9Sstevel@tonic-gate goto bad; 19637c478bd9Sstevel@tonic-gate } 19647c478bd9Sstevel@tonic-gate 19657c478bd9Sstevel@tonic-gate switch (type) { 19667c478bd9Sstevel@tonic-gate case RT_FS: 19677c478bd9Sstevel@tonic-gate bzero(&in_progress_fstab, sizeof (in_progress_fstab)); 19687c478bd9Sstevel@tonic-gate return; 19697c478bd9Sstevel@tonic-gate case RT_IPD: 1970087719fdSdp if (state_atleast(ZONE_STATE_INSTALLED)) { 19717c478bd9Sstevel@tonic-gate zerr(gettext("Zone %s already installed; %s %s not " 19727c478bd9Sstevel@tonic-gate "allowed."), zone, cmd_to_str(CMD_ADD), 19737c478bd9Sstevel@tonic-gate rt_to_str(RT_IPD)); 19747c478bd9Sstevel@tonic-gate goto bad; 19757c478bd9Sstevel@tonic-gate } 19767c478bd9Sstevel@tonic-gate bzero(&in_progress_ipdtab, sizeof (in_progress_ipdtab)); 19777c478bd9Sstevel@tonic-gate return; 19787c478bd9Sstevel@tonic-gate case RT_NET: 19797c478bd9Sstevel@tonic-gate bzero(&in_progress_nwiftab, sizeof (in_progress_nwiftab)); 19807c478bd9Sstevel@tonic-gate return; 19817c478bd9Sstevel@tonic-gate case RT_DEVICE: 19827c478bd9Sstevel@tonic-gate bzero(&in_progress_devtab, sizeof (in_progress_devtab)); 19837c478bd9Sstevel@tonic-gate return; 19847c478bd9Sstevel@tonic-gate case RT_RCTL: 19850209230bSgjelinek if (global_zone) 19860209230bSgjelinek zerr(gettext("WARNING: Setting a global zone resource " 19870209230bSgjelinek "control too low could deny\nservice " 19880209230bSgjelinek "to even the root user; " 19890209230bSgjelinek "this could render the system impossible\n" 19900209230bSgjelinek "to administer. Please use caution.")); 19917c478bd9Sstevel@tonic-gate bzero(&in_progress_rctltab, sizeof (in_progress_rctltab)); 19927c478bd9Sstevel@tonic-gate return; 19937c478bd9Sstevel@tonic-gate case RT_ATTR: 19947c478bd9Sstevel@tonic-gate bzero(&in_progress_attrtab, sizeof (in_progress_attrtab)); 19957c478bd9Sstevel@tonic-gate return; 1996fa9e4066Sahrens case RT_DATASET: 1997fa9e4066Sahrens bzero(&in_progress_dstab, sizeof (in_progress_dstab)); 1998fa9e4066Sahrens return; 19990209230bSgjelinek case RT_DCPU: 2000c97ad5cdSakolb /* Make sure there isn't already a cpu-set or cpu-cap entry. */ 20010209230bSgjelinek if (zonecfg_lookup_pset(handle, &tmp_psettab) == Z_OK) { 20020209230bSgjelinek zerr(gettext("The %s resource already exists."), 20030209230bSgjelinek rt_to_str(RT_DCPU)); 20040209230bSgjelinek goto bad; 20050209230bSgjelinek } 2006c97ad5cdSakolb if (zonecfg_get_aliased_rctl(handle, ALIAS_CPUCAP, &tmp) != 2007c97ad5cdSakolb Z_NO_ENTRY) { 2008c97ad5cdSakolb zerr(gettext("The %s resource already exists."), 2009c97ad5cdSakolb rt_to_str(RT_PCAP)); 2010c97ad5cdSakolb goto bad; 2011c97ad5cdSakolb } 20120209230bSgjelinek 20130209230bSgjelinek /* Make sure the pool property isn't set. */ 20140209230bSgjelinek if (zonecfg_get_pool(handle, pool, sizeof (pool)) == Z_OK && 20150209230bSgjelinek strlen(pool) > 0) { 20160209230bSgjelinek zerr(gettext("The %s property is already set. " 20170209230bSgjelinek "A persistent pool is incompatible with\nthe %s " 20180209230bSgjelinek "resource."), 20190209230bSgjelinek pt_to_str(PT_POOL), rt_to_str(RT_DCPU)); 20200209230bSgjelinek goto bad; 20210209230bSgjelinek } 20220209230bSgjelinek 20230209230bSgjelinek bzero(&in_progress_psettab, sizeof (in_progress_psettab)); 20240209230bSgjelinek return; 2025c97ad5cdSakolb case RT_PCAP: 2026c97ad5cdSakolb /* 2027c97ad5cdSakolb * Make sure there isn't already a cpu-set or incompatible 2028c97ad5cdSakolb * cpu-cap rctls. 2029c97ad5cdSakolb */ 2030c97ad5cdSakolb if (zonecfg_lookup_pset(handle, &tmp_psettab) == Z_OK) { 2031c97ad5cdSakolb zerr(gettext("The %s resource already exists."), 2032c97ad5cdSakolb rt_to_str(RT_DCPU)); 2033c97ad5cdSakolb goto bad; 2034c97ad5cdSakolb } 2035c97ad5cdSakolb 2036c97ad5cdSakolb switch (zonecfg_get_aliased_rctl(handle, ALIAS_CPUCAP, &tmp)) { 2037c97ad5cdSakolb case Z_ALIAS_DISALLOW: 2038c97ad5cdSakolb zone_perror(rt_to_str(RT_PCAP), Z_ALIAS_DISALLOW, 2039bbec428eSgjelinek B_FALSE); 2040c97ad5cdSakolb goto bad; 2041c97ad5cdSakolb 2042c97ad5cdSakolb case Z_OK: 2043c97ad5cdSakolb zerr(gettext("The %s resource already exists."), 2044c97ad5cdSakolb rt_to_str(RT_PCAP)); 2045c97ad5cdSakolb goto bad; 2046c97ad5cdSakolb 2047c97ad5cdSakolb default: 2048c97ad5cdSakolb break; 2049c97ad5cdSakolb } 2050c97ad5cdSakolb return; 20510209230bSgjelinek case RT_MCAP: 20520209230bSgjelinek /* 20530209230bSgjelinek * Make sure there isn't already a mem-cap entry or max-swap 20540209230bSgjelinek * or max-locked rctl. 20550209230bSgjelinek */ 20560209230bSgjelinek if (zonecfg_lookup_mcap(handle, &tmp_mcaptab) == Z_OK || 20570209230bSgjelinek zonecfg_get_aliased_rctl(handle, ALIAS_MAXSWAP, &tmp_mcap) 20580209230bSgjelinek == Z_OK || 20590209230bSgjelinek zonecfg_get_aliased_rctl(handle, ALIAS_MAXLOCKEDMEM, 20600209230bSgjelinek &tmp_mcap) == Z_OK) { 20610209230bSgjelinek zerr(gettext("The %s resource or a related resource " 20620209230bSgjelinek "control already exists."), rt_to_str(RT_MCAP)); 20630209230bSgjelinek goto bad; 20640209230bSgjelinek } 20650209230bSgjelinek if (global_zone) 20660209230bSgjelinek zerr(gettext("WARNING: Setting a global zone memory " 20670209230bSgjelinek "cap too low could deny\nservice " 20680209230bSgjelinek "to even the root user; " 20690209230bSgjelinek "this could render the system impossible\n" 20700209230bSgjelinek "to administer. Please use caution.")); 20710209230bSgjelinek bzero(&in_progress_mcaptab, sizeof (in_progress_mcaptab)); 20720209230bSgjelinek return; 20737c478bd9Sstevel@tonic-gate default: 2074bbec428eSgjelinek zone_perror(rt_to_str(type), Z_NO_RESOURCE_TYPE, B_TRUE); 2075bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 2076bbec428eSgjelinek usage(B_FALSE, HELP_RESOURCES); 20777c478bd9Sstevel@tonic-gate } 20787c478bd9Sstevel@tonic-gate bad: 2079bbec428eSgjelinek global_scope = B_TRUE; 20807c478bd9Sstevel@tonic-gate end_op = -1; 20817c478bd9Sstevel@tonic-gate } 20827c478bd9Sstevel@tonic-gate 20837c478bd9Sstevel@tonic-gate static void 20847c478bd9Sstevel@tonic-gate do_complex_rctl_val(complex_property_ptr_t cp) 20857c478bd9Sstevel@tonic-gate { 20867c478bd9Sstevel@tonic-gate struct zone_rctlvaltab *rctlvaltab; 20877c478bd9Sstevel@tonic-gate complex_property_ptr_t cx; 2088bbec428eSgjelinek boolean_t seen_priv = B_FALSE, seen_limit = B_FALSE, 2089bbec428eSgjelinek seen_action = B_FALSE; 20907c478bd9Sstevel@tonic-gate rctlblk_t *rctlblk; 20917c478bd9Sstevel@tonic-gate int err; 20927c478bd9Sstevel@tonic-gate 20937c478bd9Sstevel@tonic-gate if ((rctlvaltab = alloc_rctlvaltab()) == NULL) { 2094bbec428eSgjelinek zone_perror(zone, Z_NOMEM, B_TRUE); 20957c478bd9Sstevel@tonic-gate exit(Z_ERR); 20967c478bd9Sstevel@tonic-gate } 20977c478bd9Sstevel@tonic-gate for (cx = cp; cx != NULL; cx = cx->cp_next) { 20987c478bd9Sstevel@tonic-gate switch (cx->cp_type) { 20997c478bd9Sstevel@tonic-gate case PT_PRIV: 21007c478bd9Sstevel@tonic-gate if (seen_priv) { 21017c478bd9Sstevel@tonic-gate zerr(gettext("%s already specified"), 21027c478bd9Sstevel@tonic-gate pt_to_str(PT_PRIV)); 21037c478bd9Sstevel@tonic-gate goto bad; 21047c478bd9Sstevel@tonic-gate } 21057c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_priv, 21067c478bd9Sstevel@tonic-gate cx->cp_value, 21077c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_priv)); 2108bbec428eSgjelinek seen_priv = B_TRUE; 21097c478bd9Sstevel@tonic-gate break; 21107c478bd9Sstevel@tonic-gate case PT_LIMIT: 21117c478bd9Sstevel@tonic-gate if (seen_limit) { 21127c478bd9Sstevel@tonic-gate zerr(gettext("%s already specified"), 21137c478bd9Sstevel@tonic-gate pt_to_str(PT_LIMIT)); 21147c478bd9Sstevel@tonic-gate goto bad; 21157c478bd9Sstevel@tonic-gate } 21167c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_limit, 21177c478bd9Sstevel@tonic-gate cx->cp_value, 21187c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_limit)); 2119bbec428eSgjelinek seen_limit = B_TRUE; 21207c478bd9Sstevel@tonic-gate break; 21217c478bd9Sstevel@tonic-gate case PT_ACTION: 21227c478bd9Sstevel@tonic-gate if (seen_action) { 21237c478bd9Sstevel@tonic-gate zerr(gettext("%s already specified"), 21247c478bd9Sstevel@tonic-gate pt_to_str(PT_ACTION)); 21257c478bd9Sstevel@tonic-gate goto bad; 21267c478bd9Sstevel@tonic-gate } 21277c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_action, 21287c478bd9Sstevel@tonic-gate cx->cp_value, 21297c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_action)); 2130bbec428eSgjelinek seen_action = B_TRUE; 21317c478bd9Sstevel@tonic-gate break; 21327c478bd9Sstevel@tonic-gate default: 21337c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(PT_VALUE), 2134bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE); 2135bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 2136bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 21377c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctlvaltab); 21387c478bd9Sstevel@tonic-gate return; 21397c478bd9Sstevel@tonic-gate } 21407c478bd9Sstevel@tonic-gate } 21417c478bd9Sstevel@tonic-gate if (!seen_priv) 21427c478bd9Sstevel@tonic-gate zerr(gettext("%s not specified"), pt_to_str(PT_PRIV)); 21437c478bd9Sstevel@tonic-gate if (!seen_limit) 21447c478bd9Sstevel@tonic-gate zerr(gettext("%s not specified"), pt_to_str(PT_LIMIT)); 21457c478bd9Sstevel@tonic-gate if (!seen_action) 21467c478bd9Sstevel@tonic-gate zerr(gettext("%s not specified"), pt_to_str(PT_ACTION)); 21477c478bd9Sstevel@tonic-gate if (!seen_priv || !seen_limit || !seen_action) 21487c478bd9Sstevel@tonic-gate goto bad; 21497c478bd9Sstevel@tonic-gate rctlvaltab->zone_rctlval_next = NULL; 21507c478bd9Sstevel@tonic-gate rctlblk = alloca(rctlblk_size()); 21517c478bd9Sstevel@tonic-gate /* 21527c478bd9Sstevel@tonic-gate * Make sure the rctl value looks roughly correct; we won't know if 21537c478bd9Sstevel@tonic-gate * it's truly OK until we verify the configuration on the target 21547c478bd9Sstevel@tonic-gate * system. 21557c478bd9Sstevel@tonic-gate */ 21567c478bd9Sstevel@tonic-gate if (zonecfg_construct_rctlblk(rctlvaltab, rctlblk) != Z_OK || 21577c478bd9Sstevel@tonic-gate !zonecfg_valid_rctlblk(rctlblk)) { 21587c478bd9Sstevel@tonic-gate zerr(gettext("Invalid %s %s specification"), rt_to_str(RT_RCTL), 21597c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE)); 21607c478bd9Sstevel@tonic-gate goto bad; 21617c478bd9Sstevel@tonic-gate } 21627c478bd9Sstevel@tonic-gate err = zonecfg_add_rctl_value(&in_progress_rctltab, rctlvaltab); 21637c478bd9Sstevel@tonic-gate if (err != Z_OK) 2164bbec428eSgjelinek zone_perror(pt_to_str(PT_VALUE), err, B_TRUE); 21657c478bd9Sstevel@tonic-gate return; 21667c478bd9Sstevel@tonic-gate 21677c478bd9Sstevel@tonic-gate bad: 21687c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctlvaltab); 21697c478bd9Sstevel@tonic-gate } 21707c478bd9Sstevel@tonic-gate 21717c478bd9Sstevel@tonic-gate static void 21727c478bd9Sstevel@tonic-gate add_property(cmd_t *cmd) 21737c478bd9Sstevel@tonic-gate { 21747c478bd9Sstevel@tonic-gate char *prop_id; 21757c478bd9Sstevel@tonic-gate int err, res_type, prop_type; 21767c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 21777c478bd9Sstevel@tonic-gate list_property_ptr_t l; 21787c478bd9Sstevel@tonic-gate 21797c478bd9Sstevel@tonic-gate res_type = resource_scope; 21807c478bd9Sstevel@tonic-gate prop_type = cmd->cmd_prop_name[0]; 21817c478bd9Sstevel@tonic-gate if (res_type == RT_UNKNOWN || prop_type == PT_UNKNOWN) { 2182bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 21837c478bd9Sstevel@tonic-gate return; 21847c478bd9Sstevel@tonic-gate } 21857c478bd9Sstevel@tonic-gate 21867c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs != 1) { 2187bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 21887c478bd9Sstevel@tonic-gate return; 21897c478bd9Sstevel@tonic-gate } 21907c478bd9Sstevel@tonic-gate 2191bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 21927c478bd9Sstevel@tonic-gate return; 21937c478bd9Sstevel@tonic-gate 21947c478bd9Sstevel@tonic-gate switch (res_type) { 21957c478bd9Sstevel@tonic-gate case RT_FS: 21967c478bd9Sstevel@tonic-gate if (prop_type != PT_OPTIONS) { 21977c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 2198bbec428eSgjelinek B_TRUE); 2199bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 2200bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 22017c478bd9Sstevel@tonic-gate return; 22027c478bd9Sstevel@tonic-gate } 22037c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[0]; 22047c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE && 22057c478bd9Sstevel@tonic-gate pp->pv_type != PROP_VAL_LIST) { 22067c478bd9Sstevel@tonic-gate zerr(gettext("A %s or %s value was expected here."), 22077c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_SIMPLE), 22087c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_LIST)); 2209bbec428eSgjelinek saw_error = B_TRUE; 22107c478bd9Sstevel@tonic-gate return; 22117c478bd9Sstevel@tonic-gate } 22127c478bd9Sstevel@tonic-gate if (pp->pv_type == PROP_VAL_SIMPLE) { 22137c478bd9Sstevel@tonic-gate if (pp->pv_simple == NULL) { 2214bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 22157c478bd9Sstevel@tonic-gate return; 22167c478bd9Sstevel@tonic-gate } 22177c478bd9Sstevel@tonic-gate prop_id = pp->pv_simple; 22187c478bd9Sstevel@tonic-gate err = zonecfg_add_fs_option(&in_progress_fstab, 22197c478bd9Sstevel@tonic-gate prop_id); 22207c478bd9Sstevel@tonic-gate if (err != Z_OK) 2221bbec428eSgjelinek zone_perror(pt_to_str(prop_type), err, B_TRUE); 22227c478bd9Sstevel@tonic-gate } else { 22237c478bd9Sstevel@tonic-gate list_property_ptr_t list; 22247c478bd9Sstevel@tonic-gate 22257c478bd9Sstevel@tonic-gate for (list = pp->pv_list; list != NULL; 22267c478bd9Sstevel@tonic-gate list = list->lp_next) { 22277c478bd9Sstevel@tonic-gate prop_id = list->lp_simple; 22287c478bd9Sstevel@tonic-gate if (prop_id == NULL) 22297c478bd9Sstevel@tonic-gate break; 22307c478bd9Sstevel@tonic-gate err = zonecfg_add_fs_option( 22317c478bd9Sstevel@tonic-gate &in_progress_fstab, prop_id); 22327c478bd9Sstevel@tonic-gate if (err != Z_OK) 22337c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), err, 2234bbec428eSgjelinek B_TRUE); 22357c478bd9Sstevel@tonic-gate } 22367c478bd9Sstevel@tonic-gate } 22377c478bd9Sstevel@tonic-gate return; 22387c478bd9Sstevel@tonic-gate case RT_RCTL: 22397c478bd9Sstevel@tonic-gate if (prop_type != PT_VALUE) { 22407c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 2241bbec428eSgjelinek B_TRUE); 2242bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 2243bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 22447c478bd9Sstevel@tonic-gate return; 22457c478bd9Sstevel@tonic-gate } 22467c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[0]; 22477c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_COMPLEX && 22487c478bd9Sstevel@tonic-gate pp->pv_type != PROP_VAL_LIST) { 22497c478bd9Sstevel@tonic-gate zerr(gettext("A %s or %s value was expected here."), 22507c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_COMPLEX), 22517c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_LIST)); 2252bbec428eSgjelinek saw_error = B_TRUE; 22537c478bd9Sstevel@tonic-gate return; 22547c478bd9Sstevel@tonic-gate } 22557c478bd9Sstevel@tonic-gate if (pp->pv_type == PROP_VAL_COMPLEX) { 22567c478bd9Sstevel@tonic-gate do_complex_rctl_val(pp->pv_complex); 22577c478bd9Sstevel@tonic-gate return; 22587c478bd9Sstevel@tonic-gate } 22597c478bd9Sstevel@tonic-gate for (l = pp->pv_list; l != NULL; l = l->lp_next) 22607c478bd9Sstevel@tonic-gate do_complex_rctl_val(l->lp_complex); 22617c478bd9Sstevel@tonic-gate return; 22627c478bd9Sstevel@tonic-gate default: 2263bbec428eSgjelinek zone_perror(rt_to_str(res_type), Z_NO_RESOURCE_TYPE, B_TRUE); 2264bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 2265bbec428eSgjelinek usage(B_FALSE, HELP_RESOURCES); 22667c478bd9Sstevel@tonic-gate return; 22677c478bd9Sstevel@tonic-gate } 22687c478bd9Sstevel@tonic-gate } 22697c478bd9Sstevel@tonic-gate 22700209230bSgjelinek static boolean_t 22710209230bSgjelinek gz_invalid_resource(int type) 22720209230bSgjelinek { 22730209230bSgjelinek return (global_zone && (type == RT_FS || type == RT_IPD || 22740209230bSgjelinek type == RT_NET || type == RT_DEVICE || type == RT_ATTR || 22750209230bSgjelinek type == RT_DATASET)); 22760209230bSgjelinek } 22770209230bSgjelinek 22780209230bSgjelinek static boolean_t 22790209230bSgjelinek gz_invalid_rt_property(int type) 22800209230bSgjelinek { 22810209230bSgjelinek return (global_zone && (type == RT_ZONENAME || type == RT_ZONEPATH || 22820209230bSgjelinek type == RT_AUTOBOOT || type == RT_LIMITPRIV || 2283f4b3ec61Sdh155122 type == RT_BOOTARGS || type == RT_BRAND || type == RT_SCHED || 2284f4b3ec61Sdh155122 type == RT_IPTYPE)); 22850209230bSgjelinek } 22860209230bSgjelinek 22870209230bSgjelinek static boolean_t 22880209230bSgjelinek gz_invalid_property(int type) 22890209230bSgjelinek { 22900209230bSgjelinek return (global_zone && (type == PT_ZONENAME || type == PT_ZONEPATH || 22910209230bSgjelinek type == PT_AUTOBOOT || type == PT_LIMITPRIV || 2292f4b3ec61Sdh155122 type == PT_BOOTARGS || type == PT_BRAND || type == PT_SCHED || 2293f4b3ec61Sdh155122 type == PT_IPTYPE)); 22940209230bSgjelinek } 22950209230bSgjelinek 22967c478bd9Sstevel@tonic-gate void 22977c478bd9Sstevel@tonic-gate add_func(cmd_t *cmd) 22987c478bd9Sstevel@tonic-gate { 22997c478bd9Sstevel@tonic-gate int arg; 2300bbec428eSgjelinek boolean_t arg_err = B_FALSE; 23017c478bd9Sstevel@tonic-gate 23027c478bd9Sstevel@tonic-gate assert(cmd != NULL); 23037c478bd9Sstevel@tonic-gate 23047c478bd9Sstevel@tonic-gate optind = 0; 23057ec75eb8Sgjelinek while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?")) != EOF) { 23067c478bd9Sstevel@tonic-gate switch (arg) { 23077c478bd9Sstevel@tonic-gate case '?': 23087c478bd9Sstevel@tonic-gate longer_usage(CMD_ADD); 2309bbec428eSgjelinek arg_err = B_TRUE; 23107ec75eb8Sgjelinek break; 23117c478bd9Sstevel@tonic-gate default: 23127c478bd9Sstevel@tonic-gate short_usage(CMD_ADD); 2313bbec428eSgjelinek arg_err = B_TRUE; 23147ec75eb8Sgjelinek break; 23157ec75eb8Sgjelinek } 23167ec75eb8Sgjelinek } 23177ec75eb8Sgjelinek if (arg_err) 23187c478bd9Sstevel@tonic-gate return; 23197ec75eb8Sgjelinek 23207c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 23217c478bd9Sstevel@tonic-gate short_usage(CMD_ADD); 23227c478bd9Sstevel@tonic-gate return; 23237c478bd9Sstevel@tonic-gate } 23247c478bd9Sstevel@tonic-gate 23257c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_ADD)) 23267c478bd9Sstevel@tonic-gate return; 23277c478bd9Sstevel@tonic-gate 2328bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 23297c478bd9Sstevel@tonic-gate return; 23307c478bd9Sstevel@tonic-gate if (global_scope) { 23310209230bSgjelinek if (gz_invalid_resource(cmd->cmd_res_type)) { 23320209230bSgjelinek zerr(gettext("Cannot add a %s resource to the " 23330209230bSgjelinek "global zone."), rt_to_str(cmd->cmd_res_type)); 2334bbec428eSgjelinek saw_error = B_TRUE; 23350209230bSgjelinek return; 23360209230bSgjelinek } 23370209230bSgjelinek 2338bbec428eSgjelinek global_scope = B_FALSE; 23397c478bd9Sstevel@tonic-gate resource_scope = cmd->cmd_res_type; 23407c478bd9Sstevel@tonic-gate end_op = CMD_ADD; 23417c478bd9Sstevel@tonic-gate add_resource(cmd); 23427c478bd9Sstevel@tonic-gate } else 23437c478bd9Sstevel@tonic-gate add_property(cmd); 23447c478bd9Sstevel@tonic-gate } 23457c478bd9Sstevel@tonic-gate 2346087719fdSdp /* 2347087719fdSdp * This routine has an unusual implementation, because it tries very 2348087719fdSdp * hard to succeed in the face of a variety of failure modes. 2349087719fdSdp * The most common and most vexing occurs when the index file and 2350087719fdSdp * the /etc/zones/<zonename.xml> file are not both present. In 2351087719fdSdp * this case, delete must eradicate as much of the zone state as is left 2352087719fdSdp * so that the user can later create a new zone with the same name. 2353087719fdSdp */ 23547c478bd9Sstevel@tonic-gate void 23557c478bd9Sstevel@tonic-gate delete_func(cmd_t *cmd) 23567c478bd9Sstevel@tonic-gate { 23577c478bd9Sstevel@tonic-gate int err, arg, answer; 23587c478bd9Sstevel@tonic-gate char line[ZONENAME_MAX + 128]; /* enough to ask a question */ 2359bbec428eSgjelinek boolean_t force = B_FALSE; 2360bbec428eSgjelinek boolean_t arg_err = B_FALSE; 23617c478bd9Sstevel@tonic-gate 23627c478bd9Sstevel@tonic-gate optind = 0; 23637c478bd9Sstevel@tonic-gate while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?F")) != EOF) { 23647c478bd9Sstevel@tonic-gate switch (arg) { 23657c478bd9Sstevel@tonic-gate case '?': 23667c478bd9Sstevel@tonic-gate longer_usage(CMD_DELETE); 2367bbec428eSgjelinek arg_err = B_TRUE; 23687ec75eb8Sgjelinek break; 23697c478bd9Sstevel@tonic-gate case 'F': 2370bbec428eSgjelinek force = B_TRUE; 23717c478bd9Sstevel@tonic-gate break; 23727c478bd9Sstevel@tonic-gate default: 23737c478bd9Sstevel@tonic-gate short_usage(CMD_DELETE); 2374bbec428eSgjelinek arg_err = B_TRUE; 23757ec75eb8Sgjelinek break; 23767ec75eb8Sgjelinek } 23777ec75eb8Sgjelinek } 23787ec75eb8Sgjelinek if (arg_err) 23797c478bd9Sstevel@tonic-gate return; 23807ec75eb8Sgjelinek 23817c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 23827c478bd9Sstevel@tonic-gate short_usage(CMD_DELETE); 23837c478bd9Sstevel@tonic-gate return; 23847c478bd9Sstevel@tonic-gate } 23857c478bd9Sstevel@tonic-gate 23867c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_DELETE)) 23877c478bd9Sstevel@tonic-gate return; 23887c478bd9Sstevel@tonic-gate 2389087719fdSdp if (!force) { 2390087719fdSdp /* 2391087719fdSdp * Initialize sets up the global called "handle" and warns the 2392087719fdSdp * user if the zone is not configured. In force mode, we don't 2393087719fdSdp * trust that evaluation, and hence skip it. (We don't need the 2394087719fdSdp * handle to be loaded anyway, since zonecfg_destroy is done by 2395087719fdSdp * zonename). However, we also have to take care to emulate the 2396087719fdSdp * messages spit out by initialize; see below. 2397087719fdSdp */ 2398bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 23997c478bd9Sstevel@tonic-gate return; 24007c478bd9Sstevel@tonic-gate 24017c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), 24027c478bd9Sstevel@tonic-gate gettext("Are you sure you want to delete zone %s"), zone); 2403bbec428eSgjelinek if ((answer = ask_yesno(B_FALSE, line)) == -1) { 2404087719fdSdp zerr(gettext("Input not from terminal and -F not " 2405087719fdSdp "specified:\n%s command ignored, exiting."), 2406087719fdSdp cmd_to_str(CMD_DELETE)); 24077c478bd9Sstevel@tonic-gate exit(Z_ERR); 24087c478bd9Sstevel@tonic-gate } 24097c478bd9Sstevel@tonic-gate if (answer != 1) 24107c478bd9Sstevel@tonic-gate return; 24117c478bd9Sstevel@tonic-gate } 24127c478bd9Sstevel@tonic-gate 2413087719fdSdp if ((err = zonecfg_destroy(zone, force)) != Z_OK) { 2414087719fdSdp if ((err == Z_BAD_ZONE_STATE) && !force) { 2415087719fdSdp zerr(gettext("Zone %s not in %s state; %s not " 2416087719fdSdp "allowed. Use -F to force %s."), 2417087719fdSdp zone, zone_state_str(ZONE_STATE_CONFIGURED), 2418087719fdSdp cmd_to_str(CMD_DELETE), cmd_to_str(CMD_DELETE)); 2419087719fdSdp } else { 2420bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 24217c478bd9Sstevel@tonic-gate } 2422087719fdSdp } 2423bbec428eSgjelinek need_to_commit = B_FALSE; 2424087719fdSdp 2425087719fdSdp /* 2426087719fdSdp * Emulate initialize's messaging; if there wasn't a valid handle to 2427087719fdSdp * begin with, then user had typed delete (or delete -F) multiple 2428087719fdSdp * times. So we emit a message. 2429087719fdSdp * 2430087719fdSdp * We only do this in the 'force' case because normally, initialize() 2431087719fdSdp * takes care of this for us. 2432087719fdSdp */ 2433087719fdSdp if (force && zonecfg_check_handle(handle) != Z_OK && interactive_mode) 2434087719fdSdp (void) printf(gettext("Use '%s' to begin " 2435087719fdSdp "configuring a new zone.\n"), cmd_to_str(CMD_CREATE)); 24367c478bd9Sstevel@tonic-gate 24377c478bd9Sstevel@tonic-gate /* 24387c478bd9Sstevel@tonic-gate * Time for a new handle: finish the old one off first 24397c478bd9Sstevel@tonic-gate * then get a new one properly to avoid leaks. 24407c478bd9Sstevel@tonic-gate */ 2441087719fdSdp if (got_handle) { 24427c478bd9Sstevel@tonic-gate zonecfg_fini_handle(handle); 24437c478bd9Sstevel@tonic-gate if ((handle = zonecfg_init_handle()) == NULL) { 2444bbec428eSgjelinek zone_perror(execname, Z_NOMEM, B_TRUE); 24457c478bd9Sstevel@tonic-gate exit(Z_ERR); 24467c478bd9Sstevel@tonic-gate } 24477c478bd9Sstevel@tonic-gate if ((err = zonecfg_get_handle(zone, handle)) != Z_OK) { 24487c478bd9Sstevel@tonic-gate /* If there was no zone before, that's OK */ 24497c478bd9Sstevel@tonic-gate if (err != Z_NO_ZONE) 2450bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 2451bbec428eSgjelinek got_handle = B_FALSE; 24527c478bd9Sstevel@tonic-gate } 24537c478bd9Sstevel@tonic-gate } 2454087719fdSdp } 24557c478bd9Sstevel@tonic-gate 24567c478bd9Sstevel@tonic-gate static int 2457bbec428eSgjelinek fill_in_fstab(cmd_t *cmd, struct zone_fstab *fstab, boolean_t fill_in_only) 24587c478bd9Sstevel@tonic-gate { 24597c478bd9Sstevel@tonic-gate int err, i; 24607c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 24617c478bd9Sstevel@tonic-gate 2462bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK) 24637c478bd9Sstevel@tonic-gate return (err); 24647c478bd9Sstevel@tonic-gate 2465e193d1e6Svp157776 bzero(fstab, sizeof (*fstab)); 24667c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 24677c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i]; 24687c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 24697c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here.")); 2470bbec428eSgjelinek saw_error = B_TRUE; 24717c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 24727c478bd9Sstevel@tonic-gate } 24737c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) { 24747c478bd9Sstevel@tonic-gate case PT_DIR: 24757c478bd9Sstevel@tonic-gate (void) strlcpy(fstab->zone_fs_dir, pp->pv_simple, 24767c478bd9Sstevel@tonic-gate sizeof (fstab->zone_fs_dir)); 24777c478bd9Sstevel@tonic-gate break; 24787c478bd9Sstevel@tonic-gate case PT_SPECIAL: 24797c478bd9Sstevel@tonic-gate (void) strlcpy(fstab->zone_fs_special, pp->pv_simple, 24807c478bd9Sstevel@tonic-gate sizeof (fstab->zone_fs_special)); 24817c478bd9Sstevel@tonic-gate break; 24827c478bd9Sstevel@tonic-gate case PT_RAW: 24837c478bd9Sstevel@tonic-gate (void) strlcpy(fstab->zone_fs_raw, pp->pv_simple, 24847c478bd9Sstevel@tonic-gate sizeof (fstab->zone_fs_raw)); 24857c478bd9Sstevel@tonic-gate break; 24867c478bd9Sstevel@tonic-gate case PT_TYPE: 24877c478bd9Sstevel@tonic-gate (void) strlcpy(fstab->zone_fs_type, pp->pv_simple, 24887c478bd9Sstevel@tonic-gate sizeof (fstab->zone_fs_type)); 24897c478bd9Sstevel@tonic-gate break; 24907c478bd9Sstevel@tonic-gate default: 24917c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 2492bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE); 24937c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 24947c478bd9Sstevel@tonic-gate } 24957c478bd9Sstevel@tonic-gate } 24967c478bd9Sstevel@tonic-gate if (fill_in_only) 24977c478bd9Sstevel@tonic-gate return (Z_OK); 24987c478bd9Sstevel@tonic-gate return (zonecfg_lookup_filesystem(handle, fstab)); 24997c478bd9Sstevel@tonic-gate } 25007c478bd9Sstevel@tonic-gate 25017c478bd9Sstevel@tonic-gate static int 2502bbec428eSgjelinek fill_in_ipdtab(cmd_t *cmd, struct zone_fstab *ipdtab, boolean_t fill_in_only) 25037c478bd9Sstevel@tonic-gate { 25047c478bd9Sstevel@tonic-gate int err, i; 25057c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 25067c478bd9Sstevel@tonic-gate 2507bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK) 25087c478bd9Sstevel@tonic-gate return (err); 25097c478bd9Sstevel@tonic-gate 2510e193d1e6Svp157776 bzero(ipdtab, sizeof (*ipdtab)); 25117c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 25127c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i]; 25137c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 25147c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here.")); 2515bbec428eSgjelinek saw_error = B_TRUE; 25167c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 25177c478bd9Sstevel@tonic-gate } 25187c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) { 25197c478bd9Sstevel@tonic-gate case PT_DIR: 25207c478bd9Sstevel@tonic-gate (void) strlcpy(ipdtab->zone_fs_dir, pp->pv_simple, 25217c478bd9Sstevel@tonic-gate sizeof (ipdtab->zone_fs_dir)); 25227c478bd9Sstevel@tonic-gate break; 25237c478bd9Sstevel@tonic-gate default: 25247c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 2525bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE); 25267c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 25277c478bd9Sstevel@tonic-gate } 25287c478bd9Sstevel@tonic-gate } 25297c478bd9Sstevel@tonic-gate if (fill_in_only) 25307c478bd9Sstevel@tonic-gate return (Z_OK); 25317c478bd9Sstevel@tonic-gate return (zonecfg_lookup_ipd(handle, ipdtab)); 25327c478bd9Sstevel@tonic-gate } 25337c478bd9Sstevel@tonic-gate 25347c478bd9Sstevel@tonic-gate static int 2535bbec428eSgjelinek fill_in_nwiftab(cmd_t *cmd, struct zone_nwiftab *nwiftab, 2536bbec428eSgjelinek boolean_t fill_in_only) 25377c478bd9Sstevel@tonic-gate { 25387c478bd9Sstevel@tonic-gate int err, i; 25397c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 25407c478bd9Sstevel@tonic-gate 2541bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK) 25427c478bd9Sstevel@tonic-gate return (err); 25437c478bd9Sstevel@tonic-gate 2544e193d1e6Svp157776 bzero(nwiftab, sizeof (*nwiftab)); 25457c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 25467c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i]; 25477c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 25487c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here.")); 2549bbec428eSgjelinek saw_error = B_TRUE; 25507c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 25517c478bd9Sstevel@tonic-gate } 25527c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) { 25537c478bd9Sstevel@tonic-gate case PT_ADDRESS: 25547c478bd9Sstevel@tonic-gate (void) strlcpy(nwiftab->zone_nwif_address, 25557c478bd9Sstevel@tonic-gate pp->pv_simple, sizeof (nwiftab->zone_nwif_address)); 25567c478bd9Sstevel@tonic-gate break; 25577c478bd9Sstevel@tonic-gate case PT_PHYSICAL: 25587c478bd9Sstevel@tonic-gate (void) strlcpy(nwiftab->zone_nwif_physical, 25597c478bd9Sstevel@tonic-gate pp->pv_simple, 25607c478bd9Sstevel@tonic-gate sizeof (nwiftab->zone_nwif_physical)); 25617c478bd9Sstevel@tonic-gate break; 2562de860bd9Sgfaden case PT_DEFROUTER: 2563de860bd9Sgfaden (void) strlcpy(nwiftab->zone_nwif_defrouter, 2564de860bd9Sgfaden pp->pv_simple, 2565de860bd9Sgfaden sizeof (nwiftab->zone_nwif_defrouter)); 2566de860bd9Sgfaden break; 25677c478bd9Sstevel@tonic-gate default: 25687c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 2569bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE); 25707c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 25717c478bd9Sstevel@tonic-gate } 25727c478bd9Sstevel@tonic-gate } 25737c478bd9Sstevel@tonic-gate if (fill_in_only) 25747c478bd9Sstevel@tonic-gate return (Z_OK); 25757c478bd9Sstevel@tonic-gate err = zonecfg_lookup_nwif(handle, nwiftab); 25767c478bd9Sstevel@tonic-gate return (err); 25777c478bd9Sstevel@tonic-gate } 25787c478bd9Sstevel@tonic-gate 25797c478bd9Sstevel@tonic-gate static int 2580bbec428eSgjelinek fill_in_devtab(cmd_t *cmd, struct zone_devtab *devtab, boolean_t fill_in_only) 25817c478bd9Sstevel@tonic-gate { 25827c478bd9Sstevel@tonic-gate int err, i; 25837c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 25847c478bd9Sstevel@tonic-gate 2585bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK) 25867c478bd9Sstevel@tonic-gate return (err); 25877c478bd9Sstevel@tonic-gate 2588e193d1e6Svp157776 bzero(devtab, sizeof (*devtab)); 25897c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 25907c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i]; 25917c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 25927c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here.")); 2593bbec428eSgjelinek saw_error = B_TRUE; 25947c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 25957c478bd9Sstevel@tonic-gate } 25967c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) { 25977c478bd9Sstevel@tonic-gate case PT_MATCH: 25987c478bd9Sstevel@tonic-gate (void) strlcpy(devtab->zone_dev_match, pp->pv_simple, 25997c478bd9Sstevel@tonic-gate sizeof (devtab->zone_dev_match)); 26007c478bd9Sstevel@tonic-gate break; 26017c478bd9Sstevel@tonic-gate default: 26027c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 2603bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE); 26047c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 26057c478bd9Sstevel@tonic-gate } 26067c478bd9Sstevel@tonic-gate } 26077c478bd9Sstevel@tonic-gate if (fill_in_only) 26087c478bd9Sstevel@tonic-gate return (Z_OK); 26097c478bd9Sstevel@tonic-gate err = zonecfg_lookup_dev(handle, devtab); 26107c478bd9Sstevel@tonic-gate return (err); 26117c478bd9Sstevel@tonic-gate } 26127c478bd9Sstevel@tonic-gate 26137c478bd9Sstevel@tonic-gate static int 2614bbec428eSgjelinek fill_in_rctltab(cmd_t *cmd, struct zone_rctltab *rctltab, 2615bbec428eSgjelinek boolean_t fill_in_only) 26167c478bd9Sstevel@tonic-gate { 26177c478bd9Sstevel@tonic-gate int err, i; 26187c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 26197c478bd9Sstevel@tonic-gate 2620bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK) 26217c478bd9Sstevel@tonic-gate return (err); 26227c478bd9Sstevel@tonic-gate 2623e193d1e6Svp157776 bzero(rctltab, sizeof (*rctltab)); 26247c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 26257c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i]; 26267c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 26277c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here.")); 2628bbec428eSgjelinek saw_error = B_TRUE; 26297c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 26307c478bd9Sstevel@tonic-gate } 26317c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) { 26327c478bd9Sstevel@tonic-gate case PT_NAME: 26337c478bd9Sstevel@tonic-gate (void) strlcpy(rctltab->zone_rctl_name, pp->pv_simple, 26347c478bd9Sstevel@tonic-gate sizeof (rctltab->zone_rctl_name)); 26357c478bd9Sstevel@tonic-gate break; 26367c478bd9Sstevel@tonic-gate default: 26377c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 2638bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE); 26397c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 26407c478bd9Sstevel@tonic-gate } 26417c478bd9Sstevel@tonic-gate } 26427c478bd9Sstevel@tonic-gate if (fill_in_only) 26437c478bd9Sstevel@tonic-gate return (Z_OK); 26447c478bd9Sstevel@tonic-gate err = zonecfg_lookup_rctl(handle, rctltab); 26457c478bd9Sstevel@tonic-gate return (err); 26467c478bd9Sstevel@tonic-gate } 26477c478bd9Sstevel@tonic-gate 26487c478bd9Sstevel@tonic-gate static int 2649bbec428eSgjelinek fill_in_attrtab(cmd_t *cmd, struct zone_attrtab *attrtab, 2650bbec428eSgjelinek boolean_t fill_in_only) 26517c478bd9Sstevel@tonic-gate { 26527c478bd9Sstevel@tonic-gate int err, i; 26537c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 26547c478bd9Sstevel@tonic-gate 2655bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK) 26567c478bd9Sstevel@tonic-gate return (err); 26577c478bd9Sstevel@tonic-gate 2658e193d1e6Svp157776 bzero(attrtab, sizeof (*attrtab)); 26597c478bd9Sstevel@tonic-gate for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 26607c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[i]; 26617c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 26627c478bd9Sstevel@tonic-gate zerr(gettext("A simple value was expected here.")); 2663bbec428eSgjelinek saw_error = B_TRUE; 26647c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 26657c478bd9Sstevel@tonic-gate } 26667c478bd9Sstevel@tonic-gate switch (cmd->cmd_prop_name[i]) { 26677c478bd9Sstevel@tonic-gate case PT_NAME: 26687c478bd9Sstevel@tonic-gate (void) strlcpy(attrtab->zone_attr_name, pp->pv_simple, 26697c478bd9Sstevel@tonic-gate sizeof (attrtab->zone_attr_name)); 26707c478bd9Sstevel@tonic-gate break; 26717c478bd9Sstevel@tonic-gate case PT_TYPE: 26727c478bd9Sstevel@tonic-gate (void) strlcpy(attrtab->zone_attr_type, pp->pv_simple, 26737c478bd9Sstevel@tonic-gate sizeof (attrtab->zone_attr_type)); 26747c478bd9Sstevel@tonic-gate break; 26757c478bd9Sstevel@tonic-gate case PT_VALUE: 26767c478bd9Sstevel@tonic-gate (void) strlcpy(attrtab->zone_attr_value, pp->pv_simple, 26777c478bd9Sstevel@tonic-gate sizeof (attrtab->zone_attr_value)); 26787c478bd9Sstevel@tonic-gate break; 26797c478bd9Sstevel@tonic-gate default: 26807c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 2681bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE); 26827c478bd9Sstevel@tonic-gate return (Z_INSUFFICIENT_SPEC); 26837c478bd9Sstevel@tonic-gate } 26847c478bd9Sstevel@tonic-gate } 26857c478bd9Sstevel@tonic-gate if (fill_in_only) 26867c478bd9Sstevel@tonic-gate return (Z_OK); 26877c478bd9Sstevel@tonic-gate err = zonecfg_lookup_attr(handle, attrtab); 26887c478bd9Sstevel@tonic-gate return (err); 26897c478bd9Sstevel@tonic-gate } 26907c478bd9Sstevel@tonic-gate 2691fa9e4066Sahrens static int 2692bbec428eSgjelinek fill_in_dstab(cmd_t *cmd, struct zone_dstab *dstab, boolean_t fill_in_only) 2693fa9e4066Sahrens { 2694fa9e4066Sahrens int err, i; 2695fa9e4066Sahrens property_value_ptr_t pp; 2696fa9e4066Sahrens 2697bbec428eSgjelinek if ((err = initialize(B_TRUE)) != Z_OK) 2698fa9e4066Sahrens return (err); 2699fa9e4066Sahrens 2700fa9e4066Sahrens dstab->zone_dataset_name[0] = '\0'; 2701fa9e4066Sahrens for (i = 0; i < cmd->cmd_prop_nv_pairs; i++) { 2702fa9e4066Sahrens pp = cmd->cmd_property_ptr[i]; 2703fa9e4066Sahrens if (pp->pv_type != PROP_VAL_SIMPLE || pp->pv_simple == NULL) { 2704fa9e4066Sahrens zerr(gettext("A simple value was expected here.")); 2705bbec428eSgjelinek saw_error = B_TRUE; 2706fa9e4066Sahrens return (Z_INSUFFICIENT_SPEC); 2707fa9e4066Sahrens } 2708fa9e4066Sahrens switch (cmd->cmd_prop_name[i]) { 2709fa9e4066Sahrens case PT_NAME: 2710fa9e4066Sahrens (void) strlcpy(dstab->zone_dataset_name, pp->pv_simple, 2711fa9e4066Sahrens sizeof (dstab->zone_dataset_name)); 2712fa9e4066Sahrens break; 2713fa9e4066Sahrens default: 2714fa9e4066Sahrens zone_perror(pt_to_str(cmd->cmd_prop_name[i]), 2715bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE); 2716fa9e4066Sahrens return (Z_INSUFFICIENT_SPEC); 2717fa9e4066Sahrens } 2718fa9e4066Sahrens } 2719fa9e4066Sahrens if (fill_in_only) 2720fa9e4066Sahrens return (Z_OK); 2721fa9e4066Sahrens return (zonecfg_lookup_ds(handle, dstab)); 2722fa9e4066Sahrens } 2723fa9e4066Sahrens 27247c478bd9Sstevel@tonic-gate static void 27250209230bSgjelinek remove_aliased_rctl(int type, char *name) 27267c478bd9Sstevel@tonic-gate { 27270209230bSgjelinek int err; 27280209230bSgjelinek uint64_t tmp; 27297c478bd9Sstevel@tonic-gate 27300209230bSgjelinek if ((err = zonecfg_get_aliased_rctl(handle, name, &tmp)) != Z_OK) { 27310209230bSgjelinek zerr("%s %s: %s", cmd_to_str(CMD_CLEAR), pt_to_str(type), 27320209230bSgjelinek zonecfg_strerror(err)); 2733bbec428eSgjelinek saw_error = B_TRUE; 27347c478bd9Sstevel@tonic-gate return; 27357c478bd9Sstevel@tonic-gate } 27360209230bSgjelinek if ((err = zonecfg_rm_aliased_rctl(handle, name)) != Z_OK) { 27370209230bSgjelinek zerr("%s %s: %s", cmd_to_str(CMD_CLEAR), pt_to_str(type), 27380209230bSgjelinek zonecfg_strerror(err)); 2739bbec428eSgjelinek saw_error = B_TRUE; 27400209230bSgjelinek } else { 2741bbec428eSgjelinek need_to_commit = B_TRUE; 27420209230bSgjelinek } 27430209230bSgjelinek } 27447c478bd9Sstevel@tonic-gate 27450209230bSgjelinek static boolean_t 27460209230bSgjelinek prompt_remove_resource(cmd_t *cmd, char *rsrc) 27470209230bSgjelinek { 27480209230bSgjelinek int num; 27490209230bSgjelinek int answer; 27500209230bSgjelinek int arg; 27510209230bSgjelinek boolean_t force = B_FALSE; 27520209230bSgjelinek char prompt[128]; 2753bbec428eSgjelinek boolean_t arg_err = B_FALSE; 27547c478bd9Sstevel@tonic-gate 27550209230bSgjelinek optind = 0; 27560209230bSgjelinek while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "F")) != EOF) { 27570209230bSgjelinek switch (arg) { 27580209230bSgjelinek case 'F': 27590209230bSgjelinek force = B_TRUE; 27600209230bSgjelinek break; 27610209230bSgjelinek default: 2762bbec428eSgjelinek arg_err = B_TRUE; 27637ec75eb8Sgjelinek break; 27647ec75eb8Sgjelinek } 27657ec75eb8Sgjelinek } 27667ec75eb8Sgjelinek if (arg_err) 27670209230bSgjelinek return (B_FALSE); 27687ec75eb8Sgjelinek 27690209230bSgjelinek 27700209230bSgjelinek num = zonecfg_num_resources(handle, rsrc); 27710209230bSgjelinek 27720209230bSgjelinek if (num == 0) { 27730209230bSgjelinek z_cmd_rt_perror(CMD_REMOVE, cmd->cmd_res_type, Z_NO_ENTRY, 2774bbec428eSgjelinek B_TRUE); 27750209230bSgjelinek return (B_FALSE); 27760209230bSgjelinek } 27770209230bSgjelinek if (num > 1 && !force) { 27780209230bSgjelinek if (!interactive_mode) { 27790209230bSgjelinek zerr(gettext("There are multiple instances of this " 27800209230bSgjelinek "resource. Either qualify the resource to\n" 27810209230bSgjelinek "remove a single instance or use the -F option to " 27820209230bSgjelinek "remove all instances.")); 2783bbec428eSgjelinek saw_error = B_TRUE; 27840209230bSgjelinek return (B_FALSE); 27850209230bSgjelinek } 27860209230bSgjelinek (void) snprintf(prompt, sizeof (prompt), gettext( 27870209230bSgjelinek "Are you sure you want to remove ALL '%s' resources"), 27880209230bSgjelinek rsrc); 2789bbec428eSgjelinek answer = ask_yesno(B_FALSE, prompt); 27900209230bSgjelinek if (answer == -1) { 27910209230bSgjelinek zerr(gettext("Resource incomplete.")); 27920209230bSgjelinek return (B_FALSE); 27930209230bSgjelinek } 27940209230bSgjelinek if (answer != 1) 27950209230bSgjelinek return (B_FALSE); 27960209230bSgjelinek } 27970209230bSgjelinek return (B_TRUE); 27980209230bSgjelinek } 27990209230bSgjelinek 28000209230bSgjelinek static void 28010209230bSgjelinek remove_fs(cmd_t *cmd) 28020209230bSgjelinek { 28030209230bSgjelinek int err; 28040209230bSgjelinek 28050209230bSgjelinek /* traditional, qualified fs removal */ 28060209230bSgjelinek if (cmd->cmd_prop_nv_pairs > 0) { 28070209230bSgjelinek struct zone_fstab fstab; 28080209230bSgjelinek 2809bbec428eSgjelinek if ((err = fill_in_fstab(cmd, &fstab, B_FALSE)) != Z_OK) { 2810bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_FS, err, B_TRUE); 28117c478bd9Sstevel@tonic-gate return; 28127c478bd9Sstevel@tonic-gate } 28137c478bd9Sstevel@tonic-gate if ((err = zonecfg_delete_filesystem(handle, &fstab)) != Z_OK) 2814bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_FS, err, B_TRUE); 28157c478bd9Sstevel@tonic-gate else 2816bbec428eSgjelinek need_to_commit = B_TRUE; 28177c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(fstab.zone_fs_options); 28187c478bd9Sstevel@tonic-gate return; 28190209230bSgjelinek } 28200209230bSgjelinek 28210209230bSgjelinek /* 28220209230bSgjelinek * unqualified fs removal. remove all fs's but prompt if more 28230209230bSgjelinek * than one. 28240209230bSgjelinek */ 28250209230bSgjelinek if (!prompt_remove_resource(cmd, "fs")) 28260209230bSgjelinek return; 28270209230bSgjelinek 28280209230bSgjelinek if ((err = zonecfg_del_all_resources(handle, "fs")) != Z_OK) 2829bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_FS, err, B_TRUE); 28300209230bSgjelinek else 2831bbec428eSgjelinek need_to_commit = B_TRUE; 28320209230bSgjelinek } 28330209230bSgjelinek 28340209230bSgjelinek static void 28350209230bSgjelinek remove_ipd(cmd_t *cmd) 28360209230bSgjelinek { 28370209230bSgjelinek int err; 28380209230bSgjelinek 2839087719fdSdp if (state_atleast(ZONE_STATE_INSTALLED)) { 28400209230bSgjelinek zerr(gettext("Zone %s already installed; %s %s not allowed."), 28410209230bSgjelinek zone, cmd_to_str(CMD_REMOVE), rt_to_str(RT_IPD)); 28427c478bd9Sstevel@tonic-gate return; 28437c478bd9Sstevel@tonic-gate } 28440209230bSgjelinek 28450209230bSgjelinek /* traditional, qualified ipd removal */ 28460209230bSgjelinek if (cmd->cmd_prop_nv_pairs > 0) { 28470209230bSgjelinek struct zone_fstab fstab; 28480209230bSgjelinek 2849bbec428eSgjelinek if ((err = fill_in_ipdtab(cmd, &fstab, B_FALSE)) != Z_OK) { 2850bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_IPD, err, B_TRUE); 28517c478bd9Sstevel@tonic-gate return; 28527c478bd9Sstevel@tonic-gate } 28537c478bd9Sstevel@tonic-gate if ((err = zonecfg_delete_ipd(handle, &fstab)) != Z_OK) 2854bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_IPD, err, B_TRUE); 28557c478bd9Sstevel@tonic-gate else 2856bbec428eSgjelinek need_to_commit = B_TRUE; 28577c478bd9Sstevel@tonic-gate return; 28580209230bSgjelinek } 28590209230bSgjelinek 28600209230bSgjelinek /* 28610209230bSgjelinek * unqualified ipd removal. remove all ipds but prompt if more 28620209230bSgjelinek * than one. 28630209230bSgjelinek */ 28640209230bSgjelinek if (!prompt_remove_resource(cmd, "inherit-pkg-dir")) 28650209230bSgjelinek return; 28660209230bSgjelinek 28670209230bSgjelinek if ((err = zonecfg_del_all_resources(handle, "inherit-pkg-dir")) 28680209230bSgjelinek != Z_OK) 2869bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_IPD, err, B_TRUE); 28700209230bSgjelinek else 2871bbec428eSgjelinek need_to_commit = B_TRUE; 28720209230bSgjelinek } 28730209230bSgjelinek 28740209230bSgjelinek static void 28750209230bSgjelinek remove_net(cmd_t *cmd) 28760209230bSgjelinek { 28770209230bSgjelinek int err; 28780209230bSgjelinek 28790209230bSgjelinek /* traditional, qualified net removal */ 28800209230bSgjelinek if (cmd->cmd_prop_nv_pairs > 0) { 28810209230bSgjelinek struct zone_nwiftab nwiftab; 28820209230bSgjelinek 2883bbec428eSgjelinek if ((err = fill_in_nwiftab(cmd, &nwiftab, B_FALSE)) != Z_OK) { 2884bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_NET, err, B_TRUE); 28857c478bd9Sstevel@tonic-gate return; 28867c478bd9Sstevel@tonic-gate } 28877c478bd9Sstevel@tonic-gate if ((err = zonecfg_delete_nwif(handle, &nwiftab)) != Z_OK) 2888bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_NET, err, B_TRUE); 28897c478bd9Sstevel@tonic-gate else 2890bbec428eSgjelinek need_to_commit = B_TRUE; 28917c478bd9Sstevel@tonic-gate return; 28920209230bSgjelinek } 28930209230bSgjelinek 28940209230bSgjelinek /* 28950209230bSgjelinek * unqualified net removal. remove all nets but prompt if more 28960209230bSgjelinek * than one. 28970209230bSgjelinek */ 28980209230bSgjelinek if (!prompt_remove_resource(cmd, "net")) 28990209230bSgjelinek return; 29000209230bSgjelinek 29010209230bSgjelinek if ((err = zonecfg_del_all_resources(handle, "net")) != Z_OK) 2902bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_NET, err, B_TRUE); 29030209230bSgjelinek else 2904bbec428eSgjelinek need_to_commit = B_TRUE; 29050209230bSgjelinek } 29060209230bSgjelinek 29070209230bSgjelinek static void 29080209230bSgjelinek remove_device(cmd_t *cmd) 29090209230bSgjelinek { 29100209230bSgjelinek int err; 29110209230bSgjelinek 29120209230bSgjelinek /* traditional, qualified device removal */ 29130209230bSgjelinek if (cmd->cmd_prop_nv_pairs > 0) { 29140209230bSgjelinek struct zone_devtab devtab; 29150209230bSgjelinek 2916bbec428eSgjelinek if ((err = fill_in_devtab(cmd, &devtab, B_FALSE)) != Z_OK) { 2917bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DEVICE, err, B_TRUE); 29187c478bd9Sstevel@tonic-gate return; 29197c478bd9Sstevel@tonic-gate } 29207c478bd9Sstevel@tonic-gate if ((err = zonecfg_delete_dev(handle, &devtab)) != Z_OK) 2921bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DEVICE, err, B_TRUE); 29227c478bd9Sstevel@tonic-gate else 2923bbec428eSgjelinek need_to_commit = B_TRUE; 29247c478bd9Sstevel@tonic-gate return; 29250209230bSgjelinek } 29260209230bSgjelinek 29270209230bSgjelinek /* 29280209230bSgjelinek * unqualified device removal. remove all devices but prompt if more 29290209230bSgjelinek * than one. 29300209230bSgjelinek */ 29310209230bSgjelinek if (!prompt_remove_resource(cmd, "device")) 29320209230bSgjelinek return; 29330209230bSgjelinek 29340209230bSgjelinek if ((err = zonecfg_del_all_resources(handle, "device")) != Z_OK) 2935bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DEVICE, err, B_TRUE); 29360209230bSgjelinek else 2937bbec428eSgjelinek need_to_commit = B_TRUE; 29380209230bSgjelinek } 29390209230bSgjelinek 29400209230bSgjelinek static void 29410209230bSgjelinek remove_attr(cmd_t *cmd) 29420209230bSgjelinek { 29430209230bSgjelinek int err; 29440209230bSgjelinek 29450209230bSgjelinek /* traditional, qualified attr removal */ 29460209230bSgjelinek if (cmd->cmd_prop_nv_pairs > 0) { 29470209230bSgjelinek struct zone_attrtab attrtab; 29480209230bSgjelinek 2949bbec428eSgjelinek if ((err = fill_in_attrtab(cmd, &attrtab, B_FALSE)) != Z_OK) { 2950bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_ATTR, err, B_TRUE); 29510209230bSgjelinek return; 29520209230bSgjelinek } 29530209230bSgjelinek if ((err = zonecfg_delete_attr(handle, &attrtab)) != Z_OK) 2954bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_ATTR, err, B_TRUE); 29550209230bSgjelinek else 2956bbec428eSgjelinek need_to_commit = B_TRUE; 29570209230bSgjelinek return; 29580209230bSgjelinek } 29590209230bSgjelinek 29600209230bSgjelinek /* 29610209230bSgjelinek * unqualified attr removal. remove all attrs but prompt if more 29620209230bSgjelinek * than one. 29630209230bSgjelinek */ 29640209230bSgjelinek if (!prompt_remove_resource(cmd, "attr")) 29650209230bSgjelinek return; 29660209230bSgjelinek 29670209230bSgjelinek if ((err = zonecfg_del_all_resources(handle, "attr")) != Z_OK) 2968bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_ATTR, err, B_TRUE); 29690209230bSgjelinek else 2970bbec428eSgjelinek need_to_commit = B_TRUE; 29710209230bSgjelinek } 29720209230bSgjelinek 29730209230bSgjelinek static void 29740209230bSgjelinek remove_dataset(cmd_t *cmd) 29750209230bSgjelinek { 29760209230bSgjelinek int err; 29770209230bSgjelinek 29780209230bSgjelinek /* traditional, qualified dataset removal */ 29790209230bSgjelinek if (cmd->cmd_prop_nv_pairs > 0) { 29800209230bSgjelinek struct zone_dstab dstab; 29810209230bSgjelinek 2982bbec428eSgjelinek if ((err = fill_in_dstab(cmd, &dstab, B_FALSE)) != Z_OK) { 2983bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DATASET, err, B_TRUE); 29840209230bSgjelinek return; 29850209230bSgjelinek } 29860209230bSgjelinek if ((err = zonecfg_delete_ds(handle, &dstab)) != Z_OK) 2987bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DATASET, err, B_TRUE); 29880209230bSgjelinek else 2989bbec428eSgjelinek need_to_commit = B_TRUE; 29900209230bSgjelinek return; 29910209230bSgjelinek } 29920209230bSgjelinek 29930209230bSgjelinek /* 29940209230bSgjelinek * unqualified dataset removal. remove all datasets but prompt if more 29950209230bSgjelinek * than one. 29960209230bSgjelinek */ 29970209230bSgjelinek if (!prompt_remove_resource(cmd, "dataset")) 29980209230bSgjelinek return; 29990209230bSgjelinek 30000209230bSgjelinek if ((err = zonecfg_del_all_resources(handle, "dataset")) != Z_OK) 3001bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DATASET, err, B_TRUE); 30020209230bSgjelinek else 3003bbec428eSgjelinek need_to_commit = B_TRUE; 30040209230bSgjelinek } 30050209230bSgjelinek 30060209230bSgjelinek static void 30070209230bSgjelinek remove_rctl(cmd_t *cmd) 30080209230bSgjelinek { 30090209230bSgjelinek int err; 30100209230bSgjelinek 30110209230bSgjelinek /* traditional, qualified rctl removal */ 30120209230bSgjelinek if (cmd->cmd_prop_nv_pairs > 0) { 30130209230bSgjelinek struct zone_rctltab rctltab; 30140209230bSgjelinek 3015bbec428eSgjelinek if ((err = fill_in_rctltab(cmd, &rctltab, B_FALSE)) != Z_OK) { 3016bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_RCTL, err, B_TRUE); 30177c478bd9Sstevel@tonic-gate return; 30187c478bd9Sstevel@tonic-gate } 30197c478bd9Sstevel@tonic-gate if ((err = zonecfg_delete_rctl(handle, &rctltab)) != Z_OK) 3020bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_RCTL, err, B_TRUE); 30217c478bd9Sstevel@tonic-gate else 3022bbec428eSgjelinek need_to_commit = B_TRUE; 30237c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctltab.zone_rctl_valptr); 30247c478bd9Sstevel@tonic-gate return; 30257c478bd9Sstevel@tonic-gate } 30260209230bSgjelinek 30270209230bSgjelinek /* 30280209230bSgjelinek * unqualified rctl removal. remove all rctls but prompt if more 30290209230bSgjelinek * than one. 30300209230bSgjelinek */ 30310209230bSgjelinek if (!prompt_remove_resource(cmd, "rctl")) 30320209230bSgjelinek return; 30330209230bSgjelinek 30340209230bSgjelinek if ((err = zonecfg_del_all_resources(handle, "rctl")) != Z_OK) 3035bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_RCTL, err, B_TRUE); 30367c478bd9Sstevel@tonic-gate else 3037bbec428eSgjelinek need_to_commit = B_TRUE; 30380209230bSgjelinek } 30390209230bSgjelinek 30400209230bSgjelinek static void 30410209230bSgjelinek remove_pset() 30420209230bSgjelinek { 30430209230bSgjelinek int err; 30440209230bSgjelinek struct zone_psettab psettab; 30450209230bSgjelinek 30460209230bSgjelinek if ((err = zonecfg_lookup_pset(handle, &psettab)) != Z_OK) { 3047bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DCPU, err, B_TRUE); 30480209230bSgjelinek return; 30490209230bSgjelinek } 30500209230bSgjelinek if ((err = zonecfg_delete_pset(handle)) != Z_OK) 3051bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_DCPU, err, B_TRUE); 30520209230bSgjelinek else 3053bbec428eSgjelinek need_to_commit = B_TRUE; 30540209230bSgjelinek } 30550209230bSgjelinek 30560209230bSgjelinek static void 3057c97ad5cdSakolb remove_pcap() 3058c97ad5cdSakolb { 3059c97ad5cdSakolb int err; 3060c97ad5cdSakolb uint64_t tmp; 3061c97ad5cdSakolb 3062c97ad5cdSakolb if (zonecfg_get_aliased_rctl(handle, ALIAS_CPUCAP, &tmp) != Z_OK) { 3063c97ad5cdSakolb zerr("%s %s: %s", cmd_to_str(CMD_REMOVE), rt_to_str(RT_PCAP), 3064c97ad5cdSakolb zonecfg_strerror(Z_NO_RESOURCE_TYPE)); 3065bbec428eSgjelinek saw_error = B_TRUE; 3066c97ad5cdSakolb return; 3067c97ad5cdSakolb } 3068c97ad5cdSakolb 3069c97ad5cdSakolb if ((err = zonecfg_rm_aliased_rctl(handle, ALIAS_CPUCAP)) != Z_OK) 3070bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_PCAP, err, B_TRUE); 3071c97ad5cdSakolb else 3072bbec428eSgjelinek need_to_commit = B_TRUE; 3073c97ad5cdSakolb } 3074c97ad5cdSakolb 3075c97ad5cdSakolb static void 30760209230bSgjelinek remove_mcap() 30770209230bSgjelinek { 30780209230bSgjelinek int err, res1, res2, res3; 30790209230bSgjelinek uint64_t tmp; 30800209230bSgjelinek struct zone_mcaptab mcaptab; 30810209230bSgjelinek boolean_t revert = B_FALSE; 30820209230bSgjelinek 30830209230bSgjelinek res1 = zonecfg_lookup_mcap(handle, &mcaptab); 30840209230bSgjelinek res2 = zonecfg_get_aliased_rctl(handle, ALIAS_MAXSWAP, &tmp); 30850209230bSgjelinek res3 = zonecfg_get_aliased_rctl(handle, ALIAS_MAXLOCKEDMEM, &tmp); 30860209230bSgjelinek 30870209230bSgjelinek /* if none of these exist, there is no resource to remove */ 30880209230bSgjelinek if (res1 != Z_OK && res2 != Z_OK && res3 != Z_OK) { 30890209230bSgjelinek zerr("%s %s: %s", cmd_to_str(CMD_REMOVE), rt_to_str(RT_MCAP), 30900209230bSgjelinek zonecfg_strerror(Z_NO_RESOURCE_TYPE)); 3091bbec428eSgjelinek saw_error = B_TRUE; 30920209230bSgjelinek return; 30930209230bSgjelinek } 30940209230bSgjelinek if (res1 == Z_OK) { 30950209230bSgjelinek if ((err = zonecfg_delete_mcap(handle)) != Z_OK) { 3096bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_MCAP, err, B_TRUE); 30970209230bSgjelinek revert = B_TRUE; 30980209230bSgjelinek } else { 3099bbec428eSgjelinek need_to_commit = B_TRUE; 31000209230bSgjelinek } 31010209230bSgjelinek } 31020209230bSgjelinek if (res2 == Z_OK) { 31030209230bSgjelinek if ((err = zonecfg_rm_aliased_rctl(handle, ALIAS_MAXSWAP)) 31040209230bSgjelinek != Z_OK) { 3105bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_MCAP, err, B_TRUE); 31060209230bSgjelinek revert = B_TRUE; 31070209230bSgjelinek } else { 3108bbec428eSgjelinek need_to_commit = B_TRUE; 31090209230bSgjelinek } 31100209230bSgjelinek } 31110209230bSgjelinek if (res3 == Z_OK) { 31120209230bSgjelinek if ((err = zonecfg_rm_aliased_rctl(handle, ALIAS_MAXLOCKEDMEM)) 31130209230bSgjelinek != Z_OK) { 3114bbec428eSgjelinek z_cmd_rt_perror(CMD_REMOVE, RT_MCAP, err, B_TRUE); 31150209230bSgjelinek revert = B_TRUE; 31160209230bSgjelinek } else { 3117bbec428eSgjelinek need_to_commit = B_TRUE; 31180209230bSgjelinek } 31190209230bSgjelinek } 31200209230bSgjelinek 31210209230bSgjelinek if (revert) 3122bbec428eSgjelinek need_to_commit = B_FALSE; 31230209230bSgjelinek } 31240209230bSgjelinek 31250209230bSgjelinek static void 31260209230bSgjelinek remove_resource(cmd_t *cmd) 31270209230bSgjelinek { 31280209230bSgjelinek int type; 31290209230bSgjelinek int arg; 3130bbec428eSgjelinek boolean_t arg_err = B_FALSE; 31310209230bSgjelinek 31320209230bSgjelinek if ((type = cmd->cmd_res_type) == RT_UNKNOWN) { 3133bbec428eSgjelinek long_usage(CMD_REMOVE, B_TRUE); 31340209230bSgjelinek return; 31350209230bSgjelinek } 31360209230bSgjelinek 31370209230bSgjelinek optind = 0; 31380209230bSgjelinek while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?F")) != EOF) { 31390209230bSgjelinek switch (arg) { 31400209230bSgjelinek case '?': 31410209230bSgjelinek longer_usage(CMD_REMOVE); 3142bbec428eSgjelinek arg_err = B_TRUE; 31437ec75eb8Sgjelinek break; 31440209230bSgjelinek case 'F': 31450209230bSgjelinek break; 31460209230bSgjelinek default: 31470209230bSgjelinek short_usage(CMD_REMOVE); 3148bbec428eSgjelinek arg_err = B_TRUE; 31497ec75eb8Sgjelinek break; 31507ec75eb8Sgjelinek } 31517ec75eb8Sgjelinek } 31527ec75eb8Sgjelinek if (arg_err) 31530209230bSgjelinek return; 31540209230bSgjelinek 3155bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 31560209230bSgjelinek return; 31570209230bSgjelinek 31580209230bSgjelinek switch (type) { 31590209230bSgjelinek case RT_FS: 31600209230bSgjelinek remove_fs(cmd); 31610209230bSgjelinek return; 31620209230bSgjelinek case RT_IPD: 31630209230bSgjelinek remove_ipd(cmd); 31640209230bSgjelinek return; 31650209230bSgjelinek case RT_NET: 31660209230bSgjelinek remove_net(cmd); 31670209230bSgjelinek return; 31680209230bSgjelinek case RT_DEVICE: 31690209230bSgjelinek remove_device(cmd); 31700209230bSgjelinek return; 31710209230bSgjelinek case RT_RCTL: 31720209230bSgjelinek remove_rctl(cmd); 31730209230bSgjelinek return; 31740209230bSgjelinek case RT_ATTR: 31750209230bSgjelinek remove_attr(cmd); 31767c478bd9Sstevel@tonic-gate return; 3177fa9e4066Sahrens case RT_DATASET: 31780209230bSgjelinek remove_dataset(cmd); 3179fa9e4066Sahrens return; 31800209230bSgjelinek case RT_DCPU: 31810209230bSgjelinek remove_pset(); 31820209230bSgjelinek return; 3183c97ad5cdSakolb case RT_PCAP: 3184c97ad5cdSakolb remove_pcap(); 3185c97ad5cdSakolb return; 31860209230bSgjelinek case RT_MCAP: 31870209230bSgjelinek remove_mcap(); 3188fa9e4066Sahrens return; 31897c478bd9Sstevel@tonic-gate default: 3190bbec428eSgjelinek zone_perror(rt_to_str(type), Z_NO_RESOURCE_TYPE, B_TRUE); 3191bbec428eSgjelinek long_usage(CMD_REMOVE, B_TRUE); 3192bbec428eSgjelinek usage(B_FALSE, HELP_RESOURCES); 31937c478bd9Sstevel@tonic-gate return; 31947c478bd9Sstevel@tonic-gate } 31957c478bd9Sstevel@tonic-gate } 31967c478bd9Sstevel@tonic-gate 31977c478bd9Sstevel@tonic-gate static void 31987c478bd9Sstevel@tonic-gate remove_property(cmd_t *cmd) 31997c478bd9Sstevel@tonic-gate { 32007c478bd9Sstevel@tonic-gate char *prop_id; 32017c478bd9Sstevel@tonic-gate int err, res_type, prop_type; 32027c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 32037c478bd9Sstevel@tonic-gate struct zone_rctlvaltab *rctlvaltab; 32047c478bd9Sstevel@tonic-gate complex_property_ptr_t cx; 32057c478bd9Sstevel@tonic-gate 32067c478bd9Sstevel@tonic-gate res_type = resource_scope; 32077c478bd9Sstevel@tonic-gate prop_type = cmd->cmd_prop_name[0]; 32087c478bd9Sstevel@tonic-gate if (res_type == RT_UNKNOWN || prop_type == PT_UNKNOWN) { 3209bbec428eSgjelinek long_usage(CMD_REMOVE, B_TRUE); 32107c478bd9Sstevel@tonic-gate return; 32117c478bd9Sstevel@tonic-gate } 32127c478bd9Sstevel@tonic-gate 32137c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs != 1) { 3214bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 32157c478bd9Sstevel@tonic-gate return; 32167c478bd9Sstevel@tonic-gate } 32177c478bd9Sstevel@tonic-gate 3218bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 32197c478bd9Sstevel@tonic-gate return; 32207c478bd9Sstevel@tonic-gate 32217c478bd9Sstevel@tonic-gate switch (res_type) { 32227c478bd9Sstevel@tonic-gate case RT_FS: 32237c478bd9Sstevel@tonic-gate if (prop_type != PT_OPTIONS) { 32247c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 3225bbec428eSgjelinek B_TRUE); 3226bbec428eSgjelinek long_usage(CMD_REMOVE, B_TRUE); 3227bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 32287c478bd9Sstevel@tonic-gate return; 32297c478bd9Sstevel@tonic-gate } 32307c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[0]; 32317c478bd9Sstevel@tonic-gate if (pp->pv_type == PROP_VAL_COMPLEX) { 32327c478bd9Sstevel@tonic-gate zerr(gettext("A %s or %s value was expected here."), 32337c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_SIMPLE), 32347c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_LIST)); 3235bbec428eSgjelinek saw_error = B_TRUE; 32367c478bd9Sstevel@tonic-gate return; 32377c478bd9Sstevel@tonic-gate } 32387c478bd9Sstevel@tonic-gate if (pp->pv_type == PROP_VAL_SIMPLE) { 32397c478bd9Sstevel@tonic-gate if (pp->pv_simple == NULL) { 3240bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 32417c478bd9Sstevel@tonic-gate return; 32427c478bd9Sstevel@tonic-gate } 32437c478bd9Sstevel@tonic-gate prop_id = pp->pv_simple; 32447c478bd9Sstevel@tonic-gate err = zonecfg_remove_fs_option(&in_progress_fstab, 32457c478bd9Sstevel@tonic-gate prop_id); 32467c478bd9Sstevel@tonic-gate if (err != Z_OK) 3247bbec428eSgjelinek zone_perror(pt_to_str(prop_type), err, B_TRUE); 32487c478bd9Sstevel@tonic-gate } else { 32497c478bd9Sstevel@tonic-gate list_property_ptr_t list; 32507c478bd9Sstevel@tonic-gate 32517c478bd9Sstevel@tonic-gate for (list = pp->pv_list; list != NULL; 32527c478bd9Sstevel@tonic-gate list = list->lp_next) { 32537c478bd9Sstevel@tonic-gate prop_id = list->lp_simple; 32547c478bd9Sstevel@tonic-gate if (prop_id == NULL) 32557c478bd9Sstevel@tonic-gate break; 32567c478bd9Sstevel@tonic-gate err = zonecfg_remove_fs_option( 32577c478bd9Sstevel@tonic-gate &in_progress_fstab, prop_id); 32587c478bd9Sstevel@tonic-gate if (err != Z_OK) 32597c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), err, 3260bbec428eSgjelinek B_TRUE); 32617c478bd9Sstevel@tonic-gate } 32627c478bd9Sstevel@tonic-gate } 32637c478bd9Sstevel@tonic-gate return; 32647c478bd9Sstevel@tonic-gate case RT_RCTL: 32657c478bd9Sstevel@tonic-gate if (prop_type != PT_VALUE) { 32667c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 3267bbec428eSgjelinek B_TRUE); 3268bbec428eSgjelinek long_usage(CMD_REMOVE, B_TRUE); 3269bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 32707c478bd9Sstevel@tonic-gate return; 32717c478bd9Sstevel@tonic-gate } 32727c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[0]; 32737c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_COMPLEX) { 32747c478bd9Sstevel@tonic-gate zerr(gettext("A %s value was expected here."), 32757c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_COMPLEX)); 3276bbec428eSgjelinek saw_error = B_TRUE; 32777c478bd9Sstevel@tonic-gate return; 32787c478bd9Sstevel@tonic-gate } 32797c478bd9Sstevel@tonic-gate if ((rctlvaltab = alloc_rctlvaltab()) == NULL) { 3280bbec428eSgjelinek zone_perror(zone, Z_NOMEM, B_TRUE); 32817c478bd9Sstevel@tonic-gate exit(Z_ERR); 32827c478bd9Sstevel@tonic-gate } 32837c478bd9Sstevel@tonic-gate for (cx = pp->pv_complex; cx != NULL; cx = cx->cp_next) { 32847c478bd9Sstevel@tonic-gate switch (cx->cp_type) { 32857c478bd9Sstevel@tonic-gate case PT_PRIV: 32867c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_priv, 32877c478bd9Sstevel@tonic-gate cx->cp_value, 32887c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_priv)); 32897c478bd9Sstevel@tonic-gate break; 32907c478bd9Sstevel@tonic-gate case PT_LIMIT: 32917c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_limit, 32927c478bd9Sstevel@tonic-gate cx->cp_value, 32937c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_limit)); 32947c478bd9Sstevel@tonic-gate break; 32957c478bd9Sstevel@tonic-gate case PT_ACTION: 32967c478bd9Sstevel@tonic-gate (void) strlcpy(rctlvaltab->zone_rctlval_action, 32977c478bd9Sstevel@tonic-gate cx->cp_value, 32987c478bd9Sstevel@tonic-gate sizeof (rctlvaltab->zone_rctlval_action)); 32997c478bd9Sstevel@tonic-gate break; 33007c478bd9Sstevel@tonic-gate default: 33017c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), 3302bbec428eSgjelinek Z_NO_PROPERTY_TYPE, B_TRUE); 3303bbec428eSgjelinek long_usage(CMD_ADD, B_TRUE); 3304bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 33057c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctlvaltab); 33067c478bd9Sstevel@tonic-gate return; 33077c478bd9Sstevel@tonic-gate } 33087c478bd9Sstevel@tonic-gate } 33097c478bd9Sstevel@tonic-gate rctlvaltab->zone_rctlval_next = NULL; 33107c478bd9Sstevel@tonic-gate err = zonecfg_remove_rctl_value(&in_progress_rctltab, 33117c478bd9Sstevel@tonic-gate rctlvaltab); 33127c478bd9Sstevel@tonic-gate if (err != Z_OK) 3313bbec428eSgjelinek zone_perror(pt_to_str(prop_type), err, B_TRUE); 33147c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctlvaltab); 33157c478bd9Sstevel@tonic-gate return; 3316de860bd9Sgfaden case RT_NET: 3317de860bd9Sgfaden if (prop_type != PT_DEFROUTER) { 3318de860bd9Sgfaden zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 3319bbec428eSgjelinek B_TRUE); 3320bbec428eSgjelinek long_usage(CMD_REMOVE, B_TRUE); 3321bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 3322de860bd9Sgfaden return; 3323de860bd9Sgfaden } else { 3324de860bd9Sgfaden bzero(&in_progress_nwiftab.zone_nwif_defrouter, 3325de860bd9Sgfaden sizeof (in_progress_nwiftab.zone_nwif_defrouter)); 3326de860bd9Sgfaden return; 3327de860bd9Sgfaden } 33287c478bd9Sstevel@tonic-gate default: 3329bbec428eSgjelinek zone_perror(rt_to_str(res_type), Z_NO_RESOURCE_TYPE, B_TRUE); 3330bbec428eSgjelinek long_usage(CMD_REMOVE, B_TRUE); 3331bbec428eSgjelinek usage(B_FALSE, HELP_RESOURCES); 33327c478bd9Sstevel@tonic-gate return; 33337c478bd9Sstevel@tonic-gate } 33347c478bd9Sstevel@tonic-gate } 33357c478bd9Sstevel@tonic-gate 33367c478bd9Sstevel@tonic-gate void 33377c478bd9Sstevel@tonic-gate remove_func(cmd_t *cmd) 33387c478bd9Sstevel@tonic-gate { 33397c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_REMOVE)) 33407c478bd9Sstevel@tonic-gate return; 33417c478bd9Sstevel@tonic-gate 33427c478bd9Sstevel@tonic-gate assert(cmd != NULL); 33437c478bd9Sstevel@tonic-gate 33440209230bSgjelinek if (global_scope) { 33450209230bSgjelinek if (gz_invalid_resource(cmd->cmd_res_type)) { 33460209230bSgjelinek zerr(gettext("%s is not a valid resource for the " 33470209230bSgjelinek "global zone."), rt_to_str(cmd->cmd_res_type)); 3348bbec428eSgjelinek saw_error = B_TRUE; 33490209230bSgjelinek return; 33500209230bSgjelinek } 33517c478bd9Sstevel@tonic-gate remove_resource(cmd); 33520209230bSgjelinek } else { 33537c478bd9Sstevel@tonic-gate remove_property(cmd); 33547c478bd9Sstevel@tonic-gate } 33550209230bSgjelinek } 33560209230bSgjelinek 33570209230bSgjelinek static void 33580209230bSgjelinek clear_property(cmd_t *cmd) 33590209230bSgjelinek { 33600209230bSgjelinek int res_type, prop_type; 33610209230bSgjelinek 33620209230bSgjelinek res_type = resource_scope; 33630209230bSgjelinek prop_type = cmd->cmd_res_type; 33640209230bSgjelinek if (res_type == RT_UNKNOWN || prop_type == PT_UNKNOWN) { 3365bbec428eSgjelinek long_usage(CMD_CLEAR, B_TRUE); 33660209230bSgjelinek return; 33670209230bSgjelinek } 33680209230bSgjelinek 3369bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 33700209230bSgjelinek return; 33710209230bSgjelinek 33720209230bSgjelinek switch (res_type) { 33730209230bSgjelinek case RT_FS: 33740209230bSgjelinek if (prop_type == PT_RAW) { 33750209230bSgjelinek in_progress_fstab.zone_fs_raw[0] = '\0'; 3376bbec428eSgjelinek need_to_commit = B_TRUE; 33770209230bSgjelinek return; 33780209230bSgjelinek } 33790209230bSgjelinek break; 33800209230bSgjelinek case RT_DCPU: 33810209230bSgjelinek if (prop_type == PT_IMPORTANCE) { 33820209230bSgjelinek in_progress_psettab.zone_importance[0] = '\0'; 3383bbec428eSgjelinek need_to_commit = B_TRUE; 33840209230bSgjelinek return; 33850209230bSgjelinek } 33860209230bSgjelinek break; 33870209230bSgjelinek case RT_MCAP: 33880209230bSgjelinek switch (prop_type) { 33890209230bSgjelinek case PT_PHYSICAL: 33900209230bSgjelinek in_progress_mcaptab.zone_physmem_cap[0] = '\0'; 3391bbec428eSgjelinek need_to_commit = B_TRUE; 33920209230bSgjelinek return; 33930209230bSgjelinek case PT_SWAP: 33940209230bSgjelinek remove_aliased_rctl(PT_SWAP, ALIAS_MAXSWAP); 33950209230bSgjelinek return; 33960209230bSgjelinek case PT_LOCKED: 33970209230bSgjelinek remove_aliased_rctl(PT_LOCKED, ALIAS_MAXLOCKEDMEM); 33980209230bSgjelinek return; 33990209230bSgjelinek } 34000209230bSgjelinek break; 34010209230bSgjelinek default: 34020209230bSgjelinek break; 34030209230bSgjelinek } 34040209230bSgjelinek 3405bbec428eSgjelinek zone_perror(pt_to_str(prop_type), Z_CLEAR_DISALLOW, B_TRUE); 34060209230bSgjelinek } 34070209230bSgjelinek 34080209230bSgjelinek static void 34090209230bSgjelinek clear_global(cmd_t *cmd) 34100209230bSgjelinek { 34110209230bSgjelinek int err, type; 34120209230bSgjelinek 34130209230bSgjelinek if ((type = cmd->cmd_res_type) == RT_UNKNOWN) { 3414bbec428eSgjelinek long_usage(CMD_CLEAR, B_TRUE); 34150209230bSgjelinek return; 34160209230bSgjelinek } 34170209230bSgjelinek 3418bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 34190209230bSgjelinek return; 34200209230bSgjelinek 34210209230bSgjelinek switch (type) { 34220209230bSgjelinek case PT_ZONENAME: 34230209230bSgjelinek /* FALLTHRU */ 34240209230bSgjelinek case PT_ZONEPATH: 34250209230bSgjelinek /* FALLTHRU */ 34260209230bSgjelinek case PT_BRAND: 3427bbec428eSgjelinek zone_perror(pt_to_str(type), Z_CLEAR_DISALLOW, B_TRUE); 34280209230bSgjelinek return; 34290209230bSgjelinek case PT_AUTOBOOT: 34300209230bSgjelinek /* false is default; we'll treat as equivalent to clearing */ 34310209230bSgjelinek if ((err = zonecfg_set_autoboot(handle, B_FALSE)) != Z_OK) 3432bbec428eSgjelinek z_cmd_rt_perror(CMD_CLEAR, RT_AUTOBOOT, err, B_TRUE); 34330209230bSgjelinek else 3434bbec428eSgjelinek need_to_commit = B_TRUE; 34350209230bSgjelinek return; 34360209230bSgjelinek case PT_POOL: 34370209230bSgjelinek if ((err = zonecfg_set_pool(handle, NULL)) != Z_OK) 3438bbec428eSgjelinek z_cmd_rt_perror(CMD_CLEAR, RT_POOL, err, B_TRUE); 34390209230bSgjelinek else 3440bbec428eSgjelinek need_to_commit = B_TRUE; 34410209230bSgjelinek return; 34420209230bSgjelinek case PT_LIMITPRIV: 34430209230bSgjelinek if ((err = zonecfg_set_limitpriv(handle, NULL)) != Z_OK) 3444bbec428eSgjelinek z_cmd_rt_perror(CMD_CLEAR, RT_LIMITPRIV, err, B_TRUE); 34450209230bSgjelinek else 3446bbec428eSgjelinek need_to_commit = B_TRUE; 34470209230bSgjelinek return; 34480209230bSgjelinek case PT_BOOTARGS: 34490209230bSgjelinek if ((err = zonecfg_set_bootargs(handle, NULL)) != Z_OK) 3450bbec428eSgjelinek z_cmd_rt_perror(CMD_CLEAR, RT_BOOTARGS, err, B_TRUE); 34510209230bSgjelinek else 3452bbec428eSgjelinek need_to_commit = B_TRUE; 34530209230bSgjelinek return; 34540209230bSgjelinek case PT_SCHED: 34550209230bSgjelinek if ((err = zonecfg_set_sched(handle, NULL)) != Z_OK) 3456bbec428eSgjelinek z_cmd_rt_perror(CMD_CLEAR, RT_SCHED, err, B_TRUE); 34570209230bSgjelinek else 3458bbec428eSgjelinek need_to_commit = B_TRUE; 34590209230bSgjelinek return; 3460f4b3ec61Sdh155122 case PT_IPTYPE: 3461f4b3ec61Sdh155122 /* shared is default; we'll treat as equivalent to clearing */ 3462f4b3ec61Sdh155122 if ((err = zonecfg_set_iptype(handle, ZS_SHARED)) != Z_OK) 3463bbec428eSgjelinek z_cmd_rt_perror(CMD_CLEAR, RT_IPTYPE, err, B_TRUE); 3464f4b3ec61Sdh155122 else 3465bbec428eSgjelinek need_to_commit = B_TRUE; 3466f4b3ec61Sdh155122 return; 34670209230bSgjelinek case PT_MAXLWPS: 34680209230bSgjelinek remove_aliased_rctl(PT_MAXLWPS, ALIAS_MAXLWPS); 34690209230bSgjelinek return; 34700209230bSgjelinek case PT_MAXSHMMEM: 34710209230bSgjelinek remove_aliased_rctl(PT_MAXSHMMEM, ALIAS_MAXSHMMEM); 34720209230bSgjelinek return; 34730209230bSgjelinek case PT_MAXSHMIDS: 34740209230bSgjelinek remove_aliased_rctl(PT_MAXSHMIDS, ALIAS_MAXSHMIDS); 34750209230bSgjelinek return; 34760209230bSgjelinek case PT_MAXMSGIDS: 34770209230bSgjelinek remove_aliased_rctl(PT_MAXMSGIDS, ALIAS_MAXMSGIDS); 34780209230bSgjelinek return; 34790209230bSgjelinek case PT_MAXSEMIDS: 34800209230bSgjelinek remove_aliased_rctl(PT_MAXSEMIDS, ALIAS_MAXSEMIDS); 34810209230bSgjelinek return; 34820209230bSgjelinek case PT_SHARES: 34830209230bSgjelinek remove_aliased_rctl(PT_SHARES, ALIAS_SHARES); 34840209230bSgjelinek return; 34850209230bSgjelinek default: 3486bbec428eSgjelinek zone_perror(pt_to_str(type), Z_NO_PROPERTY_TYPE, B_TRUE); 3487bbec428eSgjelinek long_usage(CMD_CLEAR, B_TRUE); 3488bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 34890209230bSgjelinek return; 34900209230bSgjelinek } 34910209230bSgjelinek } 34920209230bSgjelinek 34930209230bSgjelinek void 34940209230bSgjelinek clear_func(cmd_t *cmd) 34950209230bSgjelinek { 34960209230bSgjelinek if (zone_is_read_only(CMD_CLEAR)) 34970209230bSgjelinek return; 34980209230bSgjelinek 34990209230bSgjelinek assert(cmd != NULL); 35000209230bSgjelinek 35010209230bSgjelinek if (global_scope) { 35020209230bSgjelinek if (gz_invalid_property(cmd->cmd_res_type)) { 35030209230bSgjelinek zerr(gettext("%s is not a valid property for the " 35040209230bSgjelinek "global zone."), pt_to_str(cmd->cmd_res_type)); 3505bbec428eSgjelinek saw_error = B_TRUE; 35060209230bSgjelinek return; 35070209230bSgjelinek } 35080209230bSgjelinek 35090209230bSgjelinek clear_global(cmd); 35100209230bSgjelinek } else { 35110209230bSgjelinek clear_property(cmd); 35120209230bSgjelinek } 35130209230bSgjelinek } 35147c478bd9Sstevel@tonic-gate 35157c478bd9Sstevel@tonic-gate void 35167c478bd9Sstevel@tonic-gate select_func(cmd_t *cmd) 35177c478bd9Sstevel@tonic-gate { 35180209230bSgjelinek int type, err, res; 35190209230bSgjelinek uint64_t limit; 3520c97ad5cdSakolb uint64_t tmp; 35217c478bd9Sstevel@tonic-gate 35227c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_SELECT)) 35237c478bd9Sstevel@tonic-gate return; 35247c478bd9Sstevel@tonic-gate 35257c478bd9Sstevel@tonic-gate assert(cmd != NULL); 35267c478bd9Sstevel@tonic-gate 35277c478bd9Sstevel@tonic-gate if (global_scope) { 3528bbec428eSgjelinek global_scope = B_FALSE; 35297c478bd9Sstevel@tonic-gate resource_scope = cmd->cmd_res_type; 35307c478bd9Sstevel@tonic-gate end_op = CMD_SELECT; 35317c478bd9Sstevel@tonic-gate } else { 35327c478bd9Sstevel@tonic-gate scope_usage(CMD_SELECT); 35337c478bd9Sstevel@tonic-gate return; 35347c478bd9Sstevel@tonic-gate } 35357c478bd9Sstevel@tonic-gate 35367c478bd9Sstevel@tonic-gate if ((type = cmd->cmd_res_type) == RT_UNKNOWN) { 3537bbec428eSgjelinek long_usage(CMD_SELECT, B_TRUE); 35387c478bd9Sstevel@tonic-gate return; 35397c478bd9Sstevel@tonic-gate } 35407c478bd9Sstevel@tonic-gate 3541bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 35427c478bd9Sstevel@tonic-gate return; 35437c478bd9Sstevel@tonic-gate 35447c478bd9Sstevel@tonic-gate switch (type) { 35457c478bd9Sstevel@tonic-gate case RT_FS: 3546bbec428eSgjelinek if ((err = fill_in_fstab(cmd, &old_fstab, B_FALSE)) != Z_OK) { 3547bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_FS, err, B_TRUE); 3548bbec428eSgjelinek global_scope = B_TRUE; 35497c478bd9Sstevel@tonic-gate } 35507c478bd9Sstevel@tonic-gate bcopy(&old_fstab, &in_progress_fstab, 35517c478bd9Sstevel@tonic-gate sizeof (struct zone_fstab)); 35527c478bd9Sstevel@tonic-gate return; 35537c478bd9Sstevel@tonic-gate case RT_IPD: 3554087719fdSdp if (state_atleast(ZONE_STATE_INCOMPLETE)) { 35557c478bd9Sstevel@tonic-gate zerr(gettext("Zone %s not in %s state; %s %s not " 35567c478bd9Sstevel@tonic-gate "allowed."), zone, 35577c478bd9Sstevel@tonic-gate zone_state_str(ZONE_STATE_CONFIGURED), 35587c478bd9Sstevel@tonic-gate cmd_to_str(CMD_SELECT), rt_to_str(RT_IPD)); 3559bbec428eSgjelinek global_scope = B_TRUE; 35607c478bd9Sstevel@tonic-gate end_op = -1; 35617c478bd9Sstevel@tonic-gate return; 35627c478bd9Sstevel@tonic-gate } 3563bbec428eSgjelinek if ((err = fill_in_ipdtab(cmd, &old_ipdtab, B_FALSE)) != Z_OK) { 3564bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_IPD, err, B_TRUE); 3565bbec428eSgjelinek global_scope = B_TRUE; 35667c478bd9Sstevel@tonic-gate } 35677c478bd9Sstevel@tonic-gate bcopy(&old_ipdtab, &in_progress_ipdtab, 35687c478bd9Sstevel@tonic-gate sizeof (struct zone_fstab)); 35697c478bd9Sstevel@tonic-gate return; 35707c478bd9Sstevel@tonic-gate case RT_NET: 3571bbec428eSgjelinek if ((err = fill_in_nwiftab(cmd, &old_nwiftab, B_FALSE)) 3572bbec428eSgjelinek != Z_OK) { 3573bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_NET, err, B_TRUE); 3574bbec428eSgjelinek global_scope = B_TRUE; 35757c478bd9Sstevel@tonic-gate } 35767c478bd9Sstevel@tonic-gate bcopy(&old_nwiftab, &in_progress_nwiftab, 35777c478bd9Sstevel@tonic-gate sizeof (struct zone_nwiftab)); 35787c478bd9Sstevel@tonic-gate return; 35797c478bd9Sstevel@tonic-gate case RT_DEVICE: 3580bbec428eSgjelinek if ((err = fill_in_devtab(cmd, &old_devtab, B_FALSE)) != Z_OK) { 3581bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_DEVICE, err, B_TRUE); 3582bbec428eSgjelinek global_scope = B_TRUE; 35837c478bd9Sstevel@tonic-gate } 35847c478bd9Sstevel@tonic-gate bcopy(&old_devtab, &in_progress_devtab, 35857c478bd9Sstevel@tonic-gate sizeof (struct zone_devtab)); 35867c478bd9Sstevel@tonic-gate return; 35877c478bd9Sstevel@tonic-gate case RT_RCTL: 3588bbec428eSgjelinek if ((err = fill_in_rctltab(cmd, &old_rctltab, B_FALSE)) 3589bbec428eSgjelinek != Z_OK) { 3590bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_RCTL, err, B_TRUE); 3591bbec428eSgjelinek global_scope = B_TRUE; 35927c478bd9Sstevel@tonic-gate } 35937c478bd9Sstevel@tonic-gate bcopy(&old_rctltab, &in_progress_rctltab, 35947c478bd9Sstevel@tonic-gate sizeof (struct zone_rctltab)); 35957c478bd9Sstevel@tonic-gate return; 35967c478bd9Sstevel@tonic-gate case RT_ATTR: 3597bbec428eSgjelinek if ((err = fill_in_attrtab(cmd, &old_attrtab, B_FALSE)) 3598bbec428eSgjelinek != Z_OK) { 3599bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_ATTR, err, B_TRUE); 3600bbec428eSgjelinek global_scope = B_TRUE; 36017c478bd9Sstevel@tonic-gate } 36027c478bd9Sstevel@tonic-gate bcopy(&old_attrtab, &in_progress_attrtab, 36037c478bd9Sstevel@tonic-gate sizeof (struct zone_attrtab)); 36047c478bd9Sstevel@tonic-gate return; 3605fa9e4066Sahrens case RT_DATASET: 3606bbec428eSgjelinek if ((err = fill_in_dstab(cmd, &old_dstab, B_FALSE)) != Z_OK) { 3607bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_DATASET, err, B_TRUE); 3608bbec428eSgjelinek global_scope = B_TRUE; 3609fa9e4066Sahrens } 3610fa9e4066Sahrens bcopy(&old_dstab, &in_progress_dstab, 3611fa9e4066Sahrens sizeof (struct zone_dstab)); 3612fa9e4066Sahrens return; 36130209230bSgjelinek case RT_DCPU: 36140209230bSgjelinek if ((err = zonecfg_lookup_pset(handle, &old_psettab)) != Z_OK) { 3615bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_DCPU, err, B_TRUE); 3616bbec428eSgjelinek global_scope = B_TRUE; 36170209230bSgjelinek } 36180209230bSgjelinek bcopy(&old_psettab, &in_progress_psettab, 36190209230bSgjelinek sizeof (struct zone_psettab)); 36200209230bSgjelinek return; 3621c97ad5cdSakolb case RT_PCAP: 3622c97ad5cdSakolb if ((err = zonecfg_get_aliased_rctl(handle, ALIAS_CPUCAP, &tmp)) 3623c97ad5cdSakolb != Z_OK) { 3624bbec428eSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_PCAP, err, B_TRUE); 3625bbec428eSgjelinek global_scope = B_TRUE; 3626c97ad5cdSakolb } 3627c97ad5cdSakolb return; 36280209230bSgjelinek case RT_MCAP: 36290209230bSgjelinek /* if none of these exist, there is no resource to select */ 36300209230bSgjelinek if ((res = zonecfg_lookup_mcap(handle, &old_mcaptab)) != Z_OK && 36310209230bSgjelinek zonecfg_get_aliased_rctl(handle, ALIAS_MAXSWAP, &limit) 36320209230bSgjelinek != Z_OK && 36330209230bSgjelinek zonecfg_get_aliased_rctl(handle, ALIAS_MAXLOCKEDMEM, &limit) 36340209230bSgjelinek != Z_OK) { 36350209230bSgjelinek z_cmd_rt_perror(CMD_SELECT, RT_MCAP, Z_NO_RESOURCE_TYPE, 3636bbec428eSgjelinek B_TRUE); 3637bbec428eSgjelinek global_scope = B_TRUE; 36380209230bSgjelinek } 36390209230bSgjelinek if (res == Z_OK) 36400209230bSgjelinek bcopy(&old_mcaptab, &in_progress_mcaptab, 36410209230bSgjelinek sizeof (struct zone_mcaptab)); 36420209230bSgjelinek else 36430209230bSgjelinek bzero(&in_progress_mcaptab, 36440209230bSgjelinek sizeof (in_progress_mcaptab)); 36450209230bSgjelinek return; 36467c478bd9Sstevel@tonic-gate default: 3647bbec428eSgjelinek zone_perror(rt_to_str(type), Z_NO_RESOURCE_TYPE, B_TRUE); 3648bbec428eSgjelinek long_usage(CMD_SELECT, B_TRUE); 3649bbec428eSgjelinek usage(B_FALSE, HELP_RESOURCES); 36507c478bd9Sstevel@tonic-gate return; 36517c478bd9Sstevel@tonic-gate } 36527c478bd9Sstevel@tonic-gate } 36537c478bd9Sstevel@tonic-gate 36547c478bd9Sstevel@tonic-gate /* 36557c478bd9Sstevel@tonic-gate * Network "addresses" can be one of the following forms: 36567c478bd9Sstevel@tonic-gate * <IPv4 address> 36577c478bd9Sstevel@tonic-gate * <IPv4 address>/<prefix length> 36587c478bd9Sstevel@tonic-gate * <IPv6 address>/<prefix length> 36597c478bd9Sstevel@tonic-gate * <host name> 36607c478bd9Sstevel@tonic-gate * <host name>/<prefix length> 36617c478bd9Sstevel@tonic-gate * In other words, the "/" followed by a prefix length is allowed but not 36627c478bd9Sstevel@tonic-gate * required for IPv4 addresses and host names, and required for IPv6 addresses. 36637c478bd9Sstevel@tonic-gate * If a prefix length is given, it must be in the allowable range: 0 to 32 for 36647c478bd9Sstevel@tonic-gate * IPv4 addresses and host names, 0 to 128 for IPv6 addresses. 36657c478bd9Sstevel@tonic-gate * Host names must start with an alpha-numeric character, and all subsequent 36667c478bd9Sstevel@tonic-gate * characters must be either alpha-numeric or "-". 36677c478bd9Sstevel@tonic-gate */ 36687c478bd9Sstevel@tonic-gate 36697c478bd9Sstevel@tonic-gate static int 36707c478bd9Sstevel@tonic-gate validate_net_address_syntax(char *address) 36717c478bd9Sstevel@tonic-gate { 36727c478bd9Sstevel@tonic-gate char *slashp, part1[MAXHOSTNAMELEN]; 36737c478bd9Sstevel@tonic-gate struct in6_addr in6; 36747c478bd9Sstevel@tonic-gate struct in_addr in4; 36757c478bd9Sstevel@tonic-gate int prefixlen, i; 36767c478bd9Sstevel@tonic-gate 36777c478bd9Sstevel@tonic-gate /* 36787c478bd9Sstevel@tonic-gate * Copy the part before any '/' into part1 or copy the whole 36797c478bd9Sstevel@tonic-gate * thing if there is no '/'. 36807c478bd9Sstevel@tonic-gate */ 36817c478bd9Sstevel@tonic-gate if ((slashp = strchr(address, '/')) != NULL) { 36827c478bd9Sstevel@tonic-gate *slashp = '\0'; 36837c478bd9Sstevel@tonic-gate (void) strlcpy(part1, address, sizeof (part1)); 36847c478bd9Sstevel@tonic-gate *slashp = '/'; 36857c478bd9Sstevel@tonic-gate prefixlen = atoi(++slashp); 36867c478bd9Sstevel@tonic-gate } else { 36877c478bd9Sstevel@tonic-gate (void) strlcpy(part1, address, sizeof (part1)); 36887c478bd9Sstevel@tonic-gate } 36897c478bd9Sstevel@tonic-gate 36907c478bd9Sstevel@tonic-gate if (inet_pton(AF_INET6, part1, &in6) == 1) { 36917c478bd9Sstevel@tonic-gate if (slashp == NULL) { 36927c478bd9Sstevel@tonic-gate zerr(gettext("%s: IPv6 addresses " 36937c478bd9Sstevel@tonic-gate "require /prefix-length suffix."), address); 36947c478bd9Sstevel@tonic-gate return (Z_ERR); 36957c478bd9Sstevel@tonic-gate } 36967c478bd9Sstevel@tonic-gate if (prefixlen < 0 || prefixlen > 128) { 36977c478bd9Sstevel@tonic-gate zerr(gettext("%s: IPv6 address " 36987c478bd9Sstevel@tonic-gate "prefix lengths must be 0 - 128."), address); 36997c478bd9Sstevel@tonic-gate return (Z_ERR); 37007c478bd9Sstevel@tonic-gate } 37017c478bd9Sstevel@tonic-gate return (Z_OK); 37027c478bd9Sstevel@tonic-gate } 37037c478bd9Sstevel@tonic-gate 37047c478bd9Sstevel@tonic-gate /* At this point, any /prefix must be for IPv4. */ 37057c478bd9Sstevel@tonic-gate if (slashp != NULL) { 37067c478bd9Sstevel@tonic-gate if (prefixlen < 0 || prefixlen > 32) { 37077c478bd9Sstevel@tonic-gate zerr(gettext("%s: IPv4 address " 37087c478bd9Sstevel@tonic-gate "prefix lengths must be 0 - 32."), address); 37097c478bd9Sstevel@tonic-gate return (Z_ERR); 37107c478bd9Sstevel@tonic-gate } 37117c478bd9Sstevel@tonic-gate } 37127c478bd9Sstevel@tonic-gate if (inet_pton(AF_INET, part1, &in4) == 1) 37137c478bd9Sstevel@tonic-gate return (Z_OK); 37147c478bd9Sstevel@tonic-gate 37157c478bd9Sstevel@tonic-gate /* address may also be a host name */ 37167c478bd9Sstevel@tonic-gate if (!isalnum(part1[0])) { 37177c478bd9Sstevel@tonic-gate zerr(gettext("%s: bogus host name or network address syntax"), 37187c478bd9Sstevel@tonic-gate part1); 3719bbec428eSgjelinek saw_error = B_TRUE; 3720bbec428eSgjelinek usage(B_FALSE, HELP_NETADDR); 37217c478bd9Sstevel@tonic-gate return (Z_ERR); 37227c478bd9Sstevel@tonic-gate } 37237c478bd9Sstevel@tonic-gate for (i = 1; part1[i]; i++) 37247c478bd9Sstevel@tonic-gate if (!isalnum(part1[i]) && part1[i] != '-' && part1[i] != '.') { 37257c478bd9Sstevel@tonic-gate zerr(gettext("%s: bogus host name or " 37267c478bd9Sstevel@tonic-gate "network address syntax"), part1); 3727bbec428eSgjelinek saw_error = B_TRUE; 3728bbec428eSgjelinek usage(B_FALSE, HELP_NETADDR); 37297c478bd9Sstevel@tonic-gate return (Z_ERR); 37307c478bd9Sstevel@tonic-gate } 37317c478bd9Sstevel@tonic-gate return (Z_OK); 37327c478bd9Sstevel@tonic-gate } 37337c478bd9Sstevel@tonic-gate 37347c478bd9Sstevel@tonic-gate static int 3735*c9f134eaSjv227347 validate_net_physical_syntax(const char *ifname) 37367c478bd9Sstevel@tonic-gate { 3737*c9f134eaSjv227347 ifspec_t ifnameprop; 3738*c9f134eaSjv227347 zone_iptype_t iptype; 3739*c9f134eaSjv227347 int err; 3740*c9f134eaSjv227347 3741*c9f134eaSjv227347 if ((err = zonecfg_get_iptype(handle, &iptype)) != Z_OK) { 3742*c9f134eaSjv227347 zerr(gettext("zone configuration has an invalid or nonexistent " 3743*c9f134eaSjv227347 "ip-type property")); 37447c478bd9Sstevel@tonic-gate return (Z_ERR); 37457c478bd9Sstevel@tonic-gate } 3746*c9f134eaSjv227347 switch (iptype) { 3747*c9f134eaSjv227347 case ZS_SHARED: 3748*c9f134eaSjv227347 if (ifparse_ifspec(ifname, &ifnameprop) == B_FALSE) { 3749*c9f134eaSjv227347 zerr(gettext("%s: invalid physical interface name"), 3750*c9f134eaSjv227347 ifname); 3751*c9f134eaSjv227347 return (Z_ERR); 3752*c9f134eaSjv227347 } 3753*c9f134eaSjv227347 if (ifnameprop.ifsp_lunvalid) { 3754*c9f134eaSjv227347 zerr(gettext("%s: LUNs not allowed in physical " 3755*c9f134eaSjv227347 "interface names"), ifname); 3756*c9f134eaSjv227347 return (Z_ERR); 3757*c9f134eaSjv227347 } 3758*c9f134eaSjv227347 break; 3759*c9f134eaSjv227347 case ZS_EXCLUSIVE: 3760*c9f134eaSjv227347 if (dladm_valid_linkname(ifname) == B_FALSE) { 3761*c9f134eaSjv227347 if (strchr(ifname, ':') != NULL) 3762*c9f134eaSjv227347 zerr(gettext("%s: physical interface name " 3763*c9f134eaSjv227347 "required; logical interface name not " 3764*c9f134eaSjv227347 "allowed"), ifname); 3765*c9f134eaSjv227347 else 3766*c9f134eaSjv227347 zerr(gettext("%s: invalid physical interface " 3767*c9f134eaSjv227347 "name"), ifname); 3768*c9f134eaSjv227347 return (Z_ERR); 3769*c9f134eaSjv227347 } 3770*c9f134eaSjv227347 break; 3771*c9f134eaSjv227347 } 3772*c9f134eaSjv227347 return (Z_OK); 3773*c9f134eaSjv227347 } 37747c478bd9Sstevel@tonic-gate 37757c478bd9Sstevel@tonic-gate static boolean_t 37767c478bd9Sstevel@tonic-gate valid_fs_type(const char *type) 37777c478bd9Sstevel@tonic-gate { 37787c478bd9Sstevel@tonic-gate /* 37797c478bd9Sstevel@tonic-gate * Is this a valid path component? 37807c478bd9Sstevel@tonic-gate */ 37817c478bd9Sstevel@tonic-gate if (strlen(type) + 1 > MAXNAMELEN) 37827c478bd9Sstevel@tonic-gate return (B_FALSE); 37837c478bd9Sstevel@tonic-gate /* 37847c478bd9Sstevel@tonic-gate * Make sure a bad value for "type" doesn't make 37857c478bd9Sstevel@tonic-gate * /usr/lib/fs/<type>/mount turn into something else. 37867c478bd9Sstevel@tonic-gate */ 37877c478bd9Sstevel@tonic-gate if (strchr(type, '/') != NULL || type[0] == '\0' || 37887c478bd9Sstevel@tonic-gate strcmp(type, ".") == 0 || strcmp(type, "..") == 0) 37897c478bd9Sstevel@tonic-gate return (B_FALSE); 37907c478bd9Sstevel@tonic-gate /* 37917c478bd9Sstevel@tonic-gate * More detailed verification happens later by zoneadm(1m). 37927c478bd9Sstevel@tonic-gate */ 37937c478bd9Sstevel@tonic-gate return (B_TRUE); 37947c478bd9Sstevel@tonic-gate } 37957c478bd9Sstevel@tonic-gate 3796f4b3ec61Sdh155122 static boolean_t 3797f4b3ec61Sdh155122 allow_exclusive() 3798f4b3ec61Sdh155122 { 3799f4b3ec61Sdh155122 brand_handle_t bh; 3800f4b3ec61Sdh155122 char brand[MAXNAMELEN]; 3801f4b3ec61Sdh155122 boolean_t ret; 3802f4b3ec61Sdh155122 3803f4b3ec61Sdh155122 if (zonecfg_get_brand(handle, brand, sizeof (brand)) != Z_OK) { 3804f4b3ec61Sdh155122 zerr("%s: %s\n", zone, gettext("could not get zone brand")); 3805f4b3ec61Sdh155122 return (B_FALSE); 3806f4b3ec61Sdh155122 } 3807f4b3ec61Sdh155122 if ((bh = brand_open(brand)) == NULL) { 3808f4b3ec61Sdh155122 zerr("%s: %s\n", zone, gettext("unknown brand.")); 3809f4b3ec61Sdh155122 return (B_FALSE); 3810f4b3ec61Sdh155122 } 3811f4b3ec61Sdh155122 ret = brand_allow_exclusive_ip(bh); 3812f4b3ec61Sdh155122 brand_close(bh); 3813f4b3ec61Sdh155122 if (!ret) 3814f4b3ec61Sdh155122 zerr(gettext("%s cannot be '%s' when %s is '%s'."), 3815f4b3ec61Sdh155122 pt_to_str(PT_IPTYPE), "exclusive", 3816f4b3ec61Sdh155122 pt_to_str(PT_BRAND), brand); 3817f4b3ec61Sdh155122 return (ret); 3818f4b3ec61Sdh155122 } 3819f4b3ec61Sdh155122 38200209230bSgjelinek static void 38210209230bSgjelinek set_aliased_rctl(char *alias, int prop_type, char *s) 38220209230bSgjelinek { 38230209230bSgjelinek uint64_t limit; 38240209230bSgjelinek int err; 38250209230bSgjelinek char tmp[128]; 38260209230bSgjelinek 38270209230bSgjelinek if (global_zone && strcmp(alias, ALIAS_SHARES) != 0) 38280209230bSgjelinek zerr(gettext("WARNING: Setting a global zone resource " 38290209230bSgjelinek "control too low could deny\nservice " 38300209230bSgjelinek "to even the root user; " 38310209230bSgjelinek "this could render the system impossible\n" 38320209230bSgjelinek "to administer. Please use caution.")); 38330209230bSgjelinek 38340209230bSgjelinek /* convert memory based properties */ 38350209230bSgjelinek if (prop_type == PT_MAXSHMMEM) { 38360209230bSgjelinek if (!zonecfg_valid_memlimit(s, &limit)) { 38370209230bSgjelinek zerr(gettext("A non-negative number with a required " 38380209230bSgjelinek "scale suffix (K, M, G or T) was expected\nhere.")); 3839bbec428eSgjelinek saw_error = B_TRUE; 38400209230bSgjelinek return; 38410209230bSgjelinek } 38420209230bSgjelinek 38430209230bSgjelinek (void) snprintf(tmp, sizeof (tmp), "%llu", limit); 38440209230bSgjelinek s = tmp; 38450209230bSgjelinek } 38460209230bSgjelinek 38470209230bSgjelinek if (!zonecfg_aliased_rctl_ok(handle, alias)) { 3848bbec428eSgjelinek zone_perror(pt_to_str(prop_type), Z_ALIAS_DISALLOW, B_FALSE); 3849bbec428eSgjelinek saw_error = B_TRUE; 38500209230bSgjelinek } else if (!zonecfg_valid_alias_limit(alias, s, &limit)) { 38510209230bSgjelinek zerr(gettext("%s property is out of range."), 38520209230bSgjelinek pt_to_str(prop_type)); 3853bbec428eSgjelinek saw_error = B_TRUE; 38540209230bSgjelinek } else if ((err = zonecfg_set_aliased_rctl(handle, alias, limit)) 38550209230bSgjelinek != Z_OK) { 3856bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 3857bbec428eSgjelinek saw_error = B_TRUE; 38580209230bSgjelinek } else { 3859bbec428eSgjelinek need_to_commit = B_TRUE; 38600209230bSgjelinek } 38610209230bSgjelinek } 38620209230bSgjelinek 38637c478bd9Sstevel@tonic-gate void 38647c478bd9Sstevel@tonic-gate set_func(cmd_t *cmd) 38657c478bd9Sstevel@tonic-gate { 38667c478bd9Sstevel@tonic-gate char *prop_id; 3867555afedfScarlsonj int arg, err, res_type, prop_type; 38687c478bd9Sstevel@tonic-gate property_value_ptr_t pp; 38697c478bd9Sstevel@tonic-gate boolean_t autoboot; 3870f4b3ec61Sdh155122 zone_iptype_t iptype; 3871bbec428eSgjelinek boolean_t force_set = B_FALSE; 38720209230bSgjelinek size_t physmem_size = sizeof (in_progress_mcaptab.zone_physmem_cap); 38730209230bSgjelinek uint64_t mem_cap, mem_limit; 3874c97ad5cdSakolb float cap; 3875c97ad5cdSakolb char *unitp; 38760209230bSgjelinek struct zone_psettab tmp_psettab; 3877bbec428eSgjelinek boolean_t arg_err = B_FALSE; 38787c478bd9Sstevel@tonic-gate 38797c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_SET)) 38807c478bd9Sstevel@tonic-gate return; 38817c478bd9Sstevel@tonic-gate 38827c478bd9Sstevel@tonic-gate assert(cmd != NULL); 38837c478bd9Sstevel@tonic-gate 3884555afedfScarlsonj optind = opterr = 0; 3885555afedfScarlsonj while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "F")) != EOF) { 3886555afedfScarlsonj switch (arg) { 3887555afedfScarlsonj case 'F': 3888bbec428eSgjelinek force_set = B_TRUE; 3889555afedfScarlsonj break; 3890555afedfScarlsonj default: 3891555afedfScarlsonj if (optopt == '?') 3892555afedfScarlsonj longer_usage(CMD_SET); 3893555afedfScarlsonj else 3894555afedfScarlsonj short_usage(CMD_SET); 3895bbec428eSgjelinek arg_err = B_TRUE; 38967ec75eb8Sgjelinek break; 38977ec75eb8Sgjelinek } 38987ec75eb8Sgjelinek } 38997ec75eb8Sgjelinek if (arg_err) 3900555afedfScarlsonj return; 3901555afedfScarlsonj 39027c478bd9Sstevel@tonic-gate prop_type = cmd->cmd_prop_name[0]; 39037c478bd9Sstevel@tonic-gate if (global_scope) { 39040209230bSgjelinek if (gz_invalid_property(prop_type)) { 39050209230bSgjelinek zerr(gettext("%s is not a valid property for the " 39060209230bSgjelinek "global zone."), pt_to_str(prop_type)); 3907bbec428eSgjelinek saw_error = B_TRUE; 39080209230bSgjelinek return; 39090209230bSgjelinek } 39100209230bSgjelinek 3911087719fdSdp if (prop_type == PT_ZONENAME) { 3912087719fdSdp res_type = RT_ZONENAME; 3913087719fdSdp } else if (prop_type == PT_ZONEPATH) { 39147c478bd9Sstevel@tonic-gate res_type = RT_ZONEPATH; 39157c478bd9Sstevel@tonic-gate } else if (prop_type == PT_AUTOBOOT) { 39167c478bd9Sstevel@tonic-gate res_type = RT_AUTOBOOT; 39179acbbeafSnn35248 } else if (prop_type == PT_BRAND) { 39189acbbeafSnn35248 res_type = RT_BRAND; 39197c478bd9Sstevel@tonic-gate } else if (prop_type == PT_POOL) { 39207c478bd9Sstevel@tonic-gate res_type = RT_POOL; 3921ffbafc53Scomay } else if (prop_type == PT_LIMITPRIV) { 3922ffbafc53Scomay res_type = RT_LIMITPRIV; 39233f2f09c1Sdp } else if (prop_type == PT_BOOTARGS) { 39243f2f09c1Sdp res_type = RT_BOOTARGS; 39250209230bSgjelinek } else if (prop_type == PT_SCHED) { 39260209230bSgjelinek res_type = RT_SCHED; 3927f4b3ec61Sdh155122 } else if (prop_type == PT_IPTYPE) { 3928f4b3ec61Sdh155122 res_type = RT_IPTYPE; 39290209230bSgjelinek } else if (prop_type == PT_MAXLWPS) { 39300209230bSgjelinek res_type = RT_MAXLWPS; 39310209230bSgjelinek } else if (prop_type == PT_MAXSHMMEM) { 39320209230bSgjelinek res_type = RT_MAXSHMMEM; 39330209230bSgjelinek } else if (prop_type == PT_MAXSHMIDS) { 39340209230bSgjelinek res_type = RT_MAXSHMIDS; 39350209230bSgjelinek } else if (prop_type == PT_MAXMSGIDS) { 39360209230bSgjelinek res_type = RT_MAXMSGIDS; 39370209230bSgjelinek } else if (prop_type == PT_MAXSEMIDS) { 39380209230bSgjelinek res_type = RT_MAXSEMIDS; 39390209230bSgjelinek } else if (prop_type == PT_SHARES) { 39400209230bSgjelinek res_type = RT_SHARES; 39417c478bd9Sstevel@tonic-gate } else { 39427c478bd9Sstevel@tonic-gate zerr(gettext("Cannot set a resource-specific property " 39437c478bd9Sstevel@tonic-gate "from the global scope.")); 3944bbec428eSgjelinek saw_error = B_TRUE; 39457c478bd9Sstevel@tonic-gate return; 39467c478bd9Sstevel@tonic-gate } 39477c478bd9Sstevel@tonic-gate } else { 39487c478bd9Sstevel@tonic-gate res_type = resource_scope; 39497c478bd9Sstevel@tonic-gate } 39507c478bd9Sstevel@tonic-gate 3951555afedfScarlsonj if (force_set) { 3952555afedfScarlsonj if (res_type != RT_ZONEPATH) { 3953555afedfScarlsonj zerr(gettext("Only zonepath setting can be forced.")); 3954bbec428eSgjelinek saw_error = B_TRUE; 3955555afedfScarlsonj return; 3956555afedfScarlsonj } 3957555afedfScarlsonj if (!zonecfg_in_alt_root()) { 3958555afedfScarlsonj zerr(gettext("Zonepath is changeable only in an " 3959555afedfScarlsonj "alternate root.")); 3960bbec428eSgjelinek saw_error = B_TRUE; 3961555afedfScarlsonj return; 3962555afedfScarlsonj } 3963555afedfScarlsonj } 3964555afedfScarlsonj 39657c478bd9Sstevel@tonic-gate pp = cmd->cmd_property_ptr[0]; 39667c478bd9Sstevel@tonic-gate /* 39677c478bd9Sstevel@tonic-gate * A nasty expression but not that complicated: 39687c478bd9Sstevel@tonic-gate * 1. fs options are simple or list (tested below) 39697c478bd9Sstevel@tonic-gate * 2. rctl value's are complex or list (tested below) 39707c478bd9Sstevel@tonic-gate * Anything else should be simple. 39717c478bd9Sstevel@tonic-gate */ 39727c478bd9Sstevel@tonic-gate if (!(res_type == RT_FS && prop_type == PT_OPTIONS) && 39737c478bd9Sstevel@tonic-gate !(res_type == RT_RCTL && prop_type == PT_VALUE) && 39747c478bd9Sstevel@tonic-gate (pp->pv_type != PROP_VAL_SIMPLE || 39757c478bd9Sstevel@tonic-gate (prop_id = pp->pv_simple) == NULL)) { 39767c478bd9Sstevel@tonic-gate zerr(gettext("A %s value was expected here."), 39777c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_SIMPLE)); 3978bbec428eSgjelinek saw_error = B_TRUE; 39797c478bd9Sstevel@tonic-gate return; 39807c478bd9Sstevel@tonic-gate } 39817c478bd9Sstevel@tonic-gate if (prop_type == PT_UNKNOWN) { 3982bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 39837c478bd9Sstevel@tonic-gate return; 39847c478bd9Sstevel@tonic-gate } 39857c478bd9Sstevel@tonic-gate 3986087719fdSdp /* 3987087719fdSdp * Special case: the user can change the zone name prior to 'create'; 3988087719fdSdp * if the zone already exists, we fall through letting initialize() 3989087719fdSdp * and the rest of the logic run. 3990087719fdSdp */ 3991bbec428eSgjelinek if (res_type == RT_ZONENAME && got_handle == B_FALSE && 3992087719fdSdp !state_atleast(ZONE_STATE_CONFIGURED)) { 3993fb03efaaSdp if ((err = zonecfg_validate_zonename(prop_id)) != Z_OK) { 3994bbec428eSgjelinek zone_perror(prop_id, err, B_TRUE); 3995bbec428eSgjelinek usage(B_FALSE, HELP_SYNTAX); 3996fb03efaaSdp return; 3997fb03efaaSdp } 3998087719fdSdp (void) strlcpy(zone, prop_id, sizeof (zone)); 3999087719fdSdp return; 4000087719fdSdp } 4001087719fdSdp 4002bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 40037c478bd9Sstevel@tonic-gate return; 40047c478bd9Sstevel@tonic-gate 40057c478bd9Sstevel@tonic-gate switch (res_type) { 4006087719fdSdp case RT_ZONENAME: 4007087719fdSdp if ((err = zonecfg_set_name(handle, prop_id)) != Z_OK) { 4008087719fdSdp /* 4009087719fdSdp * Use prop_id instead of 'zone' here, since we're 4010087719fdSdp * reporting a problem about the *new* zonename. 4011087719fdSdp */ 4012bbec428eSgjelinek zone_perror(prop_id, err, B_TRUE); 4013bbec428eSgjelinek usage(B_FALSE, HELP_SYNTAX); 4014087719fdSdp } else { 4015bbec428eSgjelinek need_to_commit = B_TRUE; 4016087719fdSdp (void) strlcpy(zone, prop_id, sizeof (zone)); 4017087719fdSdp } 4018087719fdSdp return; 40197c478bd9Sstevel@tonic-gate case RT_ZONEPATH: 4020555afedfScarlsonj if (!force_set && state_atleast(ZONE_STATE_INSTALLED)) { 40217c478bd9Sstevel@tonic-gate zerr(gettext("Zone %s already installed; %s %s not " 40227c478bd9Sstevel@tonic-gate "allowed."), zone, cmd_to_str(CMD_SET), 40237c478bd9Sstevel@tonic-gate rt_to_str(RT_ZONEPATH)); 40247c478bd9Sstevel@tonic-gate return; 40257c478bd9Sstevel@tonic-gate } 40267c478bd9Sstevel@tonic-gate if (validate_zonepath_syntax(prop_id) != Z_OK) { 4027bbec428eSgjelinek saw_error = B_TRUE; 40287c478bd9Sstevel@tonic-gate return; 40297c478bd9Sstevel@tonic-gate } 40307c478bd9Sstevel@tonic-gate if ((err = zonecfg_set_zonepath(handle, prop_id)) != Z_OK) 4031bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 40327c478bd9Sstevel@tonic-gate else 4033bbec428eSgjelinek need_to_commit = B_TRUE; 40347c478bd9Sstevel@tonic-gate return; 40359acbbeafSnn35248 case RT_BRAND: 40369acbbeafSnn35248 if (state_atleast(ZONE_STATE_INSTALLED)) { 40379acbbeafSnn35248 zerr(gettext("Zone %s already installed; %s %s not " 40389acbbeafSnn35248 "allowed."), zone, cmd_to_str(CMD_SET), 40399acbbeafSnn35248 rt_to_str(RT_BRAND)); 40409acbbeafSnn35248 return; 40419acbbeafSnn35248 } 40429acbbeafSnn35248 if ((err = zonecfg_set_brand(handle, prop_id)) != Z_OK) 4043bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 40449acbbeafSnn35248 else 4045bbec428eSgjelinek need_to_commit = B_TRUE; 40469acbbeafSnn35248 return; 40477c478bd9Sstevel@tonic-gate case RT_AUTOBOOT: 40487c478bd9Sstevel@tonic-gate if (strcmp(prop_id, "true") == 0) { 40497c478bd9Sstevel@tonic-gate autoboot = B_TRUE; 40507c478bd9Sstevel@tonic-gate } else if (strcmp(prop_id, "false") == 0) { 40517c478bd9Sstevel@tonic-gate autoboot = B_FALSE; 40527c478bd9Sstevel@tonic-gate } else { 40537c478bd9Sstevel@tonic-gate zerr(gettext("%s value must be '%s' or '%s'."), 40547c478bd9Sstevel@tonic-gate pt_to_str(PT_AUTOBOOT), "true", "false"); 4055bbec428eSgjelinek saw_error = B_TRUE; 40567c478bd9Sstevel@tonic-gate return; 40577c478bd9Sstevel@tonic-gate } 40587c478bd9Sstevel@tonic-gate if ((err = zonecfg_set_autoboot(handle, autoboot)) != Z_OK) 4059bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 40607c478bd9Sstevel@tonic-gate else 4061bbec428eSgjelinek need_to_commit = B_TRUE; 40627c478bd9Sstevel@tonic-gate return; 40637c478bd9Sstevel@tonic-gate case RT_POOL: 40640209230bSgjelinek /* don't allow use of the reserved temporary pool names */ 40650209230bSgjelinek if (strncmp("SUNW", prop_id, 4) == 0) { 40660209230bSgjelinek zerr(gettext("pool names starting with SUNW are " 40670209230bSgjelinek "reserved.")); 4068bbec428eSgjelinek saw_error = B_TRUE; 40690209230bSgjelinek return; 40700209230bSgjelinek } 40710209230bSgjelinek 40720209230bSgjelinek /* can't set pool if dedicated-cpu exists */ 40730209230bSgjelinek if (zonecfg_lookup_pset(handle, &tmp_psettab) == Z_OK) { 40740209230bSgjelinek zerr(gettext("The %s resource already exists. " 40750209230bSgjelinek "A persistent pool is incompatible\nwith the %s " 40760209230bSgjelinek "resource."), rt_to_str(RT_DCPU), 40770209230bSgjelinek rt_to_str(RT_DCPU)); 4078bbec428eSgjelinek saw_error = B_TRUE; 40790209230bSgjelinek return; 40800209230bSgjelinek } 40810209230bSgjelinek 40827c478bd9Sstevel@tonic-gate if ((err = zonecfg_set_pool(handle, prop_id)) != Z_OK) 4083bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 40847c478bd9Sstevel@tonic-gate else 4085bbec428eSgjelinek need_to_commit = B_TRUE; 40867c478bd9Sstevel@tonic-gate return; 4087ffbafc53Scomay case RT_LIMITPRIV: 4088ffbafc53Scomay if ((err = zonecfg_set_limitpriv(handle, prop_id)) != Z_OK) 4089bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 4090ffbafc53Scomay else 4091bbec428eSgjelinek need_to_commit = B_TRUE; 4092ffbafc53Scomay return; 40933f2f09c1Sdp case RT_BOOTARGS: 40943f2f09c1Sdp if ((err = zonecfg_set_bootargs(handle, prop_id)) != Z_OK) 4095bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 40963f2f09c1Sdp else 4097bbec428eSgjelinek need_to_commit = B_TRUE; 40983f2f09c1Sdp return; 40990209230bSgjelinek case RT_SCHED: 41000209230bSgjelinek if ((err = zonecfg_set_sched(handle, prop_id)) != Z_OK) 4101bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 41020209230bSgjelinek else 4103bbec428eSgjelinek need_to_commit = B_TRUE; 41040209230bSgjelinek return; 4105f4b3ec61Sdh155122 case RT_IPTYPE: 4106f4b3ec61Sdh155122 if (strcmp(prop_id, "shared") == 0) { 4107f4b3ec61Sdh155122 iptype = ZS_SHARED; 4108f4b3ec61Sdh155122 } else if (strcmp(prop_id, "exclusive") == 0) { 4109f4b3ec61Sdh155122 iptype = ZS_EXCLUSIVE; 4110f4b3ec61Sdh155122 } else { 4111f4b3ec61Sdh155122 zerr(gettext("%s value must be '%s' or '%s'."), 4112f4b3ec61Sdh155122 pt_to_str(PT_IPTYPE), "shared", "exclusive"); 4113bbec428eSgjelinek saw_error = B_TRUE; 4114f4b3ec61Sdh155122 return; 4115f4b3ec61Sdh155122 } 4116f4b3ec61Sdh155122 if (iptype == ZS_EXCLUSIVE && !allow_exclusive()) { 4117bbec428eSgjelinek saw_error = B_TRUE; 4118f4b3ec61Sdh155122 return; 4119f4b3ec61Sdh155122 } 4120f4b3ec61Sdh155122 if ((err = zonecfg_set_iptype(handle, iptype)) != Z_OK) 4121bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 4122f4b3ec61Sdh155122 else 4123bbec428eSgjelinek need_to_commit = B_TRUE; 4124f4b3ec61Sdh155122 return; 41250209230bSgjelinek case RT_MAXLWPS: 41260209230bSgjelinek set_aliased_rctl(ALIAS_MAXLWPS, prop_type, prop_id); 41270209230bSgjelinek return; 41280209230bSgjelinek case RT_MAXSHMMEM: 41290209230bSgjelinek set_aliased_rctl(ALIAS_MAXSHMMEM, prop_type, prop_id); 41300209230bSgjelinek return; 41310209230bSgjelinek case RT_MAXSHMIDS: 41320209230bSgjelinek set_aliased_rctl(ALIAS_MAXSHMIDS, prop_type, prop_id); 41330209230bSgjelinek return; 41340209230bSgjelinek case RT_MAXMSGIDS: 41350209230bSgjelinek set_aliased_rctl(ALIAS_MAXMSGIDS, prop_type, prop_id); 41360209230bSgjelinek return; 41370209230bSgjelinek case RT_MAXSEMIDS: 41380209230bSgjelinek set_aliased_rctl(ALIAS_MAXSEMIDS, prop_type, prop_id); 41390209230bSgjelinek return; 41400209230bSgjelinek case RT_SHARES: 41410209230bSgjelinek set_aliased_rctl(ALIAS_SHARES, prop_type, prop_id); 41420209230bSgjelinek return; 41437c478bd9Sstevel@tonic-gate case RT_FS: 41447c478bd9Sstevel@tonic-gate switch (prop_type) { 41457c478bd9Sstevel@tonic-gate case PT_DIR: 41467c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_fstab.zone_fs_dir, prop_id, 41477c478bd9Sstevel@tonic-gate sizeof (in_progress_fstab.zone_fs_dir)); 41487c478bd9Sstevel@tonic-gate return; 41497c478bd9Sstevel@tonic-gate case PT_SPECIAL: 41507c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_fstab.zone_fs_special, 41517c478bd9Sstevel@tonic-gate prop_id, 41527c478bd9Sstevel@tonic-gate sizeof (in_progress_fstab.zone_fs_special)); 41537c478bd9Sstevel@tonic-gate return; 41547c478bd9Sstevel@tonic-gate case PT_RAW: 41557c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_fstab.zone_fs_raw, 41567c478bd9Sstevel@tonic-gate prop_id, sizeof (in_progress_fstab.zone_fs_raw)); 41577c478bd9Sstevel@tonic-gate return; 41587c478bd9Sstevel@tonic-gate case PT_TYPE: 41597c478bd9Sstevel@tonic-gate if (!valid_fs_type(prop_id)) { 41607c478bd9Sstevel@tonic-gate zerr(gettext("\"%s\" is not a valid %s."), 41617c478bd9Sstevel@tonic-gate prop_id, pt_to_str(PT_TYPE)); 4162bbec428eSgjelinek saw_error = B_TRUE; 41637c478bd9Sstevel@tonic-gate return; 41647c478bd9Sstevel@tonic-gate } 41657c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_fstab.zone_fs_type, prop_id, 41667c478bd9Sstevel@tonic-gate sizeof (in_progress_fstab.zone_fs_type)); 41677c478bd9Sstevel@tonic-gate return; 41687c478bd9Sstevel@tonic-gate case PT_OPTIONS: 41697c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_SIMPLE && 41707c478bd9Sstevel@tonic-gate pp->pv_type != PROP_VAL_LIST) { 41717c478bd9Sstevel@tonic-gate zerr(gettext("A %s or %s value was expected " 41727c478bd9Sstevel@tonic-gate "here."), pvt_to_str(PROP_VAL_SIMPLE), 41737c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_LIST)); 4174bbec428eSgjelinek saw_error = B_TRUE; 41757c478bd9Sstevel@tonic-gate return; 41767c478bd9Sstevel@tonic-gate } 41777c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list( 41787c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_options); 41797c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_options = NULL; 41807c478bd9Sstevel@tonic-gate if (!(pp->pv_type == PROP_VAL_LIST && 41817c478bd9Sstevel@tonic-gate pp->pv_list == NULL)) 41827c478bd9Sstevel@tonic-gate add_property(cmd); 41837c478bd9Sstevel@tonic-gate return; 41847c478bd9Sstevel@tonic-gate default: 41857c478bd9Sstevel@tonic-gate break; 41867c478bd9Sstevel@tonic-gate } 4187bbec428eSgjelinek zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, B_TRUE); 4188bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4189bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 41907c478bd9Sstevel@tonic-gate return; 41917c478bd9Sstevel@tonic-gate case RT_IPD: 41927c478bd9Sstevel@tonic-gate switch (prop_type) { 41937c478bd9Sstevel@tonic-gate case PT_DIR: 41947c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_ipdtab.zone_fs_dir, prop_id, 41957c478bd9Sstevel@tonic-gate sizeof (in_progress_ipdtab.zone_fs_dir)); 41967c478bd9Sstevel@tonic-gate return; 41977c478bd9Sstevel@tonic-gate default: 41987c478bd9Sstevel@tonic-gate break; 41997c478bd9Sstevel@tonic-gate } 4200bbec428eSgjelinek zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, B_TRUE); 4201bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4202bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 42037c478bd9Sstevel@tonic-gate return; 42047c478bd9Sstevel@tonic-gate case RT_NET: 42057c478bd9Sstevel@tonic-gate switch (prop_type) { 42067c478bd9Sstevel@tonic-gate case PT_ADDRESS: 42077c478bd9Sstevel@tonic-gate if (validate_net_address_syntax(prop_id) != Z_OK) { 4208bbec428eSgjelinek saw_error = B_TRUE; 42097c478bd9Sstevel@tonic-gate return; 42107c478bd9Sstevel@tonic-gate } 42117c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_nwiftab.zone_nwif_address, 42127c478bd9Sstevel@tonic-gate prop_id, 42137c478bd9Sstevel@tonic-gate sizeof (in_progress_nwiftab.zone_nwif_address)); 42147c478bd9Sstevel@tonic-gate break; 42157c478bd9Sstevel@tonic-gate case PT_PHYSICAL: 42167c478bd9Sstevel@tonic-gate if (validate_net_physical_syntax(prop_id) != Z_OK) { 4217bbec428eSgjelinek saw_error = B_TRUE; 42187c478bd9Sstevel@tonic-gate return; 42197c478bd9Sstevel@tonic-gate } 42207c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_nwiftab.zone_nwif_physical, 42217c478bd9Sstevel@tonic-gate prop_id, 42227c478bd9Sstevel@tonic-gate sizeof (in_progress_nwiftab.zone_nwif_physical)); 42237c478bd9Sstevel@tonic-gate break; 4224de860bd9Sgfaden case PT_DEFROUTER: 4225de860bd9Sgfaden if (validate_net_address_syntax(prop_id) != Z_OK) { 4226bbec428eSgjelinek saw_error = B_TRUE; 4227de860bd9Sgfaden return; 4228de860bd9Sgfaden } 4229de860bd9Sgfaden (void) strlcpy(in_progress_nwiftab.zone_nwif_defrouter, 4230de860bd9Sgfaden prop_id, 4231de860bd9Sgfaden sizeof (in_progress_nwiftab.zone_nwif_defrouter)); 4232de860bd9Sgfaden break; 42337c478bd9Sstevel@tonic-gate default: 42347c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 4235bbec428eSgjelinek B_TRUE); 4236bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4237bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 42387c478bd9Sstevel@tonic-gate return; 42397c478bd9Sstevel@tonic-gate } 42407c478bd9Sstevel@tonic-gate return; 42417c478bd9Sstevel@tonic-gate case RT_DEVICE: 42427c478bd9Sstevel@tonic-gate switch (prop_type) { 42437c478bd9Sstevel@tonic-gate case PT_MATCH: 42447c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_devtab.zone_dev_match, 42457c478bd9Sstevel@tonic-gate prop_id, 42467c478bd9Sstevel@tonic-gate sizeof (in_progress_devtab.zone_dev_match)); 42477c478bd9Sstevel@tonic-gate break; 42487c478bd9Sstevel@tonic-gate default: 42497c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 4250bbec428eSgjelinek B_TRUE); 4251bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4252bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 42537c478bd9Sstevel@tonic-gate return; 42547c478bd9Sstevel@tonic-gate } 42557c478bd9Sstevel@tonic-gate return; 42567c478bd9Sstevel@tonic-gate case RT_RCTL: 42577c478bd9Sstevel@tonic-gate switch (prop_type) { 42587c478bd9Sstevel@tonic-gate case PT_NAME: 42597c478bd9Sstevel@tonic-gate if (!zonecfg_valid_rctlname(prop_id)) { 42607c478bd9Sstevel@tonic-gate zerr(gettext("'%s' is not a valid zone %s " 42617c478bd9Sstevel@tonic-gate "name."), prop_id, rt_to_str(RT_RCTL)); 42627c478bd9Sstevel@tonic-gate return; 42637c478bd9Sstevel@tonic-gate } 42647c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_rctltab.zone_rctl_name, 42657c478bd9Sstevel@tonic-gate prop_id, 42667c478bd9Sstevel@tonic-gate sizeof (in_progress_rctltab.zone_rctl_name)); 42677c478bd9Sstevel@tonic-gate break; 42687c478bd9Sstevel@tonic-gate case PT_VALUE: 42697c478bd9Sstevel@tonic-gate if (pp->pv_type != PROP_VAL_COMPLEX && 42707c478bd9Sstevel@tonic-gate pp->pv_type != PROP_VAL_LIST) { 42717c478bd9Sstevel@tonic-gate zerr(gettext("A %s or %s value was expected " 42727c478bd9Sstevel@tonic-gate "here."), pvt_to_str(PROP_VAL_COMPLEX), 42737c478bd9Sstevel@tonic-gate pvt_to_str(PROP_VAL_LIST)); 4274bbec428eSgjelinek saw_error = B_TRUE; 42757c478bd9Sstevel@tonic-gate return; 42767c478bd9Sstevel@tonic-gate } 42777c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list( 42787c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_valptr); 42797c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_valptr = NULL; 42807c478bd9Sstevel@tonic-gate if (!(pp->pv_type == PROP_VAL_LIST && 42817c478bd9Sstevel@tonic-gate pp->pv_list == NULL)) 42827c478bd9Sstevel@tonic-gate add_property(cmd); 42837c478bd9Sstevel@tonic-gate break; 42847c478bd9Sstevel@tonic-gate default: 42857c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 4286bbec428eSgjelinek B_TRUE); 4287bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4288bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 42897c478bd9Sstevel@tonic-gate return; 42907c478bd9Sstevel@tonic-gate } 42917c478bd9Sstevel@tonic-gate return; 42927c478bd9Sstevel@tonic-gate case RT_ATTR: 42937c478bd9Sstevel@tonic-gate switch (prop_type) { 42947c478bd9Sstevel@tonic-gate case PT_NAME: 42957c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_attrtab.zone_attr_name, 42967c478bd9Sstevel@tonic-gate prop_id, 42977c478bd9Sstevel@tonic-gate sizeof (in_progress_attrtab.zone_attr_name)); 42987c478bd9Sstevel@tonic-gate break; 42997c478bd9Sstevel@tonic-gate case PT_TYPE: 43007c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_attrtab.zone_attr_type, 43017c478bd9Sstevel@tonic-gate prop_id, 43027c478bd9Sstevel@tonic-gate sizeof (in_progress_attrtab.zone_attr_type)); 43037c478bd9Sstevel@tonic-gate break; 43047c478bd9Sstevel@tonic-gate case PT_VALUE: 43057c478bd9Sstevel@tonic-gate (void) strlcpy(in_progress_attrtab.zone_attr_value, 43067c478bd9Sstevel@tonic-gate prop_id, 43077c478bd9Sstevel@tonic-gate sizeof (in_progress_attrtab.zone_attr_value)); 43087c478bd9Sstevel@tonic-gate break; 43097c478bd9Sstevel@tonic-gate default: 43107c478bd9Sstevel@tonic-gate zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 4311bbec428eSgjelinek B_TRUE); 4312bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4313bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 43147c478bd9Sstevel@tonic-gate return; 43157c478bd9Sstevel@tonic-gate } 43167c478bd9Sstevel@tonic-gate return; 4317fa9e4066Sahrens case RT_DATASET: 4318fa9e4066Sahrens switch (prop_type) { 4319fa9e4066Sahrens case PT_NAME: 4320fa9e4066Sahrens (void) strlcpy(in_progress_dstab.zone_dataset_name, 4321fa9e4066Sahrens prop_id, 4322fa9e4066Sahrens sizeof (in_progress_dstab.zone_dataset_name)); 4323fa9e4066Sahrens return; 4324fa9e4066Sahrens default: 4325fa9e4066Sahrens break; 4326fa9e4066Sahrens } 4327bbec428eSgjelinek zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, B_TRUE); 4328bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4329bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 4330fa9e4066Sahrens return; 43310209230bSgjelinek case RT_DCPU: 43320209230bSgjelinek switch (prop_type) { 43330209230bSgjelinek char *lowp, *highp; 43340209230bSgjelinek 43350209230bSgjelinek case PT_NCPUS: 43360209230bSgjelinek lowp = prop_id; 43370209230bSgjelinek if ((highp = strchr(prop_id, '-')) != NULL) 43380209230bSgjelinek *highp++ = '\0'; 43390209230bSgjelinek else 43400209230bSgjelinek highp = lowp; 43410209230bSgjelinek 43420209230bSgjelinek /* Make sure the input makes sense. */ 43430209230bSgjelinek if (!zonecfg_valid_ncpus(lowp, highp)) { 43440209230bSgjelinek zerr(gettext("%s property is out of range."), 43450209230bSgjelinek pt_to_str(PT_NCPUS)); 4346bbec428eSgjelinek saw_error = B_TRUE; 43470209230bSgjelinek return; 43480209230bSgjelinek } 43490209230bSgjelinek 43500209230bSgjelinek (void) strlcpy( 43510209230bSgjelinek in_progress_psettab.zone_ncpu_min, lowp, 43520209230bSgjelinek sizeof (in_progress_psettab.zone_ncpu_min)); 43530209230bSgjelinek (void) strlcpy( 43540209230bSgjelinek in_progress_psettab.zone_ncpu_max, highp, 43550209230bSgjelinek sizeof (in_progress_psettab.zone_ncpu_max)); 43560209230bSgjelinek return; 43570209230bSgjelinek case PT_IMPORTANCE: 43580209230bSgjelinek /* Make sure the value makes sense. */ 43590209230bSgjelinek if (!zonecfg_valid_importance(prop_id)) { 43600209230bSgjelinek zerr(gettext("%s property is out of range."), 43610209230bSgjelinek pt_to_str(PT_IMPORTANCE)); 4362bbec428eSgjelinek saw_error = B_TRUE; 43630209230bSgjelinek return; 43640209230bSgjelinek } 43650209230bSgjelinek 43660209230bSgjelinek (void) strlcpy(in_progress_psettab.zone_importance, 43670209230bSgjelinek prop_id, 43680209230bSgjelinek sizeof (in_progress_psettab.zone_importance)); 43690209230bSgjelinek return; 43700209230bSgjelinek default: 43710209230bSgjelinek break; 43720209230bSgjelinek } 4373bbec428eSgjelinek zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, B_TRUE); 4374bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4375bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 43760209230bSgjelinek return; 4377c97ad5cdSakolb case RT_PCAP: 4378c97ad5cdSakolb if (prop_type != PT_NCPUS) { 4379c97ad5cdSakolb zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 4380bbec428eSgjelinek B_TRUE); 4381bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4382bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 4383c97ad5cdSakolb return; 4384c97ad5cdSakolb } 4385c97ad5cdSakolb 4386c97ad5cdSakolb /* 4387c97ad5cdSakolb * We already checked that an rctl alias is allowed in 4388c97ad5cdSakolb * the add_resource() function. 4389c97ad5cdSakolb */ 4390c97ad5cdSakolb 4391c97ad5cdSakolb if ((cap = strtof(prop_id, &unitp)) <= 0 || *unitp != '\0' || 4392c97ad5cdSakolb (int)(cap * 100) < 1) { 4393c97ad5cdSakolb zerr(gettext("%s property is out of range."), 4394c97ad5cdSakolb pt_to_str(PT_NCPUS)); 4395bbec428eSgjelinek saw_error = B_TRUE; 4396c97ad5cdSakolb return; 4397c97ad5cdSakolb } 4398c97ad5cdSakolb 4399c97ad5cdSakolb if ((err = zonecfg_set_aliased_rctl(handle, ALIAS_CPUCAP, 4400c97ad5cdSakolb (int)(cap * 100))) != Z_OK) 4401bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 4402c97ad5cdSakolb else 4403bbec428eSgjelinek need_to_commit = B_TRUE; 4404c97ad5cdSakolb return; 44050209230bSgjelinek case RT_MCAP: 44060209230bSgjelinek switch (prop_type) { 44070209230bSgjelinek case PT_PHYSICAL: 44080209230bSgjelinek if (!zonecfg_valid_memlimit(prop_id, &mem_cap)) { 44090209230bSgjelinek zerr(gettext("A positive number with a " 44100209230bSgjelinek "required scale suffix (K, M, G or T) was " 44110209230bSgjelinek "expected here.")); 4412bbec428eSgjelinek saw_error = B_TRUE; 44130209230bSgjelinek } else if (mem_cap < ONE_MB) { 44140209230bSgjelinek zerr(gettext("%s value is too small. It must " 44150209230bSgjelinek "be at least 1M."), pt_to_str(PT_PHYSICAL)); 4416bbec428eSgjelinek saw_error = B_TRUE; 44170209230bSgjelinek } else { 44180209230bSgjelinek snprintf(in_progress_mcaptab.zone_physmem_cap, 44190209230bSgjelinek physmem_size, "%llu", mem_cap); 44200209230bSgjelinek } 44210209230bSgjelinek break; 44220209230bSgjelinek case PT_SWAP: 44230209230bSgjelinek /* 44240209230bSgjelinek * We have to check if an rctl is allowed here since 44250209230bSgjelinek * there might already be a rctl defined that blocks 44260209230bSgjelinek * the alias. 44270209230bSgjelinek */ 44280209230bSgjelinek if (!zonecfg_aliased_rctl_ok(handle, ALIAS_MAXSWAP)) { 44290209230bSgjelinek zone_perror(pt_to_str(PT_MAXSWAP), 4430bbec428eSgjelinek Z_ALIAS_DISALLOW, B_FALSE); 4431bbec428eSgjelinek saw_error = B_TRUE; 44320209230bSgjelinek return; 44330209230bSgjelinek } 44340209230bSgjelinek 44350209230bSgjelinek if (global_zone) 44360209230bSgjelinek mem_limit = ONE_MB * 100; 44370209230bSgjelinek else 44380209230bSgjelinek mem_limit = ONE_MB * 50; 44390209230bSgjelinek 44400209230bSgjelinek if (!zonecfg_valid_memlimit(prop_id, &mem_cap)) { 44410209230bSgjelinek zerr(gettext("A positive number with a " 44420209230bSgjelinek "required scale suffix (K, M, G or T) was " 44430209230bSgjelinek "expected here.")); 4444bbec428eSgjelinek saw_error = B_TRUE; 44450209230bSgjelinek } else if (mem_cap < mem_limit) { 44460209230bSgjelinek char buf[128]; 44470209230bSgjelinek 44480209230bSgjelinek (void) snprintf(buf, sizeof (buf), "%llu", 44490209230bSgjelinek mem_limit); 44500209230bSgjelinek bytes_to_units(buf, buf, sizeof (buf)); 44510209230bSgjelinek zerr(gettext("%s value is too small. It must " 44520209230bSgjelinek "be at least %s."), pt_to_str(PT_SWAP), 44530209230bSgjelinek buf); 4454bbec428eSgjelinek saw_error = B_TRUE; 44550209230bSgjelinek } else { 44560209230bSgjelinek if ((err = zonecfg_set_aliased_rctl(handle, 44570209230bSgjelinek ALIAS_MAXSWAP, mem_cap)) != Z_OK) 4458bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 44590209230bSgjelinek else 4460bbec428eSgjelinek need_to_commit = B_TRUE; 44610209230bSgjelinek } 44620209230bSgjelinek break; 44630209230bSgjelinek case PT_LOCKED: 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, 44700209230bSgjelinek ALIAS_MAXLOCKEDMEM)) { 44710209230bSgjelinek zone_perror(pt_to_str(PT_LOCKED), 4472bbec428eSgjelinek Z_ALIAS_DISALLOW, B_FALSE); 4473bbec428eSgjelinek saw_error = B_TRUE; 44740209230bSgjelinek return; 44750209230bSgjelinek } 44760209230bSgjelinek 44770209230bSgjelinek if (!zonecfg_valid_memlimit(prop_id, &mem_cap)) { 44780209230bSgjelinek zerr(gettext("A non-negative number with a " 44790209230bSgjelinek "required scale suffix (K, M, G or T) was " 44800209230bSgjelinek "expected\nhere.")); 4481bbec428eSgjelinek saw_error = B_TRUE; 44820209230bSgjelinek } else { 44830209230bSgjelinek if ((err = zonecfg_set_aliased_rctl(handle, 44840209230bSgjelinek ALIAS_MAXLOCKEDMEM, mem_cap)) != Z_OK) 4485bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 44860209230bSgjelinek else 4487bbec428eSgjelinek need_to_commit = B_TRUE; 44880209230bSgjelinek } 44890209230bSgjelinek break; 44900209230bSgjelinek default: 44910209230bSgjelinek zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE, 4492bbec428eSgjelinek B_TRUE); 4493bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4494bbec428eSgjelinek usage(B_FALSE, HELP_PROPS); 44950209230bSgjelinek return; 44960209230bSgjelinek } 44970209230bSgjelinek 44980209230bSgjelinek return; 44997c478bd9Sstevel@tonic-gate default: 4500bbec428eSgjelinek zone_perror(rt_to_str(res_type), Z_NO_RESOURCE_TYPE, B_TRUE); 4501bbec428eSgjelinek long_usage(CMD_SET, B_TRUE); 4502bbec428eSgjelinek usage(B_FALSE, HELP_RESOURCES); 45037c478bd9Sstevel@tonic-gate return; 45047c478bd9Sstevel@tonic-gate } 45057c478bd9Sstevel@tonic-gate } 45067c478bd9Sstevel@tonic-gate 45077c478bd9Sstevel@tonic-gate static void 4508bbec428eSgjelinek output_prop(FILE *fp, int pnum, char *pval, boolean_t print_notspec) 45097c478bd9Sstevel@tonic-gate { 45107c478bd9Sstevel@tonic-gate char *qstr; 45117c478bd9Sstevel@tonic-gate 45127c478bd9Sstevel@tonic-gate if (*pval != '\0') { 45137c478bd9Sstevel@tonic-gate qstr = quoteit(pval); 45140209230bSgjelinek if (pnum == PT_SWAP || pnum == PT_LOCKED) 45150209230bSgjelinek (void) fprintf(fp, "\t[%s: %s]\n", pt_to_str(pnum), 45160209230bSgjelinek qstr); 45170209230bSgjelinek else 45187c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s: %s\n", pt_to_str(pnum), qstr); 45197c478bd9Sstevel@tonic-gate free(qstr); 45207c478bd9Sstevel@tonic-gate } else if (print_notspec) 4521087719fdSdp (void) fprintf(fp, gettext("\t%s not specified\n"), 4522087719fdSdp pt_to_str(pnum)); 4523087719fdSdp } 4524087719fdSdp 4525087719fdSdp static void 4526087719fdSdp info_zonename(zone_dochandle_t handle, FILE *fp) 4527087719fdSdp { 4528087719fdSdp char zonename[ZONENAME_MAX]; 4529087719fdSdp 4530087719fdSdp if (zonecfg_get_name(handle, zonename, sizeof (zonename)) == Z_OK) 4531087719fdSdp (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_ZONENAME), 4532087719fdSdp zonename); 4533087719fdSdp else 4534087719fdSdp (void) fprintf(fp, gettext("%s not specified\n"), 4535087719fdSdp pt_to_str(PT_ZONENAME)); 45367c478bd9Sstevel@tonic-gate } 45377c478bd9Sstevel@tonic-gate 45387c478bd9Sstevel@tonic-gate static void 45397c478bd9Sstevel@tonic-gate info_zonepath(zone_dochandle_t handle, FILE *fp) 45407c478bd9Sstevel@tonic-gate { 45417c478bd9Sstevel@tonic-gate char zonepath[MAXPATHLEN]; 45427c478bd9Sstevel@tonic-gate 45437c478bd9Sstevel@tonic-gate if (zonecfg_get_zonepath(handle, zonepath, sizeof (zonepath)) == Z_OK) 45447c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_ZONEPATH), 45457c478bd9Sstevel@tonic-gate zonepath); 4546087719fdSdp else { 4547087719fdSdp (void) fprintf(fp, gettext("%s not specified\n"), 4548087719fdSdp pt_to_str(PT_ZONEPATH)); 4549087719fdSdp } 45507c478bd9Sstevel@tonic-gate } 45517c478bd9Sstevel@tonic-gate 45527c478bd9Sstevel@tonic-gate static void 45539acbbeafSnn35248 info_brand(zone_dochandle_t handle, FILE *fp) 45549acbbeafSnn35248 { 45559acbbeafSnn35248 char brand[MAXNAMELEN]; 45569acbbeafSnn35248 45579acbbeafSnn35248 if (zonecfg_get_brand(handle, brand, sizeof (brand)) == Z_OK) 45589acbbeafSnn35248 (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_BRAND), 45599acbbeafSnn35248 brand); 45609acbbeafSnn35248 else 45619acbbeafSnn35248 (void) fprintf(fp, "%s %s\n", pt_to_str(PT_BRAND), 45629acbbeafSnn35248 gettext("not specified")); 45639acbbeafSnn35248 } 45649acbbeafSnn35248 45659acbbeafSnn35248 static void 45667c478bd9Sstevel@tonic-gate info_autoboot(zone_dochandle_t handle, FILE *fp) 45677c478bd9Sstevel@tonic-gate { 45687c478bd9Sstevel@tonic-gate boolean_t autoboot; 45697c478bd9Sstevel@tonic-gate int err; 45707c478bd9Sstevel@tonic-gate 45717c478bd9Sstevel@tonic-gate if ((err = zonecfg_get_autoboot(handle, &autoboot)) == Z_OK) 45727c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_AUTOBOOT), 45737c478bd9Sstevel@tonic-gate autoboot ? "true" : "false"); 45747c478bd9Sstevel@tonic-gate else 4575bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 45767c478bd9Sstevel@tonic-gate } 45777c478bd9Sstevel@tonic-gate 45787c478bd9Sstevel@tonic-gate static void 45797c478bd9Sstevel@tonic-gate info_pool(zone_dochandle_t handle, FILE *fp) 45807c478bd9Sstevel@tonic-gate { 45817c478bd9Sstevel@tonic-gate char pool[MAXNAMELEN]; 45827c478bd9Sstevel@tonic-gate int err; 45837c478bd9Sstevel@tonic-gate 45847c478bd9Sstevel@tonic-gate if ((err = zonecfg_get_pool(handle, pool, sizeof (pool))) == Z_OK) 45857c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_POOL), pool); 45867c478bd9Sstevel@tonic-gate else 4587bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 45887c478bd9Sstevel@tonic-gate } 45897c478bd9Sstevel@tonic-gate 45907c478bd9Sstevel@tonic-gate static void 4591ffbafc53Scomay info_limitpriv(zone_dochandle_t handle, FILE *fp) 4592ffbafc53Scomay { 4593ffbafc53Scomay char *limitpriv; 4594ffbafc53Scomay int err; 4595ffbafc53Scomay 4596ffbafc53Scomay if ((err = zonecfg_get_limitpriv(handle, &limitpriv)) == Z_OK) { 4597ffbafc53Scomay (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_LIMITPRIV), 4598ffbafc53Scomay limitpriv); 4599ffbafc53Scomay free(limitpriv); 4600ffbafc53Scomay } else { 4601bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 4602ffbafc53Scomay } 4603ffbafc53Scomay } 4604ffbafc53Scomay 4605ffbafc53Scomay static void 46063f2f09c1Sdp info_bootargs(zone_dochandle_t handle, FILE *fp) 46073f2f09c1Sdp { 46083f2f09c1Sdp char bootargs[BOOTARGS_MAX]; 46093f2f09c1Sdp int err; 46103f2f09c1Sdp 46113f2f09c1Sdp if ((err = zonecfg_get_bootargs(handle, bootargs, 46123f2f09c1Sdp sizeof (bootargs))) == Z_OK) { 46133f2f09c1Sdp (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_BOOTARGS), 46143f2f09c1Sdp bootargs); 46153f2f09c1Sdp } else { 4616bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 46173f2f09c1Sdp } 46183f2f09c1Sdp } 46193f2f09c1Sdp 46203f2f09c1Sdp static void 46210209230bSgjelinek info_sched(zone_dochandle_t handle, FILE *fp) 46220209230bSgjelinek { 46230209230bSgjelinek char sched[MAXNAMELEN]; 46240209230bSgjelinek int err; 46250209230bSgjelinek 46260209230bSgjelinek if ((err = zonecfg_get_sched_class(handle, sched, sizeof (sched))) 46270209230bSgjelinek == Z_OK) { 46280209230bSgjelinek (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_SCHED), sched); 46290209230bSgjelinek } else { 4630bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 46310209230bSgjelinek } 46320209230bSgjelinek } 46330209230bSgjelinek 46340209230bSgjelinek static void 4635f4b3ec61Sdh155122 info_iptype(zone_dochandle_t handle, FILE *fp) 4636f4b3ec61Sdh155122 { 4637f4b3ec61Sdh155122 zone_iptype_t iptype; 4638f4b3ec61Sdh155122 int err; 4639f4b3ec61Sdh155122 4640f4b3ec61Sdh155122 if ((err = zonecfg_get_iptype(handle, &iptype)) == Z_OK) { 4641f4b3ec61Sdh155122 switch (iptype) { 4642f4b3ec61Sdh155122 case ZS_SHARED: 4643f4b3ec61Sdh155122 (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_IPTYPE), 4644f4b3ec61Sdh155122 "shared"); 4645f4b3ec61Sdh155122 break; 4646f4b3ec61Sdh155122 case ZS_EXCLUSIVE: 4647f4b3ec61Sdh155122 (void) fprintf(fp, "%s: %s\n", pt_to_str(PT_IPTYPE), 4648f4b3ec61Sdh155122 "exclusive"); 4649f4b3ec61Sdh155122 break; 4650f4b3ec61Sdh155122 } 4651f4b3ec61Sdh155122 } else { 4652bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 4653f4b3ec61Sdh155122 } 4654f4b3ec61Sdh155122 } 4655f4b3ec61Sdh155122 4656f4b3ec61Sdh155122 static void 46577c478bd9Sstevel@tonic-gate output_fs(FILE *fp, struct zone_fstab *fstab) 46587c478bd9Sstevel@tonic-gate { 46597c478bd9Sstevel@tonic-gate zone_fsopt_t *this; 46607c478bd9Sstevel@tonic-gate 46617c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n", rt_to_str(RT_FS)); 46627c478bd9Sstevel@tonic-gate output_prop(fp, PT_DIR, fstab->zone_fs_dir, B_TRUE); 46637c478bd9Sstevel@tonic-gate output_prop(fp, PT_SPECIAL, fstab->zone_fs_special, B_TRUE); 46647c478bd9Sstevel@tonic-gate output_prop(fp, PT_RAW, fstab->zone_fs_raw, B_TRUE); 46657c478bd9Sstevel@tonic-gate output_prop(fp, PT_TYPE, fstab->zone_fs_type, B_TRUE); 46667c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\t%s: [", pt_to_str(PT_OPTIONS)); 46677c478bd9Sstevel@tonic-gate for (this = fstab->zone_fs_options; this != NULL; 46687c478bd9Sstevel@tonic-gate this = this->zone_fsopt_next) { 46697c478bd9Sstevel@tonic-gate if (strchr(this->zone_fsopt_opt, '=')) 46707c478bd9Sstevel@tonic-gate (void) fprintf(fp, "\"%s\"", this->zone_fsopt_opt); 46717c478bd9Sstevel@tonic-gate else 46727c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s", this->zone_fsopt_opt); 46737c478bd9Sstevel@tonic-gate if (this->zone_fsopt_next != NULL) 46747c478bd9Sstevel@tonic-gate (void) fprintf(fp, ","); 46757c478bd9Sstevel@tonic-gate } 46767c478bd9Sstevel@tonic-gate (void) fprintf(fp, "]\n"); 46777c478bd9Sstevel@tonic-gate } 46787c478bd9Sstevel@tonic-gate 46797c478bd9Sstevel@tonic-gate static void 46807c478bd9Sstevel@tonic-gate output_ipd(FILE *fp, struct zone_fstab *ipdtab) 46817c478bd9Sstevel@tonic-gate { 46827c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n", rt_to_str(RT_IPD)); 46837c478bd9Sstevel@tonic-gate output_prop(fp, PT_DIR, ipdtab->zone_fs_dir, B_TRUE); 46847c478bd9Sstevel@tonic-gate } 46857c478bd9Sstevel@tonic-gate 46867c478bd9Sstevel@tonic-gate static void 46877c478bd9Sstevel@tonic-gate info_fs(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 46887c478bd9Sstevel@tonic-gate { 46897c478bd9Sstevel@tonic-gate struct zone_fstab lookup, user; 4690bbec428eSgjelinek boolean_t output = B_FALSE; 46917c478bd9Sstevel@tonic-gate 46927c478bd9Sstevel@tonic-gate if (zonecfg_setfsent(handle) != Z_OK) 46937c478bd9Sstevel@tonic-gate return; 46947c478bd9Sstevel@tonic-gate while (zonecfg_getfsent(handle, &lookup) == Z_OK) { 46957c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) { 46967c478bd9Sstevel@tonic-gate output_fs(fp, &lookup); 46977c478bd9Sstevel@tonic-gate goto loopend; 46987c478bd9Sstevel@tonic-gate } 4699bbec428eSgjelinek if (fill_in_fstab(cmd, &user, B_TRUE) != Z_OK) 47007c478bd9Sstevel@tonic-gate goto loopend; 47017c478bd9Sstevel@tonic-gate if (strlen(user.zone_fs_dir) > 0 && 47027c478bd9Sstevel@tonic-gate strcmp(user.zone_fs_dir, lookup.zone_fs_dir) != 0) 47037c478bd9Sstevel@tonic-gate goto loopend; /* no match */ 47047c478bd9Sstevel@tonic-gate if (strlen(user.zone_fs_special) > 0 && 47057c478bd9Sstevel@tonic-gate strcmp(user.zone_fs_special, lookup.zone_fs_special) != 0) 47067c478bd9Sstevel@tonic-gate goto loopend; /* no match */ 47077c478bd9Sstevel@tonic-gate if (strlen(user.zone_fs_type) > 0 && 47087c478bd9Sstevel@tonic-gate strcmp(user.zone_fs_type, lookup.zone_fs_type) != 0) 47097c478bd9Sstevel@tonic-gate goto loopend; /* no match */ 47107c478bd9Sstevel@tonic-gate output_fs(fp, &lookup); 4711bbec428eSgjelinek output = B_TRUE; 47127c478bd9Sstevel@tonic-gate loopend: 47137c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(lookup.zone_fs_options); 47147c478bd9Sstevel@tonic-gate } 47157c478bd9Sstevel@tonic-gate (void) zonecfg_endfsent(handle); 47167c478bd9Sstevel@tonic-gate /* 47177c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was 47187c478bd9Sstevel@tonic-gate * nothing to output. 47197c478bd9Sstevel@tonic-gate */ 47207c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0) 47217c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"), 47227c478bd9Sstevel@tonic-gate rt_to_str(RT_FS)); 47237c478bd9Sstevel@tonic-gate } 47247c478bd9Sstevel@tonic-gate 47257c478bd9Sstevel@tonic-gate static void 47267c478bd9Sstevel@tonic-gate info_ipd(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 47277c478bd9Sstevel@tonic-gate { 47287c478bd9Sstevel@tonic-gate struct zone_fstab lookup, user; 4729bbec428eSgjelinek boolean_t output = B_FALSE; 47307c478bd9Sstevel@tonic-gate 47317c478bd9Sstevel@tonic-gate if (zonecfg_setipdent(handle) != Z_OK) 47327c478bd9Sstevel@tonic-gate return; 47337c478bd9Sstevel@tonic-gate while (zonecfg_getipdent(handle, &lookup) == Z_OK) { 47347c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) { 47357c478bd9Sstevel@tonic-gate output_ipd(fp, &lookup); 47367c478bd9Sstevel@tonic-gate continue; 47377c478bd9Sstevel@tonic-gate } 4738bbec428eSgjelinek if (fill_in_ipdtab(cmd, &user, B_TRUE) != Z_OK) 47397c478bd9Sstevel@tonic-gate continue; 47407c478bd9Sstevel@tonic-gate if (strlen(user.zone_fs_dir) > 0 && 47417c478bd9Sstevel@tonic-gate strcmp(user.zone_fs_dir, lookup.zone_fs_dir) != 0) 47427c478bd9Sstevel@tonic-gate continue; /* no match */ 47437c478bd9Sstevel@tonic-gate output_ipd(fp, &lookup); 4744bbec428eSgjelinek output = B_TRUE; 47457c478bd9Sstevel@tonic-gate } 47467c478bd9Sstevel@tonic-gate (void) zonecfg_endipdent(handle); 47477c478bd9Sstevel@tonic-gate /* 47487c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was 47497c478bd9Sstevel@tonic-gate * nothing to output. 47507c478bd9Sstevel@tonic-gate */ 47517c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0) 47527c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"), 47537c478bd9Sstevel@tonic-gate rt_to_str(RT_IPD)); 47547c478bd9Sstevel@tonic-gate } 47557c478bd9Sstevel@tonic-gate 47567c478bd9Sstevel@tonic-gate static void 47577c478bd9Sstevel@tonic-gate output_net(FILE *fp, struct zone_nwiftab *nwiftab) 47587c478bd9Sstevel@tonic-gate { 47597c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n", rt_to_str(RT_NET)); 47607c478bd9Sstevel@tonic-gate output_prop(fp, PT_ADDRESS, nwiftab->zone_nwif_address, B_TRUE); 47617c478bd9Sstevel@tonic-gate output_prop(fp, PT_PHYSICAL, nwiftab->zone_nwif_physical, B_TRUE); 4762de860bd9Sgfaden output_prop(fp, PT_DEFROUTER, nwiftab->zone_nwif_defrouter, B_TRUE); 47637c478bd9Sstevel@tonic-gate } 47647c478bd9Sstevel@tonic-gate 47657c478bd9Sstevel@tonic-gate static void 47667c478bd9Sstevel@tonic-gate info_net(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 47677c478bd9Sstevel@tonic-gate { 47687c478bd9Sstevel@tonic-gate struct zone_nwiftab lookup, user; 4769bbec428eSgjelinek boolean_t output = B_FALSE; 47707c478bd9Sstevel@tonic-gate 47717c478bd9Sstevel@tonic-gate if (zonecfg_setnwifent(handle) != Z_OK) 47727c478bd9Sstevel@tonic-gate return; 47737c478bd9Sstevel@tonic-gate while (zonecfg_getnwifent(handle, &lookup) == Z_OK) { 47747c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) { 47757c478bd9Sstevel@tonic-gate output_net(fp, &lookup); 47767c478bd9Sstevel@tonic-gate continue; 47777c478bd9Sstevel@tonic-gate } 4778bbec428eSgjelinek if (fill_in_nwiftab(cmd, &user, B_TRUE) != Z_OK) 47797c478bd9Sstevel@tonic-gate continue; 47807c478bd9Sstevel@tonic-gate if (strlen(user.zone_nwif_physical) > 0 && 47817c478bd9Sstevel@tonic-gate strcmp(user.zone_nwif_physical, 47827c478bd9Sstevel@tonic-gate lookup.zone_nwif_physical) != 0) 47837c478bd9Sstevel@tonic-gate continue; /* no match */ 4784f4b3ec61Sdh155122 /* If present make sure it matches */ 47857c478bd9Sstevel@tonic-gate if (strlen(user.zone_nwif_address) > 0 && 47867c478bd9Sstevel@tonic-gate !zonecfg_same_net_address(user.zone_nwif_address, 47877c478bd9Sstevel@tonic-gate lookup.zone_nwif_address)) 47887c478bd9Sstevel@tonic-gate continue; /* no match */ 47897c478bd9Sstevel@tonic-gate output_net(fp, &lookup); 4790bbec428eSgjelinek output = B_TRUE; 47917c478bd9Sstevel@tonic-gate } 47927c478bd9Sstevel@tonic-gate (void) zonecfg_endnwifent(handle); 47937c478bd9Sstevel@tonic-gate /* 47947c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was 47957c478bd9Sstevel@tonic-gate * nothing to output. 47967c478bd9Sstevel@tonic-gate */ 47977c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0) 47987c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"), 47997c478bd9Sstevel@tonic-gate rt_to_str(RT_NET)); 48007c478bd9Sstevel@tonic-gate } 48017c478bd9Sstevel@tonic-gate 48027c478bd9Sstevel@tonic-gate static void 48037c478bd9Sstevel@tonic-gate output_dev(FILE *fp, struct zone_devtab *devtab) 48047c478bd9Sstevel@tonic-gate { 480527e6fb21Sdp (void) fprintf(fp, "%s:\n", rt_to_str(RT_DEVICE)); 48067c478bd9Sstevel@tonic-gate output_prop(fp, PT_MATCH, devtab->zone_dev_match, B_TRUE); 48077c478bd9Sstevel@tonic-gate } 48087c478bd9Sstevel@tonic-gate 48097c478bd9Sstevel@tonic-gate static void 48107c478bd9Sstevel@tonic-gate info_dev(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 48117c478bd9Sstevel@tonic-gate { 48127c478bd9Sstevel@tonic-gate struct zone_devtab lookup, user; 4813bbec428eSgjelinek boolean_t output = B_FALSE; 48147c478bd9Sstevel@tonic-gate 48157c478bd9Sstevel@tonic-gate if (zonecfg_setdevent(handle) != Z_OK) 48167c478bd9Sstevel@tonic-gate return; 48177c478bd9Sstevel@tonic-gate while (zonecfg_getdevent(handle, &lookup) == Z_OK) { 48187c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) { 48197c478bd9Sstevel@tonic-gate output_dev(fp, &lookup); 48207c478bd9Sstevel@tonic-gate continue; 48217c478bd9Sstevel@tonic-gate } 4822bbec428eSgjelinek if (fill_in_devtab(cmd, &user, B_TRUE) != Z_OK) 48237c478bd9Sstevel@tonic-gate continue; 48247c478bd9Sstevel@tonic-gate if (strlen(user.zone_dev_match) > 0 && 48257c478bd9Sstevel@tonic-gate strcmp(user.zone_dev_match, lookup.zone_dev_match) != 0) 48267c478bd9Sstevel@tonic-gate continue; /* no match */ 48277c478bd9Sstevel@tonic-gate output_dev(fp, &lookup); 4828bbec428eSgjelinek output = B_TRUE; 48297c478bd9Sstevel@tonic-gate } 48307c478bd9Sstevel@tonic-gate (void) zonecfg_enddevent(handle); 48317c478bd9Sstevel@tonic-gate /* 48327c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was 48337c478bd9Sstevel@tonic-gate * nothing to output. 48347c478bd9Sstevel@tonic-gate */ 48357c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0) 48367c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"), 48377c478bd9Sstevel@tonic-gate rt_to_str(RT_DEVICE)); 48387c478bd9Sstevel@tonic-gate } 48397c478bd9Sstevel@tonic-gate 48407c478bd9Sstevel@tonic-gate static void 48417c478bd9Sstevel@tonic-gate output_rctl(FILE *fp, struct zone_rctltab *rctltab) 48427c478bd9Sstevel@tonic-gate { 48437c478bd9Sstevel@tonic-gate struct zone_rctlvaltab *valptr; 48447c478bd9Sstevel@tonic-gate 48457c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n", rt_to_str(RT_RCTL)); 48467c478bd9Sstevel@tonic-gate output_prop(fp, PT_NAME, rctltab->zone_rctl_name, B_TRUE); 48477c478bd9Sstevel@tonic-gate for (valptr = rctltab->zone_rctl_valptr; valptr != NULL; 48487c478bd9Sstevel@tonic-gate valptr = valptr->zone_rctlval_next) { 48497c478bd9Sstevel@tonic-gate fprintf(fp, "\t%s: (%s=%s,%s=%s,%s=%s)\n", 48507c478bd9Sstevel@tonic-gate pt_to_str(PT_VALUE), 48517c478bd9Sstevel@tonic-gate pt_to_str(PT_PRIV), valptr->zone_rctlval_priv, 48527c478bd9Sstevel@tonic-gate pt_to_str(PT_LIMIT), valptr->zone_rctlval_limit, 48537c478bd9Sstevel@tonic-gate pt_to_str(PT_ACTION), valptr->zone_rctlval_action); 48547c478bd9Sstevel@tonic-gate } 48557c478bd9Sstevel@tonic-gate } 48567c478bd9Sstevel@tonic-gate 48577c478bd9Sstevel@tonic-gate static void 48587c478bd9Sstevel@tonic-gate info_rctl(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 48597c478bd9Sstevel@tonic-gate { 48607c478bd9Sstevel@tonic-gate struct zone_rctltab lookup, user; 4861bbec428eSgjelinek boolean_t output = B_FALSE; 48627c478bd9Sstevel@tonic-gate 48637c478bd9Sstevel@tonic-gate if (zonecfg_setrctlent(handle) != Z_OK) 48647c478bd9Sstevel@tonic-gate return; 48657c478bd9Sstevel@tonic-gate while (zonecfg_getrctlent(handle, &lookup) == Z_OK) { 48667c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) { 48677c478bd9Sstevel@tonic-gate output_rctl(fp, &lookup); 4868bbec428eSgjelinek } else if (fill_in_rctltab(cmd, &user, B_TRUE) == Z_OK && 48697c478bd9Sstevel@tonic-gate (strlen(user.zone_rctl_name) == 0 || 48707c478bd9Sstevel@tonic-gate strcmp(user.zone_rctl_name, lookup.zone_rctl_name) == 0)) { 48717c478bd9Sstevel@tonic-gate output_rctl(fp, &lookup); 4872bbec428eSgjelinek output = B_TRUE; 48737c478bd9Sstevel@tonic-gate } 48747c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(lookup.zone_rctl_valptr); 48757c478bd9Sstevel@tonic-gate } 48767c478bd9Sstevel@tonic-gate (void) zonecfg_endrctlent(handle); 48777c478bd9Sstevel@tonic-gate /* 48787c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was 48797c478bd9Sstevel@tonic-gate * nothing to output. 48807c478bd9Sstevel@tonic-gate */ 48817c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0) 48827c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"), 48837c478bd9Sstevel@tonic-gate rt_to_str(RT_RCTL)); 48847c478bd9Sstevel@tonic-gate } 48857c478bd9Sstevel@tonic-gate 48867c478bd9Sstevel@tonic-gate static void 48877c478bd9Sstevel@tonic-gate output_attr(FILE *fp, struct zone_attrtab *attrtab) 48887c478bd9Sstevel@tonic-gate { 48897c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%s:\n", rt_to_str(RT_ATTR)); 48907c478bd9Sstevel@tonic-gate output_prop(fp, PT_NAME, attrtab->zone_attr_name, B_TRUE); 48917c478bd9Sstevel@tonic-gate output_prop(fp, PT_TYPE, attrtab->zone_attr_type, B_TRUE); 48927c478bd9Sstevel@tonic-gate output_prop(fp, PT_VALUE, attrtab->zone_attr_value, B_TRUE); 48937c478bd9Sstevel@tonic-gate } 48947c478bd9Sstevel@tonic-gate 48957c478bd9Sstevel@tonic-gate static void 48967c478bd9Sstevel@tonic-gate info_attr(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 48977c478bd9Sstevel@tonic-gate { 48987c478bd9Sstevel@tonic-gate struct zone_attrtab lookup, user; 4899bbec428eSgjelinek boolean_t output = B_FALSE; 49007c478bd9Sstevel@tonic-gate 49017c478bd9Sstevel@tonic-gate if (zonecfg_setattrent(handle) != Z_OK) 49027c478bd9Sstevel@tonic-gate return; 49037c478bd9Sstevel@tonic-gate while (zonecfg_getattrent(handle, &lookup) == Z_OK) { 49047c478bd9Sstevel@tonic-gate if (cmd->cmd_prop_nv_pairs == 0) { 49057c478bd9Sstevel@tonic-gate output_attr(fp, &lookup); 49067c478bd9Sstevel@tonic-gate continue; 49077c478bd9Sstevel@tonic-gate } 4908bbec428eSgjelinek if (fill_in_attrtab(cmd, &user, B_TRUE) != Z_OK) 49097c478bd9Sstevel@tonic-gate continue; 49107c478bd9Sstevel@tonic-gate if (strlen(user.zone_attr_name) > 0 && 49117c478bd9Sstevel@tonic-gate strcmp(user.zone_attr_name, lookup.zone_attr_name) != 0) 49127c478bd9Sstevel@tonic-gate continue; /* no match */ 49137c478bd9Sstevel@tonic-gate if (strlen(user.zone_attr_type) > 0 && 49147c478bd9Sstevel@tonic-gate strcmp(user.zone_attr_type, lookup.zone_attr_type) != 0) 49157c478bd9Sstevel@tonic-gate continue; /* no match */ 49167c478bd9Sstevel@tonic-gate if (strlen(user.zone_attr_value) > 0 && 49177c478bd9Sstevel@tonic-gate strcmp(user.zone_attr_value, lookup.zone_attr_value) != 0) 49187c478bd9Sstevel@tonic-gate continue; /* no match */ 49197c478bd9Sstevel@tonic-gate output_attr(fp, &lookup); 4920bbec428eSgjelinek output = B_TRUE; 49217c478bd9Sstevel@tonic-gate } 49227c478bd9Sstevel@tonic-gate (void) zonecfg_endattrent(handle); 49237c478bd9Sstevel@tonic-gate /* 49247c478bd9Sstevel@tonic-gate * If a property n/v pair was specified, warn the user if there was 49257c478bd9Sstevel@tonic-gate * nothing to output. 49267c478bd9Sstevel@tonic-gate */ 49277c478bd9Sstevel@tonic-gate if (!output && cmd->cmd_prop_nv_pairs > 0) 49287c478bd9Sstevel@tonic-gate (void) printf(gettext("No such %s resource.\n"), 49297c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR)); 49307c478bd9Sstevel@tonic-gate } 49317c478bd9Sstevel@tonic-gate 4932fa9e4066Sahrens static void 4933fa9e4066Sahrens output_ds(FILE *fp, struct zone_dstab *dstab) 4934fa9e4066Sahrens { 4935fa9e4066Sahrens (void) fprintf(fp, "%s:\n", rt_to_str(RT_DATASET)); 4936fa9e4066Sahrens output_prop(fp, PT_NAME, dstab->zone_dataset_name, B_TRUE); 4937fa9e4066Sahrens } 4938fa9e4066Sahrens 4939fa9e4066Sahrens static void 4940fa9e4066Sahrens info_ds(zone_dochandle_t handle, FILE *fp, cmd_t *cmd) 4941fa9e4066Sahrens { 4942fa9e4066Sahrens struct zone_dstab lookup, user; 4943bbec428eSgjelinek boolean_t output = B_FALSE; 4944fa9e4066Sahrens 49450209230bSgjelinek if (zonecfg_setdsent(handle) != Z_OK) 4946fa9e4066Sahrens return; 4947fa9e4066Sahrens while (zonecfg_getdsent(handle, &lookup) == Z_OK) { 4948fa9e4066Sahrens if (cmd->cmd_prop_nv_pairs == 0) { 4949fa9e4066Sahrens output_ds(fp, &lookup); 4950fa9e4066Sahrens continue; 4951fa9e4066Sahrens } 4952bbec428eSgjelinek if (fill_in_dstab(cmd, &user, B_TRUE) != Z_OK) 4953fa9e4066Sahrens continue; 4954fa9e4066Sahrens if (strlen(user.zone_dataset_name) > 0 && 4955fa9e4066Sahrens strcmp(user.zone_dataset_name, 4956fa9e4066Sahrens lookup.zone_dataset_name) != 0) 4957fa9e4066Sahrens continue; /* no match */ 4958fa9e4066Sahrens output_ds(fp, &lookup); 4959bbec428eSgjelinek output = B_TRUE; 4960fa9e4066Sahrens } 4961fa9e4066Sahrens (void) zonecfg_enddsent(handle); 4962fa9e4066Sahrens /* 4963fa9e4066Sahrens * If a property n/v pair was specified, warn the user if there was 4964fa9e4066Sahrens * nothing to output. 4965fa9e4066Sahrens */ 4966fa9e4066Sahrens if (!output && cmd->cmd_prop_nv_pairs > 0) 4967fa9e4066Sahrens (void) printf(gettext("No such %s resource.\n"), 4968fa9e4066Sahrens rt_to_str(RT_DATASET)); 4969fa9e4066Sahrens } 4970fa9e4066Sahrens 49710209230bSgjelinek static void 49720209230bSgjelinek output_pset(FILE *fp, struct zone_psettab *psettab) 49730209230bSgjelinek { 49740209230bSgjelinek (void) fprintf(fp, "%s:\n", rt_to_str(RT_DCPU)); 49750209230bSgjelinek if (strcmp(psettab->zone_ncpu_min, psettab->zone_ncpu_max) == 0) 49760209230bSgjelinek (void) fprintf(fp, "\t%s: %s\n", pt_to_str(PT_NCPUS), 49770209230bSgjelinek psettab->zone_ncpu_max); 49780209230bSgjelinek else 49790209230bSgjelinek (void) fprintf(fp, "\t%s: %s-%s\n", pt_to_str(PT_NCPUS), 49800209230bSgjelinek psettab->zone_ncpu_min, psettab->zone_ncpu_max); 49810209230bSgjelinek if (psettab->zone_importance[0] != '\0') 49820209230bSgjelinek (void) fprintf(fp, "\t%s: %s\n", pt_to_str(PT_IMPORTANCE), 49830209230bSgjelinek psettab->zone_importance); 49840209230bSgjelinek } 49850209230bSgjelinek 49860209230bSgjelinek static void 49870209230bSgjelinek info_pset(zone_dochandle_t handle, FILE *fp) 49880209230bSgjelinek { 49890209230bSgjelinek struct zone_psettab lookup; 49900209230bSgjelinek 49910209230bSgjelinek if (zonecfg_getpsetent(handle, &lookup) == Z_OK) 49920209230bSgjelinek output_pset(fp, &lookup); 49930209230bSgjelinek } 49940209230bSgjelinek 49950209230bSgjelinek static void 4996c97ad5cdSakolb output_pcap(FILE *fp) 4997c97ad5cdSakolb { 4998c97ad5cdSakolb uint64_t cap; 4999c97ad5cdSakolb 5000c97ad5cdSakolb if (zonecfg_get_aliased_rctl(handle, ALIAS_CPUCAP, &cap) == Z_OK) { 5001c97ad5cdSakolb float scaled = (float)cap / 100; 5002c97ad5cdSakolb (void) fprintf(fp, "%s:\n", rt_to_str(RT_PCAP)); 5003c97ad5cdSakolb (void) fprintf(fp, "\t[%s: %.2f]\n", pt_to_str(PT_NCPUS), 5004c97ad5cdSakolb scaled); 5005c97ad5cdSakolb } 5006c97ad5cdSakolb } 5007c97ad5cdSakolb 5008c97ad5cdSakolb static void 5009c97ad5cdSakolb info_pcap(FILE *fp) 5010c97ad5cdSakolb { 5011c97ad5cdSakolb output_pcap(fp); 5012c97ad5cdSakolb } 5013c97ad5cdSakolb 5014c97ad5cdSakolb 5015c97ad5cdSakolb static void 50160209230bSgjelinek info_aliased_rctl(zone_dochandle_t handle, FILE *fp, char *alias) 50170209230bSgjelinek { 50180209230bSgjelinek uint64_t limit; 50190209230bSgjelinek 50200209230bSgjelinek if (zonecfg_get_aliased_rctl(handle, alias, &limit) == Z_OK) { 50210209230bSgjelinek /* convert memory based properties */ 50220209230bSgjelinek if (strcmp(alias, ALIAS_MAXSHMMEM) == 0) { 50230209230bSgjelinek char buf[128]; 50240209230bSgjelinek 50250209230bSgjelinek (void) snprintf(buf, sizeof (buf), "%llu", limit); 50260209230bSgjelinek bytes_to_units(buf, buf, sizeof (buf)); 50270209230bSgjelinek (void) fprintf(fp, "[%s: %s]\n", alias, buf); 50280209230bSgjelinek return; 50290209230bSgjelinek } 50300209230bSgjelinek 50310209230bSgjelinek (void) fprintf(fp, "[%s: %llu]\n", alias, limit); 50320209230bSgjelinek } 50330209230bSgjelinek } 50340209230bSgjelinek 50350209230bSgjelinek static void 50360209230bSgjelinek bytes_to_units(char *str, char *buf, int bufsize) 50370209230bSgjelinek { 50380209230bSgjelinek unsigned long long num; 50390209230bSgjelinek unsigned long long save = 0; 50400209230bSgjelinek char *units = "BKMGT"; 50410209230bSgjelinek char *up = units; 50420209230bSgjelinek 50430209230bSgjelinek num = strtoll(str, NULL, 10); 50440209230bSgjelinek 50450209230bSgjelinek if (num < 1024) { 50460209230bSgjelinek (void) snprintf(buf, bufsize, "%llu", num); 50470209230bSgjelinek return; 50480209230bSgjelinek } 50490209230bSgjelinek 50500209230bSgjelinek while ((num >= 1024) && (*up != 'T')) { 50510209230bSgjelinek up++; /* next unit of measurement */ 50520209230bSgjelinek save = num; 50530209230bSgjelinek num = (num + 512) >> 10; 50540209230bSgjelinek } 50550209230bSgjelinek 50560209230bSgjelinek /* check if we should output a fraction. snprintf will round for us */ 50570209230bSgjelinek if (save % 1024 != 0 && ((save >> 10) < 10)) 50580209230bSgjelinek (void) snprintf(buf, bufsize, "%2.1f%c", ((float)save / 1024), 50590209230bSgjelinek *up); 50600209230bSgjelinek else 50610209230bSgjelinek (void) snprintf(buf, bufsize, "%llu%c", num, *up); 50620209230bSgjelinek } 50630209230bSgjelinek 50640209230bSgjelinek static void 50650209230bSgjelinek output_mcap(FILE *fp, struct zone_mcaptab *mcaptab, int showswap, 50660209230bSgjelinek uint64_t maxswap, int showlocked, uint64_t maxlocked) 50670209230bSgjelinek { 50680209230bSgjelinek char buf[128]; 50690209230bSgjelinek 50700209230bSgjelinek (void) fprintf(fp, "%s:\n", rt_to_str(RT_MCAP)); 50710209230bSgjelinek if (mcaptab->zone_physmem_cap[0] != '\0') { 50720209230bSgjelinek bytes_to_units(mcaptab->zone_physmem_cap, buf, sizeof (buf)); 50730209230bSgjelinek output_prop(fp, PT_PHYSICAL, buf, B_TRUE); 50740209230bSgjelinek } 50750209230bSgjelinek 50760209230bSgjelinek if (showswap == Z_OK) { 50770209230bSgjelinek (void) snprintf(buf, sizeof (buf), "%llu", maxswap); 50780209230bSgjelinek bytes_to_units(buf, buf, sizeof (buf)); 50790209230bSgjelinek output_prop(fp, PT_SWAP, buf, B_TRUE); 50800209230bSgjelinek } 50810209230bSgjelinek 50820209230bSgjelinek if (showlocked == Z_OK) { 50830209230bSgjelinek (void) snprintf(buf, sizeof (buf), "%llu", maxlocked); 50840209230bSgjelinek bytes_to_units(buf, buf, sizeof (buf)); 50850209230bSgjelinek output_prop(fp, PT_LOCKED, buf, B_TRUE); 50860209230bSgjelinek } 50870209230bSgjelinek } 50880209230bSgjelinek 50890209230bSgjelinek static void 50900209230bSgjelinek info_mcap(zone_dochandle_t handle, FILE *fp) 50910209230bSgjelinek { 50920209230bSgjelinek int res1, res2, res3; 50930209230bSgjelinek uint64_t swap_limit; 50940209230bSgjelinek uint64_t locked_limit; 50950209230bSgjelinek struct zone_mcaptab lookup; 50960209230bSgjelinek 50970209230bSgjelinek bzero(&lookup, sizeof (lookup)); 50980209230bSgjelinek res1 = zonecfg_getmcapent(handle, &lookup); 50990209230bSgjelinek res2 = zonecfg_get_aliased_rctl(handle, ALIAS_MAXSWAP, &swap_limit); 51000209230bSgjelinek res3 = zonecfg_get_aliased_rctl(handle, ALIAS_MAXLOCKEDMEM, 51010209230bSgjelinek &locked_limit); 51020209230bSgjelinek 51030209230bSgjelinek if (res1 == Z_OK || res2 == Z_OK || res3 == Z_OK) 51040209230bSgjelinek output_mcap(fp, &lookup, res2, swap_limit, res3, locked_limit); 51050209230bSgjelinek } 51060209230bSgjelinek 51077c478bd9Sstevel@tonic-gate void 51087c478bd9Sstevel@tonic-gate info_func(cmd_t *cmd) 51097c478bd9Sstevel@tonic-gate { 51107c478bd9Sstevel@tonic-gate FILE *fp = stdout; 5111bbec428eSgjelinek boolean_t need_to_close = B_FALSE; 51127c478bd9Sstevel@tonic-gate char *pager; 51130209230bSgjelinek int type; 51140209230bSgjelinek int res1, res2; 51150209230bSgjelinek uint64_t swap_limit; 51160209230bSgjelinek uint64_t locked_limit; 51177c478bd9Sstevel@tonic-gate 51187c478bd9Sstevel@tonic-gate assert(cmd != NULL); 51197c478bd9Sstevel@tonic-gate 5120bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 51217c478bd9Sstevel@tonic-gate return; 51227c478bd9Sstevel@tonic-gate 51237c478bd9Sstevel@tonic-gate /* don't page error output */ 51247c478bd9Sstevel@tonic-gate if (interactive_mode) { 51257c478bd9Sstevel@tonic-gate if ((pager = getenv("PAGER")) == NULL) 51267c478bd9Sstevel@tonic-gate pager = PAGER; 51277c478bd9Sstevel@tonic-gate if ((fp = popen(pager, "w")) != NULL) 5128bbec428eSgjelinek need_to_close = B_TRUE; 51297c478bd9Sstevel@tonic-gate setbuf(fp, NULL); 51307c478bd9Sstevel@tonic-gate } 51317c478bd9Sstevel@tonic-gate 51327c478bd9Sstevel@tonic-gate if (!global_scope) { 51337c478bd9Sstevel@tonic-gate switch (resource_scope) { 51347c478bd9Sstevel@tonic-gate case RT_FS: 51357c478bd9Sstevel@tonic-gate output_fs(fp, &in_progress_fstab); 51367c478bd9Sstevel@tonic-gate break; 51377c478bd9Sstevel@tonic-gate case RT_IPD: 51387c478bd9Sstevel@tonic-gate output_ipd(fp, &in_progress_ipdtab); 51397c478bd9Sstevel@tonic-gate break; 51407c478bd9Sstevel@tonic-gate case RT_NET: 51417c478bd9Sstevel@tonic-gate output_net(fp, &in_progress_nwiftab); 51427c478bd9Sstevel@tonic-gate break; 51437c478bd9Sstevel@tonic-gate case RT_DEVICE: 51447c478bd9Sstevel@tonic-gate output_dev(fp, &in_progress_devtab); 51457c478bd9Sstevel@tonic-gate break; 51467c478bd9Sstevel@tonic-gate case RT_RCTL: 51477c478bd9Sstevel@tonic-gate output_rctl(fp, &in_progress_rctltab); 51487c478bd9Sstevel@tonic-gate break; 51497c478bd9Sstevel@tonic-gate case RT_ATTR: 51507c478bd9Sstevel@tonic-gate output_attr(fp, &in_progress_attrtab); 51517c478bd9Sstevel@tonic-gate break; 5152fa9e4066Sahrens case RT_DATASET: 5153fa9e4066Sahrens output_ds(fp, &in_progress_dstab); 5154fa9e4066Sahrens break; 51550209230bSgjelinek case RT_DCPU: 51560209230bSgjelinek output_pset(fp, &in_progress_psettab); 51570209230bSgjelinek break; 5158c97ad5cdSakolb case RT_PCAP: 5159c97ad5cdSakolb output_pcap(fp); 5160c97ad5cdSakolb break; 51610209230bSgjelinek case RT_MCAP: 51620209230bSgjelinek res1 = zonecfg_get_aliased_rctl(handle, ALIAS_MAXSWAP, 51630209230bSgjelinek &swap_limit); 51640209230bSgjelinek res2 = zonecfg_get_aliased_rctl(handle, 51650209230bSgjelinek ALIAS_MAXLOCKEDMEM, &locked_limit); 51660209230bSgjelinek output_mcap(fp, &in_progress_mcaptab, res1, swap_limit, 51670209230bSgjelinek res2, locked_limit); 51680209230bSgjelinek break; 51697c478bd9Sstevel@tonic-gate } 51707c478bd9Sstevel@tonic-gate goto cleanup; 51717c478bd9Sstevel@tonic-gate } 51727c478bd9Sstevel@tonic-gate 51730209230bSgjelinek type = cmd->cmd_res_type; 51740209230bSgjelinek 51750209230bSgjelinek if (gz_invalid_rt_property(type)) { 51760209230bSgjelinek zerr(gettext("%s is not a valid property for the global zone."), 51770209230bSgjelinek rt_to_str(type)); 51780209230bSgjelinek goto cleanup; 51790209230bSgjelinek } 51800209230bSgjelinek 51810209230bSgjelinek if (gz_invalid_resource(type)) { 51820209230bSgjelinek zerr(gettext("%s is not a valid resource for the global zone."), 51830209230bSgjelinek rt_to_str(type)); 51840209230bSgjelinek goto cleanup; 51850209230bSgjelinek } 51860209230bSgjelinek 51877c478bd9Sstevel@tonic-gate switch (cmd->cmd_res_type) { 51887c478bd9Sstevel@tonic-gate case RT_UNKNOWN: 5189087719fdSdp info_zonename(handle, fp); 51900209230bSgjelinek if (!global_zone) { 51917c478bd9Sstevel@tonic-gate info_zonepath(handle, fp); 51929acbbeafSnn35248 info_brand(handle, fp); 51937c478bd9Sstevel@tonic-gate info_autoboot(handle, fp); 51943f2f09c1Sdp info_bootargs(handle, fp); 51950209230bSgjelinek } 51967c478bd9Sstevel@tonic-gate info_pool(handle, fp); 51970209230bSgjelinek if (!global_zone) { 5198ffbafc53Scomay info_limitpriv(handle, fp); 51990209230bSgjelinek info_sched(handle, fp); 5200f4b3ec61Sdh155122 info_iptype(handle, fp); 52010209230bSgjelinek } 52020209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXLWPS); 52030209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXSHMMEM); 52040209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXSHMIDS); 52050209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXMSGIDS); 52060209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXSEMIDS); 52070209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_SHARES); 52080209230bSgjelinek if (!global_zone) { 52097c478bd9Sstevel@tonic-gate info_ipd(handle, fp, cmd); 52107c478bd9Sstevel@tonic-gate info_fs(handle, fp, cmd); 52117c478bd9Sstevel@tonic-gate info_net(handle, fp, cmd); 52127c478bd9Sstevel@tonic-gate info_dev(handle, fp, cmd); 52130209230bSgjelinek } 52140209230bSgjelinek info_pset(handle, fp); 5215c97ad5cdSakolb info_pcap(fp); 52160209230bSgjelinek info_mcap(handle, fp); 52170209230bSgjelinek if (!global_zone) { 52187c478bd9Sstevel@tonic-gate info_attr(handle, fp, cmd); 5219fa9e4066Sahrens info_ds(handle, fp, cmd); 52200209230bSgjelinek } 52210209230bSgjelinek info_rctl(handle, fp, cmd); 52227c478bd9Sstevel@tonic-gate break; 5223087719fdSdp case RT_ZONENAME: 5224087719fdSdp info_zonename(handle, fp); 5225087719fdSdp break; 52267c478bd9Sstevel@tonic-gate case RT_ZONEPATH: 52277c478bd9Sstevel@tonic-gate info_zonepath(handle, fp); 52287c478bd9Sstevel@tonic-gate break; 52299acbbeafSnn35248 case RT_BRAND: 52309acbbeafSnn35248 info_brand(handle, fp); 52319acbbeafSnn35248 break; 52327c478bd9Sstevel@tonic-gate case RT_AUTOBOOT: 52337c478bd9Sstevel@tonic-gate info_autoboot(handle, fp); 52347c478bd9Sstevel@tonic-gate break; 52357c478bd9Sstevel@tonic-gate case RT_POOL: 52367c478bd9Sstevel@tonic-gate info_pool(handle, fp); 52377c478bd9Sstevel@tonic-gate break; 5238ffbafc53Scomay case RT_LIMITPRIV: 5239ffbafc53Scomay info_limitpriv(handle, fp); 5240ffbafc53Scomay break; 52413f2f09c1Sdp case RT_BOOTARGS: 52423f2f09c1Sdp info_bootargs(handle, fp); 52433f2f09c1Sdp break; 52440209230bSgjelinek case RT_SCHED: 52450209230bSgjelinek info_sched(handle, fp); 52460209230bSgjelinek break; 5247f4b3ec61Sdh155122 case RT_IPTYPE: 5248f4b3ec61Sdh155122 info_iptype(handle, fp); 5249f4b3ec61Sdh155122 break; 52500209230bSgjelinek case RT_MAXLWPS: 52510209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXLWPS); 52520209230bSgjelinek break; 52530209230bSgjelinek case RT_MAXSHMMEM: 52540209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXSHMMEM); 52550209230bSgjelinek break; 52560209230bSgjelinek case RT_MAXSHMIDS: 52570209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXSHMIDS); 52580209230bSgjelinek break; 52590209230bSgjelinek case RT_MAXMSGIDS: 52600209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXMSGIDS); 52610209230bSgjelinek break; 52620209230bSgjelinek case RT_MAXSEMIDS: 52630209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_MAXSEMIDS); 52640209230bSgjelinek break; 52650209230bSgjelinek case RT_SHARES: 52660209230bSgjelinek info_aliased_rctl(handle, fp, ALIAS_SHARES); 52670209230bSgjelinek break; 52687c478bd9Sstevel@tonic-gate case RT_FS: 52697c478bd9Sstevel@tonic-gate info_fs(handle, fp, cmd); 52707c478bd9Sstevel@tonic-gate break; 52717c478bd9Sstevel@tonic-gate case RT_IPD: 52727c478bd9Sstevel@tonic-gate info_ipd(handle, fp, cmd); 52737c478bd9Sstevel@tonic-gate break; 52747c478bd9Sstevel@tonic-gate case RT_NET: 52757c478bd9Sstevel@tonic-gate info_net(handle, fp, cmd); 52767c478bd9Sstevel@tonic-gate break; 52777c478bd9Sstevel@tonic-gate case RT_DEVICE: 52787c478bd9Sstevel@tonic-gate info_dev(handle, fp, cmd); 52797c478bd9Sstevel@tonic-gate break; 52807c478bd9Sstevel@tonic-gate case RT_RCTL: 52817c478bd9Sstevel@tonic-gate info_rctl(handle, fp, cmd); 52827c478bd9Sstevel@tonic-gate break; 52837c478bd9Sstevel@tonic-gate case RT_ATTR: 52847c478bd9Sstevel@tonic-gate info_attr(handle, fp, cmd); 52857c478bd9Sstevel@tonic-gate break; 5286fa9e4066Sahrens case RT_DATASET: 5287fa9e4066Sahrens info_ds(handle, fp, cmd); 5288fa9e4066Sahrens break; 52890209230bSgjelinek case RT_DCPU: 52900209230bSgjelinek info_pset(handle, fp); 52910209230bSgjelinek break; 5292c97ad5cdSakolb case RT_PCAP: 5293c97ad5cdSakolb info_pcap(fp); 5294c97ad5cdSakolb break; 52950209230bSgjelinek case RT_MCAP: 52960209230bSgjelinek info_mcap(handle, fp); 52970209230bSgjelinek break; 52987c478bd9Sstevel@tonic-gate default: 52997c478bd9Sstevel@tonic-gate zone_perror(rt_to_str(cmd->cmd_res_type), Z_NO_RESOURCE_TYPE, 5300bbec428eSgjelinek B_TRUE); 53017c478bd9Sstevel@tonic-gate } 53027c478bd9Sstevel@tonic-gate 53037c478bd9Sstevel@tonic-gate cleanup: 53047c478bd9Sstevel@tonic-gate if (need_to_close) 53057c478bd9Sstevel@tonic-gate (void) pclose(fp); 53067c478bd9Sstevel@tonic-gate } 53077c478bd9Sstevel@tonic-gate 5308087719fdSdp /* 5309087719fdSdp * Helper function for verify-- checks that a required string property 5310087719fdSdp * exists. 5311087719fdSdp */ 5312087719fdSdp static void 5313087719fdSdp check_reqd_prop(char *attr, int rt, int pt, int *ret_val) 53147c478bd9Sstevel@tonic-gate { 5315087719fdSdp if (strlen(attr) == 0) { 5316087719fdSdp zerr(gettext("%s: %s not specified"), rt_to_str(rt), 5317087719fdSdp pt_to_str(pt)); 5318bbec428eSgjelinek saw_error = B_TRUE; 5319087719fdSdp if (*ret_val == Z_OK) 5320087719fdSdp *ret_val = Z_REQD_PROPERTY_MISSING; 53217c478bd9Sstevel@tonic-gate } 53227c478bd9Sstevel@tonic-gate } 53237c478bd9Sstevel@tonic-gate 53249acbbeafSnn35248 static int 53259acbbeafSnn35248 do_subproc(char *cmdbuf) 53269acbbeafSnn35248 { 53279acbbeafSnn35248 char inbuf[MAX_CMD_LEN]; 53289acbbeafSnn35248 FILE *file; 53299acbbeafSnn35248 int status; 53309acbbeafSnn35248 53319acbbeafSnn35248 file = popen(cmdbuf, "r"); 53329acbbeafSnn35248 if (file == NULL) { 53339acbbeafSnn35248 zerr(gettext("Could not launch: %s"), cmdbuf); 53349acbbeafSnn35248 return (-1); 53359acbbeafSnn35248 } 53369acbbeafSnn35248 53379acbbeafSnn35248 while (fgets(inbuf, sizeof (inbuf), file) != NULL) 53389acbbeafSnn35248 fprintf(stderr, "%s", inbuf); 53399acbbeafSnn35248 status = pclose(file); 53409acbbeafSnn35248 53419acbbeafSnn35248 if (WIFSIGNALED(status)) { 53429acbbeafSnn35248 zerr(gettext("%s unexpectedly terminated due to signal %d"), 53439acbbeafSnn35248 cmdbuf, WTERMSIG(status)); 53449acbbeafSnn35248 return (-1); 53459acbbeafSnn35248 } 53469acbbeafSnn35248 assert(WIFEXITED(status)); 53479acbbeafSnn35248 return (WEXITSTATUS(status)); 53489acbbeafSnn35248 } 53499acbbeafSnn35248 53509acbbeafSnn35248 static int 53519acbbeafSnn35248 brand_verify(zone_dochandle_t handle) 53529acbbeafSnn35248 { 53536e65f9afSnn35248 char xml_file[32]; 53549acbbeafSnn35248 char cmdbuf[MAX_CMD_LEN]; 5355123807fbSedp brand_handle_t bh; 53569acbbeafSnn35248 char brand[MAXNAMELEN]; 53579acbbeafSnn35248 int err; 53589acbbeafSnn35248 53599acbbeafSnn35248 if (zonecfg_get_brand(handle, brand, sizeof (brand)) != Z_OK) { 53609acbbeafSnn35248 zerr("%s: %s\n", zone, gettext("could not get zone brand")); 53619acbbeafSnn35248 return (Z_INVALID_DOCUMENT); 53629acbbeafSnn35248 } 5363123807fbSedp if ((bh = brand_open(brand)) == NULL) { 53649acbbeafSnn35248 zerr("%s: %s\n", zone, gettext("unknown brand.")); 53659acbbeafSnn35248 return (Z_INVALID_DOCUMENT); 53669acbbeafSnn35248 } 53679acbbeafSnn35248 53689acbbeafSnn35248 /* 53699acbbeafSnn35248 * Fetch the verify command, if any, from the brand configuration 53709acbbeafSnn35248 * and build the command line to execute it. 53719acbbeafSnn35248 */ 53729acbbeafSnn35248 strcpy(cmdbuf, EXEC_PREFIX); 5373123807fbSedp err = brand_get_verify_cfg(bh, cmdbuf + EXEC_LEN, 53749acbbeafSnn35248 sizeof (cmdbuf) - (EXEC_LEN + (strlen(xml_file) + 1))); 5375123807fbSedp brand_close(bh); 53769acbbeafSnn35248 if (err != Z_OK) { 53779acbbeafSnn35248 zerr("%s: %s\n", zone, 53789acbbeafSnn35248 gettext("could not get brand verification command")); 53799acbbeafSnn35248 return (Z_INVALID_DOCUMENT); 53809acbbeafSnn35248 } 53819acbbeafSnn35248 53829acbbeafSnn35248 /* 53839acbbeafSnn35248 * If the brand doesn't provide a verification routine, we just 53849acbbeafSnn35248 * return success. 53859acbbeafSnn35248 */ 53869acbbeafSnn35248 if (strlen(cmdbuf) == EXEC_LEN) 53879acbbeafSnn35248 return (Z_OK); 53889acbbeafSnn35248 53899acbbeafSnn35248 /* 53909acbbeafSnn35248 * Dump the current config information for this zone to a file. 53919acbbeafSnn35248 */ 53926e65f9afSnn35248 strcpy(xml_file, "/tmp/zonecfg_verify.XXXXXX"); 53939acbbeafSnn35248 if (mkstemp(xml_file) == NULL) 53949acbbeafSnn35248 return (Z_TEMP_FILE); 53959acbbeafSnn35248 if ((err = zonecfg_verify_save(handle, xml_file)) != Z_OK) { 53969acbbeafSnn35248 (void) unlink(xml_file); 53979acbbeafSnn35248 return (err); 53989acbbeafSnn35248 } 53999acbbeafSnn35248 54009acbbeafSnn35248 /* 54019acbbeafSnn35248 * Execute the verification command. 54029acbbeafSnn35248 */ 54039acbbeafSnn35248 if ((strlcat(cmdbuf, " ", MAX_CMD_LEN) >= MAX_CMD_LEN) || 54049acbbeafSnn35248 (strlcat(cmdbuf, xml_file, MAX_CMD_LEN) >= MAX_CMD_LEN)) { 54059acbbeafSnn35248 err = Z_BRAND_ERROR; 54069acbbeafSnn35248 } else { 54079acbbeafSnn35248 err = do_subproc(cmdbuf); 54089acbbeafSnn35248 } 54099acbbeafSnn35248 54109acbbeafSnn35248 (void) unlink(xml_file); 54119acbbeafSnn35248 return ((err == Z_OK) ? Z_OK : Z_BRAND_ERROR); 54129acbbeafSnn35248 } 54139acbbeafSnn35248 54147c478bd9Sstevel@tonic-gate /* 54157c478bd9Sstevel@tonic-gate * See the DTD for which attributes are required for which resources. 54167c478bd9Sstevel@tonic-gate * 54177c478bd9Sstevel@tonic-gate * This function can be called by commit_func(), which needs to save things, 54187c478bd9Sstevel@tonic-gate * in addition to the general call from parse_and_run(), which doesn't need 54197c478bd9Sstevel@tonic-gate * things saved. Since the parameters are standardized, we distinguish by 54207c478bd9Sstevel@tonic-gate * having commit_func() call here with cmd->cmd_arg set to "save" to indicate 54217c478bd9Sstevel@tonic-gate * that a save is needed. 54227c478bd9Sstevel@tonic-gate */ 54237c478bd9Sstevel@tonic-gate void 54247c478bd9Sstevel@tonic-gate verify_func(cmd_t *cmd) 54257c478bd9Sstevel@tonic-gate { 54267c478bd9Sstevel@tonic-gate struct zone_nwiftab nwiftab; 54277c478bd9Sstevel@tonic-gate struct zone_fstab fstab; 54287c478bd9Sstevel@tonic-gate struct zone_attrtab attrtab; 54297c478bd9Sstevel@tonic-gate struct zone_rctltab rctltab; 5430fa9e4066Sahrens struct zone_dstab dstab; 54310209230bSgjelinek struct zone_psettab psettab; 54327c478bd9Sstevel@tonic-gate char zonepath[MAXPATHLEN]; 54330209230bSgjelinek char sched[MAXNAMELEN]; 54349acbbeafSnn35248 char brand[MAXNAMELEN]; 54357c478bd9Sstevel@tonic-gate int err, ret_val = Z_OK, arg; 5436c97ad5cdSakolb int pset_res; 5437bbec428eSgjelinek boolean_t save = B_FALSE; 5438bbec428eSgjelinek boolean_t arg_err = B_FALSE; 5439f4b3ec61Sdh155122 zone_iptype_t iptype; 54400209230bSgjelinek boolean_t has_cpu_shares = B_FALSE; 5441c97ad5cdSakolb boolean_t has_cpu_cap = B_FALSE; 54427c478bd9Sstevel@tonic-gate 54437c478bd9Sstevel@tonic-gate optind = 0; 54447ec75eb8Sgjelinek while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?")) != EOF) { 54457c478bd9Sstevel@tonic-gate switch (arg) { 54467c478bd9Sstevel@tonic-gate case '?': 54477c478bd9Sstevel@tonic-gate longer_usage(CMD_VERIFY); 5448bbec428eSgjelinek arg_err = B_TRUE; 54497ec75eb8Sgjelinek break; 54507c478bd9Sstevel@tonic-gate default: 54517c478bd9Sstevel@tonic-gate short_usage(CMD_VERIFY); 5452bbec428eSgjelinek arg_err = B_TRUE; 54537ec75eb8Sgjelinek break; 54547ec75eb8Sgjelinek } 54557ec75eb8Sgjelinek } 54567ec75eb8Sgjelinek if (arg_err) 54577c478bd9Sstevel@tonic-gate return; 54587ec75eb8Sgjelinek 54597c478bd9Sstevel@tonic-gate if (optind > cmd->cmd_argc) { 54607c478bd9Sstevel@tonic-gate short_usage(CMD_VERIFY); 54617c478bd9Sstevel@tonic-gate return; 54627c478bd9Sstevel@tonic-gate } 54637c478bd9Sstevel@tonic-gate 54647c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_VERIFY)) 54657c478bd9Sstevel@tonic-gate return; 54667c478bd9Sstevel@tonic-gate 54677c478bd9Sstevel@tonic-gate assert(cmd != NULL); 54687c478bd9Sstevel@tonic-gate 54697c478bd9Sstevel@tonic-gate if (cmd->cmd_argc > 0 && (strcmp(cmd->cmd_argv[0], "save") == 0)) 5470bbec428eSgjelinek save = B_TRUE; 5471bbec428eSgjelinek if (initialize(B_TRUE) != Z_OK) 54727c478bd9Sstevel@tonic-gate return; 54737c478bd9Sstevel@tonic-gate 54740209230bSgjelinek if (zonecfg_get_zonepath(handle, zonepath, sizeof (zonepath)) != Z_OK && 54750209230bSgjelinek !global_zone) { 5476087719fdSdp zerr(gettext("%s not specified"), pt_to_str(PT_ZONEPATH)); 54777c478bd9Sstevel@tonic-gate ret_val = Z_REQD_RESOURCE_MISSING; 5478bbec428eSgjelinek saw_error = B_TRUE; 54797c478bd9Sstevel@tonic-gate } 54800209230bSgjelinek if (strlen(zonepath) == 0 && !global_zone) { 5481087719fdSdp zerr(gettext("%s cannot be empty."), pt_to_str(PT_ZONEPATH)); 54827c478bd9Sstevel@tonic-gate ret_val = Z_REQD_RESOURCE_MISSING; 5483bbec428eSgjelinek saw_error = B_TRUE; 54847c478bd9Sstevel@tonic-gate } 54857c478bd9Sstevel@tonic-gate 54869acbbeafSnn35248 if ((err = zonecfg_get_brand(handle, brand, sizeof (brand))) != Z_OK) { 5487bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 54889acbbeafSnn35248 return; 54899acbbeafSnn35248 } 54909acbbeafSnn35248 if (strcmp(brand, NATIVE_BRAND_NAME) != 0) { 54919acbbeafSnn35248 if ((err = brand_verify(handle)) != Z_OK) { 5492bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 54939acbbeafSnn35248 return; 54949acbbeafSnn35248 } 54959acbbeafSnn35248 } 54969acbbeafSnn35248 5497f4b3ec61Sdh155122 if (zonecfg_get_iptype(handle, &iptype) != Z_OK) { 5498f4b3ec61Sdh155122 zerr("%s %s", gettext("cannot get"), pt_to_str(PT_IPTYPE)); 5499f4b3ec61Sdh155122 ret_val = Z_REQD_RESOURCE_MISSING; 5500bbec428eSgjelinek saw_error = B_TRUE; 5501f4b3ec61Sdh155122 } 55027c478bd9Sstevel@tonic-gate if ((err = zonecfg_setipdent(handle)) != Z_OK) { 5503bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 55047c478bd9Sstevel@tonic-gate return; 55057c478bd9Sstevel@tonic-gate } 55067c478bd9Sstevel@tonic-gate while (zonecfg_getipdent(handle, &fstab) == Z_OK) { 5507087719fdSdp check_reqd_prop(fstab.zone_fs_dir, RT_IPD, PT_DIR, &ret_val); 55087c478bd9Sstevel@tonic-gate } 55097c478bd9Sstevel@tonic-gate (void) zonecfg_endipdent(handle); 55107c478bd9Sstevel@tonic-gate 55117c478bd9Sstevel@tonic-gate if ((err = zonecfg_setfsent(handle)) != Z_OK) { 5512bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 55137c478bd9Sstevel@tonic-gate return; 55147c478bd9Sstevel@tonic-gate } 55157c478bd9Sstevel@tonic-gate while (zonecfg_getfsent(handle, &fstab) == Z_OK) { 5516087719fdSdp check_reqd_prop(fstab.zone_fs_dir, RT_FS, PT_DIR, &ret_val); 5517087719fdSdp check_reqd_prop(fstab.zone_fs_special, RT_FS, PT_SPECIAL, 5518087719fdSdp &ret_val); 5519087719fdSdp check_reqd_prop(fstab.zone_fs_type, RT_FS, PT_TYPE, &ret_val); 5520087719fdSdp 55217c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(fstab.zone_fs_options); 55227c478bd9Sstevel@tonic-gate } 55237c478bd9Sstevel@tonic-gate (void) zonecfg_endfsent(handle); 55247c478bd9Sstevel@tonic-gate 55257c478bd9Sstevel@tonic-gate if ((err = zonecfg_setnwifent(handle)) != Z_OK) { 5526bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 55277c478bd9Sstevel@tonic-gate return; 55287c478bd9Sstevel@tonic-gate } 55297c478bd9Sstevel@tonic-gate while (zonecfg_getnwifent(handle, &nwiftab) == Z_OK) { 5530f4b3ec61Sdh155122 /* 5531f4b3ec61Sdh155122 * physical is required in all cases. 5532de860bd9Sgfaden * A shared IP requires an address, 5533de860bd9Sgfaden * and may include a default router, while 5534de860bd9Sgfaden * an exclusive IP must have neither an address 5535de860bd9Sgfaden * nor a default router. 5536f4b3ec61Sdh155122 */ 5537087719fdSdp check_reqd_prop(nwiftab.zone_nwif_physical, RT_NET, 5538087719fdSdp PT_PHYSICAL, &ret_val); 5539f4b3ec61Sdh155122 5540f4b3ec61Sdh155122 switch (iptype) { 5541f4b3ec61Sdh155122 case ZS_SHARED: 5542f4b3ec61Sdh155122 check_reqd_prop(nwiftab.zone_nwif_address, RT_NET, 5543f4b3ec61Sdh155122 PT_ADDRESS, &ret_val); 5544f4b3ec61Sdh155122 break; 5545f4b3ec61Sdh155122 case ZS_EXCLUSIVE: 5546f4b3ec61Sdh155122 if (strlen(nwiftab.zone_nwif_address) > 0) { 5547f4b3ec61Sdh155122 zerr(gettext("%s: %s cannot be specified " 5548f4b3ec61Sdh155122 "for an exclusive IP type"), 5549f4b3ec61Sdh155122 rt_to_str(RT_NET), pt_to_str(PT_ADDRESS)); 5550bbec428eSgjelinek saw_error = B_TRUE; 5551f4b3ec61Sdh155122 if (ret_val == Z_OK) 5552f4b3ec61Sdh155122 ret_val = Z_INVAL; 5553f4b3ec61Sdh155122 } 5554de860bd9Sgfaden if (strlen(nwiftab.zone_nwif_defrouter) > 0) { 5555de860bd9Sgfaden zerr(gettext("%s: %s cannot be specified " 5556de860bd9Sgfaden "for an exclusive IP type"), 5557de860bd9Sgfaden rt_to_str(RT_NET), pt_to_str(PT_DEFROUTER)); 5558bbec428eSgjelinek saw_error = B_TRUE; 5559de860bd9Sgfaden if (ret_val == Z_OK) 5560de860bd9Sgfaden ret_val = Z_INVAL; 5561de860bd9Sgfaden } 5562f4b3ec61Sdh155122 break; 5563f4b3ec61Sdh155122 } 55647c478bd9Sstevel@tonic-gate } 55657c478bd9Sstevel@tonic-gate (void) zonecfg_endnwifent(handle); 55667c478bd9Sstevel@tonic-gate 55677c478bd9Sstevel@tonic-gate if ((err = zonecfg_setrctlent(handle)) != Z_OK) { 5568bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 55697c478bd9Sstevel@tonic-gate return; 55707c478bd9Sstevel@tonic-gate } 55717c478bd9Sstevel@tonic-gate while (zonecfg_getrctlent(handle, &rctltab) == Z_OK) { 5572087719fdSdp check_reqd_prop(rctltab.zone_rctl_name, RT_RCTL, PT_NAME, 5573087719fdSdp &ret_val); 5574087719fdSdp 55750209230bSgjelinek if (strcmp(rctltab.zone_rctl_name, "zone.cpu-shares") == 0) 55760209230bSgjelinek has_cpu_shares = B_TRUE; 55770209230bSgjelinek 5578c97ad5cdSakolb if (strcmp(rctltab.zone_rctl_name, "zone.cpu-cap") == 0) 5579c97ad5cdSakolb has_cpu_cap = B_TRUE; 5580c97ad5cdSakolb 55817c478bd9Sstevel@tonic-gate if (rctltab.zone_rctl_valptr == NULL) { 55827c478bd9Sstevel@tonic-gate zerr(gettext("%s: no %s specified"), 55837c478bd9Sstevel@tonic-gate rt_to_str(RT_RCTL), pt_to_str(PT_VALUE)); 5584bbec428eSgjelinek saw_error = B_TRUE; 55857c478bd9Sstevel@tonic-gate if (ret_val == Z_OK) 55867c478bd9Sstevel@tonic-gate ret_val = Z_REQD_PROPERTY_MISSING; 55877c478bd9Sstevel@tonic-gate } else { 55887c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(rctltab.zone_rctl_valptr); 55897c478bd9Sstevel@tonic-gate } 55907c478bd9Sstevel@tonic-gate } 55917c478bd9Sstevel@tonic-gate (void) zonecfg_endrctlent(handle); 55927c478bd9Sstevel@tonic-gate 5593c97ad5cdSakolb if ((pset_res = zonecfg_lookup_pset(handle, &psettab)) == Z_OK && 5594c97ad5cdSakolb has_cpu_shares) { 55950209230bSgjelinek zerr(gettext("%s zone.cpu-shares and %s are incompatible."), 55960209230bSgjelinek rt_to_str(RT_RCTL), rt_to_str(RT_DCPU)); 5597bbec428eSgjelinek saw_error = B_TRUE; 55980209230bSgjelinek if (ret_val == Z_OK) 55990209230bSgjelinek ret_val = Z_INCOMPATIBLE; 56000209230bSgjelinek } 56010209230bSgjelinek 56020209230bSgjelinek if (has_cpu_shares && zonecfg_get_sched_class(handle, sched, 56030209230bSgjelinek sizeof (sched)) == Z_OK && strlen(sched) > 0 && 56040209230bSgjelinek strcmp(sched, "FSS") != 0) { 56050209230bSgjelinek zerr(gettext("WARNING: %s zone.cpu-shares and %s=%s are " 56060209230bSgjelinek "incompatible"), 56070209230bSgjelinek rt_to_str(RT_RCTL), rt_to_str(RT_SCHED), sched); 5608bbec428eSgjelinek saw_error = B_TRUE; 56090209230bSgjelinek if (ret_val == Z_OK) 56100209230bSgjelinek ret_val = Z_INCOMPATIBLE; 56110209230bSgjelinek } 56120209230bSgjelinek 5613c97ad5cdSakolb if (pset_res == Z_OK && has_cpu_cap) { 5614c97ad5cdSakolb zerr(gettext("%s zone.cpu-cap and the %s are incompatible."), 5615c97ad5cdSakolb rt_to_str(RT_RCTL), rt_to_str(RT_DCPU)); 5616bbec428eSgjelinek saw_error = B_TRUE; 5617c97ad5cdSakolb if (ret_val == Z_OK) 5618c97ad5cdSakolb ret_val = Z_INCOMPATIBLE; 5619c97ad5cdSakolb } 5620c97ad5cdSakolb 56217c478bd9Sstevel@tonic-gate if ((err = zonecfg_setattrent(handle)) != Z_OK) { 5622bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 56237c478bd9Sstevel@tonic-gate return; 56247c478bd9Sstevel@tonic-gate } 56257c478bd9Sstevel@tonic-gate while (zonecfg_getattrent(handle, &attrtab) == Z_OK) { 5626087719fdSdp check_reqd_prop(attrtab.zone_attr_name, RT_ATTR, PT_NAME, 5627087719fdSdp &ret_val); 5628087719fdSdp check_reqd_prop(attrtab.zone_attr_type, RT_ATTR, PT_TYPE, 5629087719fdSdp &ret_val); 5630087719fdSdp check_reqd_prop(attrtab.zone_attr_value, RT_ATTR, PT_VALUE, 5631087719fdSdp &ret_val); 56327c478bd9Sstevel@tonic-gate } 56337c478bd9Sstevel@tonic-gate (void) zonecfg_endattrent(handle); 56347c478bd9Sstevel@tonic-gate 5635fa9e4066Sahrens if ((err = zonecfg_setdsent(handle)) != Z_OK) { 5636bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 5637fa9e4066Sahrens return; 5638fa9e4066Sahrens } 5639fa9e4066Sahrens while (zonecfg_getdsent(handle, &dstab) == Z_OK) { 5640fa9e4066Sahrens if (strlen(dstab.zone_dataset_name) == 0) { 5641fa9e4066Sahrens zerr("%s: %s %s", rt_to_str(RT_DATASET), 5642fa9e4066Sahrens pt_to_str(PT_NAME), gettext("not specified")); 5643bbec428eSgjelinek saw_error = B_TRUE; 5644fa9e4066Sahrens if (ret_val == Z_OK) 5645fa9e4066Sahrens ret_val = Z_REQD_PROPERTY_MISSING; 5646fa9e4066Sahrens } else if (!zfs_name_valid(dstab.zone_dataset_name, 5647fa9e4066Sahrens ZFS_TYPE_FILESYSTEM)) { 5648fa9e4066Sahrens zerr("%s: %s %s", rt_to_str(RT_DATASET), 5649fa9e4066Sahrens pt_to_str(PT_NAME), gettext("invalid")); 5650bbec428eSgjelinek saw_error = B_TRUE; 5651fa9e4066Sahrens if (ret_val == Z_OK) 5652fa9e4066Sahrens ret_val = Z_BAD_PROPERTY; 5653fa9e4066Sahrens } 5654fa9e4066Sahrens 5655fa9e4066Sahrens } 5656fa9e4066Sahrens (void) zonecfg_enddsent(handle); 5657fa9e4066Sahrens 56587c478bd9Sstevel@tonic-gate if (!global_scope) { 56597c478bd9Sstevel@tonic-gate zerr(gettext("resource specification incomplete")); 5660bbec428eSgjelinek saw_error = B_TRUE; 56617c478bd9Sstevel@tonic-gate if (ret_val == Z_OK) 56627c478bd9Sstevel@tonic-gate ret_val = Z_INSUFFICIENT_SPEC; 56637c478bd9Sstevel@tonic-gate } 56647c478bd9Sstevel@tonic-gate 56657c478bd9Sstevel@tonic-gate if (save) { 5666087719fdSdp if (ret_val == Z_OK) { 5667087719fdSdp if ((ret_val = zonecfg_save(handle)) == Z_OK) { 5668bbec428eSgjelinek need_to_commit = B_FALSE; 5669087719fdSdp (void) strlcpy(revert_zone, zone, 5670087719fdSdp sizeof (revert_zone)); 5671087719fdSdp } 5672087719fdSdp } else { 5673087719fdSdp zerr(gettext("Zone %s failed to verify"), zone); 5674087719fdSdp } 56757c478bd9Sstevel@tonic-gate } 56767c478bd9Sstevel@tonic-gate if (ret_val != Z_OK) 5677bbec428eSgjelinek zone_perror(zone, ret_val, B_TRUE); 56787c478bd9Sstevel@tonic-gate } 56797c478bd9Sstevel@tonic-gate 56807c478bd9Sstevel@tonic-gate void 56817c478bd9Sstevel@tonic-gate cancel_func(cmd_t *cmd) 56827c478bd9Sstevel@tonic-gate { 56837c478bd9Sstevel@tonic-gate int arg; 5684bbec428eSgjelinek boolean_t arg_err = B_FALSE; 56857c478bd9Sstevel@tonic-gate 56867c478bd9Sstevel@tonic-gate assert(cmd != NULL); 56877c478bd9Sstevel@tonic-gate 56887c478bd9Sstevel@tonic-gate optind = 0; 56897ec75eb8Sgjelinek while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?")) != EOF) { 56907c478bd9Sstevel@tonic-gate switch (arg) { 56917c478bd9Sstevel@tonic-gate case '?': 56927c478bd9Sstevel@tonic-gate longer_usage(CMD_CANCEL); 5693bbec428eSgjelinek arg_err = B_TRUE; 56947ec75eb8Sgjelinek break; 56957c478bd9Sstevel@tonic-gate default: 56967c478bd9Sstevel@tonic-gate short_usage(CMD_CANCEL); 5697bbec428eSgjelinek arg_err = B_TRUE; 56987ec75eb8Sgjelinek break; 56997ec75eb8Sgjelinek } 57007ec75eb8Sgjelinek } 57017ec75eb8Sgjelinek if (arg_err) 57027c478bd9Sstevel@tonic-gate return; 57037ec75eb8Sgjelinek 57047c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 57057c478bd9Sstevel@tonic-gate short_usage(CMD_CANCEL); 57067c478bd9Sstevel@tonic-gate return; 57077c478bd9Sstevel@tonic-gate } 57087c478bd9Sstevel@tonic-gate 57097c478bd9Sstevel@tonic-gate if (global_scope) 57107c478bd9Sstevel@tonic-gate scope_usage(CMD_CANCEL); 5711bbec428eSgjelinek global_scope = B_TRUE; 57127c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(in_progress_fstab.zone_fs_options); 57137c478bd9Sstevel@tonic-gate bzero(&in_progress_fstab, sizeof (in_progress_fstab)); 57147c478bd9Sstevel@tonic-gate bzero(&in_progress_nwiftab, sizeof (in_progress_nwiftab)); 5715fa9e4066Sahrens bzero(&in_progress_ipdtab, sizeof (in_progress_ipdtab)); 57167c478bd9Sstevel@tonic-gate bzero(&in_progress_devtab, sizeof (in_progress_devtab)); 57177c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list(in_progress_rctltab.zone_rctl_valptr); 57187c478bd9Sstevel@tonic-gate bzero(&in_progress_rctltab, sizeof (in_progress_rctltab)); 57197c478bd9Sstevel@tonic-gate bzero(&in_progress_attrtab, sizeof (in_progress_attrtab)); 5720fa9e4066Sahrens bzero(&in_progress_dstab, sizeof (in_progress_dstab)); 57217c478bd9Sstevel@tonic-gate } 57227c478bd9Sstevel@tonic-gate 57237c478bd9Sstevel@tonic-gate static int 57247c478bd9Sstevel@tonic-gate validate_attr_name(char *name) 57257c478bd9Sstevel@tonic-gate { 57267c478bd9Sstevel@tonic-gate int i; 57277c478bd9Sstevel@tonic-gate 57287c478bd9Sstevel@tonic-gate if (!isalnum(name[0])) { 57297c478bd9Sstevel@tonic-gate zerr(gettext("Invalid %s %s %s: must start with an alpha-" 57307c478bd9Sstevel@tonic-gate "numeric character."), rt_to_str(RT_ATTR), 57317c478bd9Sstevel@tonic-gate pt_to_str(PT_NAME), name); 57327c478bd9Sstevel@tonic-gate return (Z_INVAL); 57337c478bd9Sstevel@tonic-gate } 57347c478bd9Sstevel@tonic-gate for (i = 1; name[i]; i++) 57357c478bd9Sstevel@tonic-gate if (!isalnum(name[i]) && name[i] != '-' && name[i] != '.') { 57367c478bd9Sstevel@tonic-gate zerr(gettext("Invalid %s %s %s: can only contain " 57377c478bd9Sstevel@tonic-gate "alpha-numeric characters, plus '-' and '.'."), 57387c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_NAME), name); 57397c478bd9Sstevel@tonic-gate return (Z_INVAL); 57407c478bd9Sstevel@tonic-gate } 57417c478bd9Sstevel@tonic-gate return (Z_OK); 57427c478bd9Sstevel@tonic-gate } 57437c478bd9Sstevel@tonic-gate 57447c478bd9Sstevel@tonic-gate static int 57457c478bd9Sstevel@tonic-gate validate_attr_type_val(struct zone_attrtab *attrtab) 57467c478bd9Sstevel@tonic-gate { 57477c478bd9Sstevel@tonic-gate boolean_t boolval; 57487c478bd9Sstevel@tonic-gate int64_t intval; 57497c478bd9Sstevel@tonic-gate char strval[MAXNAMELEN]; 57507c478bd9Sstevel@tonic-gate uint64_t uintval; 57517c478bd9Sstevel@tonic-gate 57527c478bd9Sstevel@tonic-gate if (strcmp(attrtab->zone_attr_type, "boolean") == 0) { 57537c478bd9Sstevel@tonic-gate if (zonecfg_get_attr_boolean(attrtab, &boolval) == Z_OK) 57547c478bd9Sstevel@tonic-gate return (Z_OK); 57557c478bd9Sstevel@tonic-gate zerr(gettext("invalid %s value for %s=%s"), 57567c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_TYPE), "boolean"); 57577c478bd9Sstevel@tonic-gate return (Z_ERR); 57587c478bd9Sstevel@tonic-gate } 57597c478bd9Sstevel@tonic-gate 57607c478bd9Sstevel@tonic-gate if (strcmp(attrtab->zone_attr_type, "int") == 0) { 57617c478bd9Sstevel@tonic-gate if (zonecfg_get_attr_int(attrtab, &intval) == Z_OK) 57627c478bd9Sstevel@tonic-gate return (Z_OK); 57637c478bd9Sstevel@tonic-gate zerr(gettext("invalid %s value for %s=%s"), 57647c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_TYPE), "int"); 57657c478bd9Sstevel@tonic-gate return (Z_ERR); 57667c478bd9Sstevel@tonic-gate } 57677c478bd9Sstevel@tonic-gate 57687c478bd9Sstevel@tonic-gate if (strcmp(attrtab->zone_attr_type, "string") == 0) { 57697c478bd9Sstevel@tonic-gate if (zonecfg_get_attr_string(attrtab, strval, 57707c478bd9Sstevel@tonic-gate sizeof (strval)) == Z_OK) 57717c478bd9Sstevel@tonic-gate return (Z_OK); 57727c478bd9Sstevel@tonic-gate zerr(gettext("invalid %s value for %s=%s"), 57737c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_TYPE), "string"); 57747c478bd9Sstevel@tonic-gate return (Z_ERR); 57757c478bd9Sstevel@tonic-gate } 57767c478bd9Sstevel@tonic-gate 57777c478bd9Sstevel@tonic-gate if (strcmp(attrtab->zone_attr_type, "uint") == 0) { 57787c478bd9Sstevel@tonic-gate if (zonecfg_get_attr_uint(attrtab, &uintval) == Z_OK) 57797c478bd9Sstevel@tonic-gate return (Z_OK); 57807c478bd9Sstevel@tonic-gate zerr(gettext("invalid %s value for %s=%s"), 57817c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_TYPE), "uint"); 57827c478bd9Sstevel@tonic-gate return (Z_ERR); 57837c478bd9Sstevel@tonic-gate } 57847c478bd9Sstevel@tonic-gate 57857c478bd9Sstevel@tonic-gate zerr(gettext("invalid %s %s '%s'"), rt_to_str(RT_ATTR), 57867c478bd9Sstevel@tonic-gate pt_to_str(PT_TYPE), attrtab->zone_attr_type); 57877c478bd9Sstevel@tonic-gate return (Z_ERR); 57887c478bd9Sstevel@tonic-gate } 57897c478bd9Sstevel@tonic-gate 5790087719fdSdp /* 5791087719fdSdp * Helper function for end_func-- checks the existence of a given property 5792087719fdSdp * and emits a message if not specified. 5793087719fdSdp */ 5794087719fdSdp static int 5795bbec428eSgjelinek end_check_reqd(char *attr, int pt, boolean_t *validation_failed) 5796087719fdSdp { 5797087719fdSdp if (strlen(attr) == 0) { 5798bbec428eSgjelinek *validation_failed = B_TRUE; 5799087719fdSdp zerr(gettext("%s not specified"), pt_to_str(pt)); 5800087719fdSdp return (Z_ERR); 5801087719fdSdp } 5802087719fdSdp return (Z_OK); 5803087719fdSdp } 5804087719fdSdp 58057c478bd9Sstevel@tonic-gate void 58067c478bd9Sstevel@tonic-gate end_func(cmd_t *cmd) 58077c478bd9Sstevel@tonic-gate { 5808bbec428eSgjelinek boolean_t validation_failed = B_FALSE; 5809bbec428eSgjelinek boolean_t arg_err = B_FALSE; 58107c478bd9Sstevel@tonic-gate struct zone_fstab tmp_fstab; 58117c478bd9Sstevel@tonic-gate struct zone_nwiftab tmp_nwiftab; 58127c478bd9Sstevel@tonic-gate struct zone_devtab tmp_devtab; 58137c478bd9Sstevel@tonic-gate struct zone_rctltab tmp_rctltab; 58147c478bd9Sstevel@tonic-gate struct zone_attrtab tmp_attrtab; 5815fa9e4066Sahrens struct zone_dstab tmp_dstab; 58160209230bSgjelinek int err, arg, res1, res2, res3; 58170209230bSgjelinek uint64_t swap_limit; 58180209230bSgjelinek uint64_t locked_limit; 5819c97ad5cdSakolb uint64_t proc_cap; 58207c478bd9Sstevel@tonic-gate 58217c478bd9Sstevel@tonic-gate assert(cmd != NULL); 58227c478bd9Sstevel@tonic-gate 58237c478bd9Sstevel@tonic-gate optind = 0; 58247ec75eb8Sgjelinek while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?")) != EOF) { 58257c478bd9Sstevel@tonic-gate switch (arg) { 58267c478bd9Sstevel@tonic-gate case '?': 58277c478bd9Sstevel@tonic-gate longer_usage(CMD_END); 5828bbec428eSgjelinek arg_err = B_TRUE; 58297ec75eb8Sgjelinek break; 58307c478bd9Sstevel@tonic-gate default: 58317c478bd9Sstevel@tonic-gate short_usage(CMD_END); 5832bbec428eSgjelinek arg_err = B_TRUE; 58337ec75eb8Sgjelinek break; 58347ec75eb8Sgjelinek } 58357ec75eb8Sgjelinek } 58367ec75eb8Sgjelinek if (arg_err) 58377c478bd9Sstevel@tonic-gate return; 58387ec75eb8Sgjelinek 58397c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 58407c478bd9Sstevel@tonic-gate short_usage(CMD_END); 58417c478bd9Sstevel@tonic-gate return; 58427c478bd9Sstevel@tonic-gate } 58437c478bd9Sstevel@tonic-gate 58447c478bd9Sstevel@tonic-gate if (global_scope) { 58457c478bd9Sstevel@tonic-gate scope_usage(CMD_END); 58467c478bd9Sstevel@tonic-gate return; 58477c478bd9Sstevel@tonic-gate } 58487c478bd9Sstevel@tonic-gate 58497c478bd9Sstevel@tonic-gate assert(end_op == CMD_ADD || end_op == CMD_SELECT); 58507c478bd9Sstevel@tonic-gate 58517c478bd9Sstevel@tonic-gate switch (resource_scope) { 58527c478bd9Sstevel@tonic-gate case RT_FS: 58537c478bd9Sstevel@tonic-gate /* First make sure everything was filled in. */ 5854087719fdSdp if (end_check_reqd(in_progress_fstab.zone_fs_dir, 5855087719fdSdp PT_DIR, &validation_failed) == Z_OK) { 5856087719fdSdp if (in_progress_fstab.zone_fs_dir[0] != '/') { 5857087719fdSdp zerr(gettext("%s %s is not an absolute path."), 5858087719fdSdp pt_to_str(PT_DIR), 5859087719fdSdp in_progress_fstab.zone_fs_dir); 5860bbec428eSgjelinek validation_failed = B_TRUE; 58617c478bd9Sstevel@tonic-gate } 58627c478bd9Sstevel@tonic-gate } 5863087719fdSdp 5864087719fdSdp (void) end_check_reqd(in_progress_fstab.zone_fs_special, 5865087719fdSdp PT_SPECIAL, &validation_failed); 5866087719fdSdp 58677c478bd9Sstevel@tonic-gate if (in_progress_fstab.zone_fs_raw[0] != '\0' && 58687c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_raw[0] != '/') { 5869087719fdSdp zerr(gettext("%s %s is not an absolute path."), 5870087719fdSdp pt_to_str(PT_RAW), 5871087719fdSdp in_progress_fstab.zone_fs_raw); 5872bbec428eSgjelinek validation_failed = B_TRUE; 58737c478bd9Sstevel@tonic-gate } 5874087719fdSdp 5875087719fdSdp (void) end_check_reqd(in_progress_fstab.zone_fs_type, PT_TYPE, 5876087719fdSdp &validation_failed); 5877087719fdSdp 5878087719fdSdp if (validation_failed) { 5879bbec428eSgjelinek saw_error = B_TRUE; 58807c478bd9Sstevel@tonic-gate return; 5881087719fdSdp } 5882087719fdSdp 58837c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) { 58847c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */ 58857c478bd9Sstevel@tonic-gate bzero(&tmp_fstab, sizeof (tmp_fstab)); 58867c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_fstab.zone_fs_dir, 58877c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_dir, 58887c478bd9Sstevel@tonic-gate sizeof (tmp_fstab.zone_fs_dir)); 58897c478bd9Sstevel@tonic-gate err = zonecfg_lookup_filesystem(handle, &tmp_fstab); 58907c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(tmp_fstab.zone_fs_options); 58917c478bd9Sstevel@tonic-gate if (err == Z_OK) { 58927c478bd9Sstevel@tonic-gate zerr(gettext("A %s resource " 58937c478bd9Sstevel@tonic-gate "with the %s '%s' already exists."), 58947c478bd9Sstevel@tonic-gate rt_to_str(RT_FS), pt_to_str(PT_DIR), 58957c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_dir); 5896bbec428eSgjelinek saw_error = B_TRUE; 58977c478bd9Sstevel@tonic-gate return; 58987c478bd9Sstevel@tonic-gate } 58997c478bd9Sstevel@tonic-gate err = zonecfg_add_filesystem(handle, 59007c478bd9Sstevel@tonic-gate &in_progress_fstab); 59017c478bd9Sstevel@tonic-gate } else { 59027c478bd9Sstevel@tonic-gate err = zonecfg_modify_filesystem(handle, &old_fstab, 59037c478bd9Sstevel@tonic-gate &in_progress_fstab); 59047c478bd9Sstevel@tonic-gate } 59057c478bd9Sstevel@tonic-gate zonecfg_free_fs_option_list(in_progress_fstab.zone_fs_options); 59067c478bd9Sstevel@tonic-gate in_progress_fstab.zone_fs_options = NULL; 59077c478bd9Sstevel@tonic-gate break; 5908087719fdSdp 59097c478bd9Sstevel@tonic-gate case RT_IPD: 59107c478bd9Sstevel@tonic-gate /* First make sure everything was filled in. */ 5911087719fdSdp if (end_check_reqd(in_progress_ipdtab.zone_fs_dir, PT_DIR, 5912087719fdSdp &validation_failed) == Z_OK) { 5913087719fdSdp if (in_progress_ipdtab.zone_fs_dir[0] != '/') { 5914087719fdSdp zerr(gettext("%s %s is not an absolute path."), 5915087719fdSdp pt_to_str(PT_DIR), 5916087719fdSdp in_progress_ipdtab.zone_fs_dir); 5917bbec428eSgjelinek validation_failed = B_TRUE; 59187c478bd9Sstevel@tonic-gate } 5919087719fdSdp } 5920087719fdSdp if (validation_failed) { 5921bbec428eSgjelinek saw_error = B_TRUE; 59227c478bd9Sstevel@tonic-gate return; 5923087719fdSdp } 5924087719fdSdp 59257c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) { 59267c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */ 59277c478bd9Sstevel@tonic-gate bzero(&tmp_fstab, sizeof (tmp_fstab)); 59287c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_fstab.zone_fs_dir, 59297c478bd9Sstevel@tonic-gate in_progress_ipdtab.zone_fs_dir, 59307c478bd9Sstevel@tonic-gate sizeof (tmp_fstab.zone_fs_dir)); 59317c478bd9Sstevel@tonic-gate err = zonecfg_lookup_ipd(handle, &tmp_fstab); 59327c478bd9Sstevel@tonic-gate if (err == Z_OK) { 59337c478bd9Sstevel@tonic-gate zerr(gettext("An %s resource " 59347c478bd9Sstevel@tonic-gate "with the %s '%s' already exists."), 59357c478bd9Sstevel@tonic-gate rt_to_str(RT_IPD), pt_to_str(PT_DIR), 59367c478bd9Sstevel@tonic-gate in_progress_ipdtab.zone_fs_dir); 5937bbec428eSgjelinek saw_error = B_TRUE; 59387c478bd9Sstevel@tonic-gate return; 59397c478bd9Sstevel@tonic-gate } 59407c478bd9Sstevel@tonic-gate err = zonecfg_add_ipd(handle, &in_progress_ipdtab); 59417c478bd9Sstevel@tonic-gate } else { 59427c478bd9Sstevel@tonic-gate err = zonecfg_modify_ipd(handle, &old_ipdtab, 59437c478bd9Sstevel@tonic-gate &in_progress_ipdtab); 59447c478bd9Sstevel@tonic-gate } 59457c478bd9Sstevel@tonic-gate break; 59467c478bd9Sstevel@tonic-gate case RT_NET: 5947f4b3ec61Sdh155122 /* 5948f4b3ec61Sdh155122 * First make sure everything was filled in. 5949f4b3ec61Sdh155122 * Since we don't know whether IP will be shared 5950f4b3ec61Sdh155122 * or exclusive here, some checks are deferred until 5951f4b3ec61Sdh155122 * the verify command. 5952f4b3ec61Sdh155122 */ 5953087719fdSdp (void) end_check_reqd(in_progress_nwiftab.zone_nwif_physical, 5954087719fdSdp PT_PHYSICAL, &validation_failed); 5955087719fdSdp 5956087719fdSdp if (validation_failed) { 5957bbec428eSgjelinek saw_error = B_TRUE; 59587c478bd9Sstevel@tonic-gate return; 5959087719fdSdp } 59607c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) { 59617c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */ 59627c478bd9Sstevel@tonic-gate bzero(&tmp_nwiftab, sizeof (tmp_nwiftab)); 5963f4b3ec61Sdh155122 (void) strlcpy(tmp_nwiftab.zone_nwif_physical, 5964f4b3ec61Sdh155122 in_progress_nwiftab.zone_nwif_physical, 5965f4b3ec61Sdh155122 sizeof (tmp_nwiftab.zone_nwif_physical)); 59667c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_nwiftab.zone_nwif_address, 59677c478bd9Sstevel@tonic-gate in_progress_nwiftab.zone_nwif_address, 59687c478bd9Sstevel@tonic-gate sizeof (tmp_nwiftab.zone_nwif_address)); 59697c478bd9Sstevel@tonic-gate if (zonecfg_lookup_nwif(handle, &tmp_nwiftab) == Z_OK) { 5970f4b3ec61Sdh155122 zerr(gettext("A %s resource with the %s '%s', " 5971f4b3ec61Sdh155122 "and %s '%s' already exists."), 5972f4b3ec61Sdh155122 rt_to_str(RT_NET), 5973f4b3ec61Sdh155122 pt_to_str(PT_PHYSICAL), 5974f4b3ec61Sdh155122 in_progress_nwiftab.zone_nwif_physical, 5975f4b3ec61Sdh155122 pt_to_str(PT_ADDRESS), 59767c478bd9Sstevel@tonic-gate in_progress_nwiftab.zone_nwif_address); 5977bbec428eSgjelinek saw_error = B_TRUE; 59787c478bd9Sstevel@tonic-gate return; 59797c478bd9Sstevel@tonic-gate } 59807c478bd9Sstevel@tonic-gate err = zonecfg_add_nwif(handle, &in_progress_nwiftab); 59817c478bd9Sstevel@tonic-gate } else { 59827c478bd9Sstevel@tonic-gate err = zonecfg_modify_nwif(handle, &old_nwiftab, 59837c478bd9Sstevel@tonic-gate &in_progress_nwiftab); 59847c478bd9Sstevel@tonic-gate } 59857c478bd9Sstevel@tonic-gate break; 5986087719fdSdp 59877c478bd9Sstevel@tonic-gate case RT_DEVICE: 59887c478bd9Sstevel@tonic-gate /* First make sure everything was filled in. */ 5989087719fdSdp (void) end_check_reqd(in_progress_devtab.zone_dev_match, 5990087719fdSdp PT_MATCH, &validation_failed); 5991087719fdSdp 5992087719fdSdp if (validation_failed) { 5993bbec428eSgjelinek saw_error = B_TRUE; 59947c478bd9Sstevel@tonic-gate return; 5995087719fdSdp } 5996087719fdSdp 59977c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) { 59987c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */ 59997c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_devtab.zone_dev_match, 60007c478bd9Sstevel@tonic-gate in_progress_devtab.zone_dev_match, 60017c478bd9Sstevel@tonic-gate sizeof (tmp_devtab.zone_dev_match)); 60027c478bd9Sstevel@tonic-gate if (zonecfg_lookup_dev(handle, &tmp_devtab) == Z_OK) { 60037c478bd9Sstevel@tonic-gate zerr(gettext("A %s resource with the %s '%s' " 60047c478bd9Sstevel@tonic-gate "already exists."), rt_to_str(RT_DEVICE), 60057c478bd9Sstevel@tonic-gate pt_to_str(PT_MATCH), 60067c478bd9Sstevel@tonic-gate in_progress_devtab.zone_dev_match); 6007bbec428eSgjelinek saw_error = B_TRUE; 60087c478bd9Sstevel@tonic-gate return; 60097c478bd9Sstevel@tonic-gate } 60107c478bd9Sstevel@tonic-gate err = zonecfg_add_dev(handle, &in_progress_devtab); 60117c478bd9Sstevel@tonic-gate } else { 60127c478bd9Sstevel@tonic-gate err = zonecfg_modify_dev(handle, &old_devtab, 60137c478bd9Sstevel@tonic-gate &in_progress_devtab); 60147c478bd9Sstevel@tonic-gate } 60157c478bd9Sstevel@tonic-gate break; 6016087719fdSdp 60177c478bd9Sstevel@tonic-gate case RT_RCTL: 60187c478bd9Sstevel@tonic-gate /* First make sure everything was filled in. */ 6019087719fdSdp (void) end_check_reqd(in_progress_rctltab.zone_rctl_name, 6020087719fdSdp PT_NAME, &validation_failed); 6021087719fdSdp 60227c478bd9Sstevel@tonic-gate if (in_progress_rctltab.zone_rctl_valptr == NULL) { 60237c478bd9Sstevel@tonic-gate zerr(gettext("no %s specified"), pt_to_str(PT_VALUE)); 6024bbec428eSgjelinek validation_failed = B_TRUE; 60257c478bd9Sstevel@tonic-gate } 6026087719fdSdp 6027087719fdSdp if (validation_failed) { 6028bbec428eSgjelinek saw_error = B_TRUE; 60297c478bd9Sstevel@tonic-gate return; 6030087719fdSdp } 6031087719fdSdp 60327c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) { 60337c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */ 60347c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_rctltab.zone_rctl_name, 60357c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_name, 60367c478bd9Sstevel@tonic-gate sizeof (tmp_rctltab.zone_rctl_name)); 60377c478bd9Sstevel@tonic-gate tmp_rctltab.zone_rctl_valptr = NULL; 60387c478bd9Sstevel@tonic-gate err = zonecfg_lookup_rctl(handle, &tmp_rctltab); 60397c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list( 60407c478bd9Sstevel@tonic-gate tmp_rctltab.zone_rctl_valptr); 60417c478bd9Sstevel@tonic-gate if (err == Z_OK) { 60427c478bd9Sstevel@tonic-gate zerr(gettext("A %s resource " 60437c478bd9Sstevel@tonic-gate "with the %s '%s' already exists."), 60447c478bd9Sstevel@tonic-gate rt_to_str(RT_RCTL), pt_to_str(PT_NAME), 60457c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_name); 6046bbec428eSgjelinek saw_error = B_TRUE; 60477c478bd9Sstevel@tonic-gate return; 60487c478bd9Sstevel@tonic-gate } 60497c478bd9Sstevel@tonic-gate err = zonecfg_add_rctl(handle, &in_progress_rctltab); 60507c478bd9Sstevel@tonic-gate } else { 60517c478bd9Sstevel@tonic-gate err = zonecfg_modify_rctl(handle, &old_rctltab, 60527c478bd9Sstevel@tonic-gate &in_progress_rctltab); 60537c478bd9Sstevel@tonic-gate } 60547c478bd9Sstevel@tonic-gate if (err == Z_OK) { 60557c478bd9Sstevel@tonic-gate zonecfg_free_rctl_value_list( 60567c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_valptr); 60577c478bd9Sstevel@tonic-gate in_progress_rctltab.zone_rctl_valptr = NULL; 60587c478bd9Sstevel@tonic-gate } 60597c478bd9Sstevel@tonic-gate break; 6060087719fdSdp 60617c478bd9Sstevel@tonic-gate case RT_ATTR: 60627c478bd9Sstevel@tonic-gate /* First make sure everything was filled in. */ 6063087719fdSdp (void) end_check_reqd(in_progress_attrtab.zone_attr_name, 6064087719fdSdp PT_NAME, &validation_failed); 6065087719fdSdp (void) end_check_reqd(in_progress_attrtab.zone_attr_type, 6066087719fdSdp PT_TYPE, &validation_failed); 6067087719fdSdp (void) end_check_reqd(in_progress_attrtab.zone_attr_value, 6068087719fdSdp PT_VALUE, &validation_failed); 6069087719fdSdp 60707c478bd9Sstevel@tonic-gate if (validate_attr_name(in_progress_attrtab.zone_attr_name) != 6071087719fdSdp Z_OK) 6072bbec428eSgjelinek validation_failed = B_TRUE; 6073087719fdSdp 6074087719fdSdp if (validate_attr_type_val(&in_progress_attrtab) != Z_OK) 6075bbec428eSgjelinek validation_failed = B_TRUE; 6076087719fdSdp 6077087719fdSdp if (validation_failed) { 6078bbec428eSgjelinek saw_error = B_TRUE; 60797c478bd9Sstevel@tonic-gate return; 6080087719fdSdp } 60817c478bd9Sstevel@tonic-gate if (end_op == CMD_ADD) { 60827c478bd9Sstevel@tonic-gate /* Make sure there isn't already one like this. */ 60837c478bd9Sstevel@tonic-gate bzero(&tmp_attrtab, sizeof (tmp_attrtab)); 60847c478bd9Sstevel@tonic-gate (void) strlcpy(tmp_attrtab.zone_attr_name, 60857c478bd9Sstevel@tonic-gate in_progress_attrtab.zone_attr_name, 60867c478bd9Sstevel@tonic-gate sizeof (tmp_attrtab.zone_attr_name)); 60877c478bd9Sstevel@tonic-gate if (zonecfg_lookup_attr(handle, &tmp_attrtab) == Z_OK) { 60887c478bd9Sstevel@tonic-gate zerr(gettext("An %s resource " 60897c478bd9Sstevel@tonic-gate "with the %s '%s' already exists."), 60907c478bd9Sstevel@tonic-gate rt_to_str(RT_ATTR), pt_to_str(PT_NAME), 60917c478bd9Sstevel@tonic-gate in_progress_attrtab.zone_attr_name); 6092bbec428eSgjelinek saw_error = B_TRUE; 60937c478bd9Sstevel@tonic-gate return; 60947c478bd9Sstevel@tonic-gate } 60957c478bd9Sstevel@tonic-gate err = zonecfg_add_attr(handle, &in_progress_attrtab); 60967c478bd9Sstevel@tonic-gate } else { 60977c478bd9Sstevel@tonic-gate err = zonecfg_modify_attr(handle, &old_attrtab, 60987c478bd9Sstevel@tonic-gate &in_progress_attrtab); 60997c478bd9Sstevel@tonic-gate } 61007c478bd9Sstevel@tonic-gate break; 6101fa9e4066Sahrens case RT_DATASET: 6102fa9e4066Sahrens /* First make sure everything was filled in. */ 6103fa9e4066Sahrens if (strlen(in_progress_dstab.zone_dataset_name) == 0) { 6104fa9e4066Sahrens zerr("%s %s", pt_to_str(PT_NAME), 6105fa9e4066Sahrens gettext("not specified")); 6106bbec428eSgjelinek saw_error = B_TRUE; 6107bbec428eSgjelinek validation_failed = B_TRUE; 6108fa9e4066Sahrens } 6109fa9e4066Sahrens if (validation_failed) 6110fa9e4066Sahrens return; 6111fa9e4066Sahrens if (end_op == CMD_ADD) { 6112fa9e4066Sahrens /* Make sure there isn't already one like this. */ 6113fa9e4066Sahrens bzero(&tmp_dstab, sizeof (tmp_dstab)); 6114fa9e4066Sahrens (void) strlcpy(tmp_dstab.zone_dataset_name, 6115fa9e4066Sahrens in_progress_dstab.zone_dataset_name, 6116fa9e4066Sahrens sizeof (tmp_dstab.zone_dataset_name)); 6117fa9e4066Sahrens err = zonecfg_lookup_ds(handle, &tmp_dstab); 6118fa9e4066Sahrens if (err == Z_OK) { 6119fa9e4066Sahrens zerr(gettext("A %s resource " 6120fa9e4066Sahrens "with the %s '%s' already exists."), 6121fa9e4066Sahrens rt_to_str(RT_DATASET), pt_to_str(PT_NAME), 6122fa9e4066Sahrens in_progress_dstab.zone_dataset_name); 6123bbec428eSgjelinek saw_error = B_TRUE; 6124fa9e4066Sahrens return; 6125fa9e4066Sahrens } 6126fa9e4066Sahrens err = zonecfg_add_ds(handle, &in_progress_dstab); 6127fa9e4066Sahrens } else { 6128fa9e4066Sahrens err = zonecfg_modify_ds(handle, &old_dstab, 6129fa9e4066Sahrens &in_progress_dstab); 6130fa9e4066Sahrens } 6131fa9e4066Sahrens break; 61320209230bSgjelinek case RT_DCPU: 61330209230bSgjelinek /* Make sure everything was filled in. */ 61340209230bSgjelinek if (end_check_reqd(in_progress_psettab.zone_ncpu_min, 61350209230bSgjelinek PT_NCPUS, &validation_failed) != Z_OK) { 6136bbec428eSgjelinek saw_error = B_TRUE; 61370209230bSgjelinek return; 61380209230bSgjelinek } 61390209230bSgjelinek 61400209230bSgjelinek if (end_op == CMD_ADD) { 61410209230bSgjelinek err = zonecfg_add_pset(handle, &in_progress_psettab); 61420209230bSgjelinek } else { 61430209230bSgjelinek err = zonecfg_modify_pset(handle, &in_progress_psettab); 61440209230bSgjelinek } 61450209230bSgjelinek break; 6146c97ad5cdSakolb case RT_PCAP: 6147c97ad5cdSakolb /* Make sure everything was filled in. */ 6148c97ad5cdSakolb if (zonecfg_get_aliased_rctl(handle, ALIAS_CPUCAP, &proc_cap) 6149c97ad5cdSakolb != Z_OK) { 6150c97ad5cdSakolb zerr(gettext("%s not specified"), pt_to_str(PT_NCPUS)); 6151bbec428eSgjelinek saw_error = B_TRUE; 6152bbec428eSgjelinek validation_failed = B_TRUE; 6153c97ad5cdSakolb return; 6154c97ad5cdSakolb } 6155c97ad5cdSakolb err = Z_OK; 6156c97ad5cdSakolb break; 61570209230bSgjelinek case RT_MCAP: 61580209230bSgjelinek /* Make sure everything was filled in. */ 61590209230bSgjelinek res1 = strlen(in_progress_mcaptab.zone_physmem_cap) == 0 ? 61600209230bSgjelinek Z_ERR : Z_OK; 61610209230bSgjelinek res2 = zonecfg_get_aliased_rctl(handle, ALIAS_MAXSWAP, 61620209230bSgjelinek &swap_limit); 61630209230bSgjelinek res3 = zonecfg_get_aliased_rctl(handle, ALIAS_MAXLOCKEDMEM, 61640209230bSgjelinek &locked_limit); 61650209230bSgjelinek 61660209230bSgjelinek if (res1 != Z_OK && res2 != Z_OK && res3 != Z_OK) { 61670209230bSgjelinek zerr(gettext("No property was specified. One of %s, " 61680209230bSgjelinek "%s or %s is required."), pt_to_str(PT_PHYSICAL), 61690209230bSgjelinek pt_to_str(PT_SWAP), pt_to_str(PT_LOCKED)); 6170bbec428eSgjelinek saw_error = B_TRUE; 61710209230bSgjelinek return; 61720209230bSgjelinek } 61730209230bSgjelinek 61740209230bSgjelinek /* if phys & locked are both set, verify locked <= phys */ 61750209230bSgjelinek if (res1 == Z_OK && res3 == Z_OK) { 61760209230bSgjelinek uint64_t phys_limit; 61770209230bSgjelinek char *endp; 61780209230bSgjelinek 61790209230bSgjelinek phys_limit = strtoull( 61800209230bSgjelinek in_progress_mcaptab.zone_physmem_cap, &endp, 10); 61810209230bSgjelinek if (phys_limit < locked_limit) { 61820209230bSgjelinek zerr(gettext("The %s cap must be less than or " 61830209230bSgjelinek "equal to the %s cap."), 61840209230bSgjelinek pt_to_str(PT_LOCKED), 61850209230bSgjelinek pt_to_str(PT_PHYSICAL)); 6186bbec428eSgjelinek saw_error = B_TRUE; 61870209230bSgjelinek return; 61880209230bSgjelinek } 61890209230bSgjelinek } 61900209230bSgjelinek 61910209230bSgjelinek err = Z_OK; 61920209230bSgjelinek if (res1 == Z_OK) { 61930209230bSgjelinek /* 61940209230bSgjelinek * We could be ending from either an add operation 61950209230bSgjelinek * or a select operation. Since all of the properties 61960209230bSgjelinek * within this resource are optional, we always use 61970209230bSgjelinek * modify on the mcap entry. zonecfg_modify_mcap() 61980209230bSgjelinek * will handle both adding and modifying a memory cap. 61990209230bSgjelinek */ 62000209230bSgjelinek err = zonecfg_modify_mcap(handle, &in_progress_mcaptab); 62010209230bSgjelinek } else if (end_op == CMD_SELECT) { 62020209230bSgjelinek /* 62030209230bSgjelinek * If we're ending from a select and the physical 62040209230bSgjelinek * memory cap is empty then the user could have cleared 62050209230bSgjelinek * the physical cap value, so try to delete the entry. 62060209230bSgjelinek */ 62070209230bSgjelinek (void) zonecfg_delete_mcap(handle); 62080209230bSgjelinek } 62090209230bSgjelinek break; 62107c478bd9Sstevel@tonic-gate default: 62117c478bd9Sstevel@tonic-gate zone_perror(rt_to_str(resource_scope), Z_NO_RESOURCE_TYPE, 6212bbec428eSgjelinek B_TRUE); 6213bbec428eSgjelinek saw_error = B_TRUE; 62147c478bd9Sstevel@tonic-gate return; 62157c478bd9Sstevel@tonic-gate } 62167c478bd9Sstevel@tonic-gate 62177c478bd9Sstevel@tonic-gate if (err != Z_OK) { 6218bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 62197c478bd9Sstevel@tonic-gate } else { 6220bbec428eSgjelinek need_to_commit = B_TRUE; 6221bbec428eSgjelinek global_scope = B_TRUE; 62227c478bd9Sstevel@tonic-gate end_op = -1; 62237c478bd9Sstevel@tonic-gate } 62247c478bd9Sstevel@tonic-gate } 62257c478bd9Sstevel@tonic-gate 62267c478bd9Sstevel@tonic-gate void 62277c478bd9Sstevel@tonic-gate commit_func(cmd_t *cmd) 62287c478bd9Sstevel@tonic-gate { 62297c478bd9Sstevel@tonic-gate int arg; 6230bbec428eSgjelinek boolean_t arg_err = B_FALSE; 62317c478bd9Sstevel@tonic-gate 62327c478bd9Sstevel@tonic-gate optind = 0; 62337ec75eb8Sgjelinek while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?")) != EOF) { 62347c478bd9Sstevel@tonic-gate switch (arg) { 62357c478bd9Sstevel@tonic-gate case '?': 62367c478bd9Sstevel@tonic-gate longer_usage(CMD_COMMIT); 6237bbec428eSgjelinek arg_err = B_TRUE; 62387ec75eb8Sgjelinek break; 62397c478bd9Sstevel@tonic-gate default: 62407c478bd9Sstevel@tonic-gate short_usage(CMD_COMMIT); 6241bbec428eSgjelinek arg_err = B_TRUE; 62427ec75eb8Sgjelinek break; 62437ec75eb8Sgjelinek } 62447ec75eb8Sgjelinek } 62457ec75eb8Sgjelinek if (arg_err) 62467c478bd9Sstevel@tonic-gate return; 62477ec75eb8Sgjelinek 62487c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 62497c478bd9Sstevel@tonic-gate short_usage(CMD_COMMIT); 62507c478bd9Sstevel@tonic-gate return; 62517c478bd9Sstevel@tonic-gate } 62527c478bd9Sstevel@tonic-gate 62537c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_COMMIT)) 62547c478bd9Sstevel@tonic-gate return; 62557c478bd9Sstevel@tonic-gate 62567c478bd9Sstevel@tonic-gate assert(cmd != NULL); 62577c478bd9Sstevel@tonic-gate 62587c478bd9Sstevel@tonic-gate cmd->cmd_argc = 1; 62597c478bd9Sstevel@tonic-gate /* 62607c478bd9Sstevel@tonic-gate * cmd_arg normally comes from a strdup() in the lexer, and the 62617c478bd9Sstevel@tonic-gate * whole cmd structure and its (char *) attributes are freed at 62627c478bd9Sstevel@tonic-gate * the completion of each command, so the strdup() below is needed 62637c478bd9Sstevel@tonic-gate * to match this and prevent a core dump from trying to free() 62647c478bd9Sstevel@tonic-gate * something that can't be. 62657c478bd9Sstevel@tonic-gate */ 62667c478bd9Sstevel@tonic-gate if ((cmd->cmd_argv[0] = strdup("save")) == NULL) { 6267bbec428eSgjelinek zone_perror(zone, Z_NOMEM, B_TRUE); 62687c478bd9Sstevel@tonic-gate exit(Z_ERR); 62697c478bd9Sstevel@tonic-gate } 62707c478bd9Sstevel@tonic-gate cmd->cmd_argv[1] = NULL; 62717c478bd9Sstevel@tonic-gate verify_func(cmd); 62727c478bd9Sstevel@tonic-gate } 62737c478bd9Sstevel@tonic-gate 62747c478bd9Sstevel@tonic-gate void 62757c478bd9Sstevel@tonic-gate revert_func(cmd_t *cmd) 62767c478bd9Sstevel@tonic-gate { 62777c478bd9Sstevel@tonic-gate char line[128]; /* enough to ask a question */ 6278bbec428eSgjelinek boolean_t force = B_FALSE; 6279bbec428eSgjelinek boolean_t arg_err = B_FALSE; 62807c478bd9Sstevel@tonic-gate int err, arg, answer; 62817c478bd9Sstevel@tonic-gate 62827c478bd9Sstevel@tonic-gate optind = 0; 62837c478bd9Sstevel@tonic-gate while ((arg = getopt(cmd->cmd_argc, cmd->cmd_argv, "?F")) != EOF) { 62847c478bd9Sstevel@tonic-gate switch (arg) { 62857c478bd9Sstevel@tonic-gate case '?': 62867c478bd9Sstevel@tonic-gate longer_usage(CMD_REVERT); 6287bbec428eSgjelinek arg_err = B_TRUE; 62887ec75eb8Sgjelinek break; 62897c478bd9Sstevel@tonic-gate case 'F': 6290bbec428eSgjelinek force = B_TRUE; 62917c478bd9Sstevel@tonic-gate break; 62927c478bd9Sstevel@tonic-gate default: 62937c478bd9Sstevel@tonic-gate short_usage(CMD_REVERT); 6294bbec428eSgjelinek arg_err = B_TRUE; 62957ec75eb8Sgjelinek break; 62967ec75eb8Sgjelinek } 62977ec75eb8Sgjelinek } 62987ec75eb8Sgjelinek if (arg_err) 62997c478bd9Sstevel@tonic-gate return; 63007ec75eb8Sgjelinek 63017c478bd9Sstevel@tonic-gate if (optind != cmd->cmd_argc) { 63027c478bd9Sstevel@tonic-gate short_usage(CMD_REVERT); 63037c478bd9Sstevel@tonic-gate return; 63047c478bd9Sstevel@tonic-gate } 63057c478bd9Sstevel@tonic-gate 63067c478bd9Sstevel@tonic-gate if (zone_is_read_only(CMD_REVERT)) 63077c478bd9Sstevel@tonic-gate return; 63087c478bd9Sstevel@tonic-gate 63097c478bd9Sstevel@tonic-gate if (zonecfg_check_handle(handle) != Z_OK) { 63107c478bd9Sstevel@tonic-gate zerr(gettext("No changes to revert.")); 6311bbec428eSgjelinek saw_error = B_TRUE; 63127c478bd9Sstevel@tonic-gate return; 63137c478bd9Sstevel@tonic-gate } 63147c478bd9Sstevel@tonic-gate 63157c478bd9Sstevel@tonic-gate if (!force) { 63167c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), 63177c478bd9Sstevel@tonic-gate gettext("Are you sure you want to revert")); 6318bbec428eSgjelinek if ((answer = ask_yesno(B_FALSE, line)) == -1) { 63197c478bd9Sstevel@tonic-gate zerr(gettext("Input not from terminal and -F not " 63207c478bd9Sstevel@tonic-gate "specified:\n%s command ignored, exiting."), 63217c478bd9Sstevel@tonic-gate cmd_to_str(CMD_REVERT)); 63227c478bd9Sstevel@tonic-gate exit(Z_ERR); 63237c478bd9Sstevel@tonic-gate } 63247c478bd9Sstevel@tonic-gate if (answer != 1) 63257c478bd9Sstevel@tonic-gate return; 63267c478bd9Sstevel@tonic-gate } 63277c478bd9Sstevel@tonic-gate 63287c478bd9Sstevel@tonic-gate /* 63297c478bd9Sstevel@tonic-gate * Time for a new handle: finish the old one off first 63307c478bd9Sstevel@tonic-gate * then get a new one properly to avoid leaks. 63317c478bd9Sstevel@tonic-gate */ 63327c478bd9Sstevel@tonic-gate zonecfg_fini_handle(handle); 63337c478bd9Sstevel@tonic-gate if ((handle = zonecfg_init_handle()) == NULL) { 6334bbec428eSgjelinek zone_perror(execname, Z_NOMEM, B_TRUE); 63357c478bd9Sstevel@tonic-gate exit(Z_ERR); 63367c478bd9Sstevel@tonic-gate } 6337087719fdSdp if ((err = zonecfg_get_handle(revert_zone, handle)) != Z_OK) { 6338bbec428eSgjelinek saw_error = B_TRUE; 6339bbec428eSgjelinek got_handle = B_FALSE; 63407c478bd9Sstevel@tonic-gate if (err == Z_NO_ZONE) 63417c478bd9Sstevel@tonic-gate zerr(gettext("%s: no such saved zone to revert to."), 6342087719fdSdp revert_zone); 63437c478bd9Sstevel@tonic-gate else 6344bbec428eSgjelinek zone_perror(zone, err, B_TRUE); 63457c478bd9Sstevel@tonic-gate } 6346087719fdSdp (void) strlcpy(zone, revert_zone, sizeof (zone)); 63477c478bd9Sstevel@tonic-gate } 63487c478bd9Sstevel@tonic-gate 63497c478bd9Sstevel@tonic-gate void 63507c478bd9Sstevel@tonic-gate help_func(cmd_t *cmd) 63517c478bd9Sstevel@tonic-gate { 63527c478bd9Sstevel@tonic-gate int i; 63537c478bd9Sstevel@tonic-gate 63547c478bd9Sstevel@tonic-gate assert(cmd != NULL); 63557c478bd9Sstevel@tonic-gate 63567c478bd9Sstevel@tonic-gate if (cmd->cmd_argc == 0) { 6357bbec428eSgjelinek usage(B_TRUE, global_scope ? HELP_SUBCMDS : HELP_RES_SCOPE); 63587c478bd9Sstevel@tonic-gate return; 63597c478bd9Sstevel@tonic-gate } 63607c478bd9Sstevel@tonic-gate if (strcmp(cmd->cmd_argv[0], "usage") == 0) { 6361bbec428eSgjelinek usage(B_TRUE, HELP_USAGE); 63627c478bd9Sstevel@tonic-gate return; 63637c478bd9Sstevel@tonic-gate } 63647c478bd9Sstevel@tonic-gate if (strcmp(cmd->cmd_argv[0], "commands") == 0) { 6365bbec428eSgjelinek usage(B_TRUE, HELP_SUBCMDS); 63667c478bd9Sstevel@tonic-gate return; 63677c478bd9Sstevel@tonic-gate } 63687c478bd9Sstevel@tonic-gate if (strcmp(cmd->cmd_argv[0], "syntax") == 0) { 6369bbec428eSgjelinek usage(B_TRUE, HELP_SYNTAX | HELP_RES_PROPS); 63707c478bd9Sstevel@tonic-gate return; 63717c478bd9Sstevel@tonic-gate } 63727c478bd9Sstevel@tonic-gate if (strcmp(cmd->cmd_argv[0], "-?") == 0) { 63737c478bd9Sstevel@tonic-gate longer_usage(CMD_HELP); 63747c478bd9Sstevel@tonic-gate return; 63757c478bd9Sstevel@tonic-gate } 63767c478bd9Sstevel@tonic-gate 63777c478bd9Sstevel@tonic-gate for (i = 0; i <= CMD_MAX; i++) { 63787c478bd9Sstevel@tonic-gate if (strcmp(cmd->cmd_argv[0], cmd_to_str(i)) == 0) { 63797c478bd9Sstevel@tonic-gate longer_usage(i); 63807c478bd9Sstevel@tonic-gate return; 63817c478bd9Sstevel@tonic-gate } 63827c478bd9Sstevel@tonic-gate } 63837c478bd9Sstevel@tonic-gate /* We do not use zerr() here because we do not want its extra \n. */ 63847c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("Unknown help subject %s. "), 63857c478bd9Sstevel@tonic-gate cmd->cmd_argv[0]); 6386bbec428eSgjelinek usage(B_FALSE, HELP_META); 63877c478bd9Sstevel@tonic-gate } 63887c478bd9Sstevel@tonic-gate 63897c478bd9Sstevel@tonic-gate static int 63907c478bd9Sstevel@tonic-gate string_to_yyin(char *string) 63917c478bd9Sstevel@tonic-gate { 63927c478bd9Sstevel@tonic-gate if ((yyin = tmpfile()) == NULL) { 6393bbec428eSgjelinek zone_perror(execname, Z_TEMP_FILE, B_TRUE); 63947c478bd9Sstevel@tonic-gate return (Z_ERR); 63957c478bd9Sstevel@tonic-gate } 63967c478bd9Sstevel@tonic-gate if (fwrite(string, strlen(string), 1, yyin) != 1) { 6397bbec428eSgjelinek zone_perror(execname, Z_TEMP_FILE, B_TRUE); 63987c478bd9Sstevel@tonic-gate return (Z_ERR); 63997c478bd9Sstevel@tonic-gate } 64007c478bd9Sstevel@tonic-gate if (fseek(yyin, 0, SEEK_SET) != 0) { 6401bbec428eSgjelinek zone_perror(execname, Z_TEMP_FILE, B_TRUE); 64027c478bd9Sstevel@tonic-gate return (Z_ERR); 64037c478bd9Sstevel@tonic-gate } 64047c478bd9Sstevel@tonic-gate return (Z_OK); 64057c478bd9Sstevel@tonic-gate } 64067c478bd9Sstevel@tonic-gate 64077c478bd9Sstevel@tonic-gate /* This is the back-end helper function for read_input() below. */ 64087c478bd9Sstevel@tonic-gate 64097c478bd9Sstevel@tonic-gate static int 64107c478bd9Sstevel@tonic-gate cleanup() 64117c478bd9Sstevel@tonic-gate { 64127c478bd9Sstevel@tonic-gate int answer; 64137c478bd9Sstevel@tonic-gate cmd_t *cmd; 64147c478bd9Sstevel@tonic-gate 64157c478bd9Sstevel@tonic-gate if (!interactive_mode && !cmd_file_mode) { 64167c478bd9Sstevel@tonic-gate /* 64177c478bd9Sstevel@tonic-gate * If we're not in interactive mode, and we're not in command 64187c478bd9Sstevel@tonic-gate * file mode, then we must be in commands-from-the-command-line 64197c478bd9Sstevel@tonic-gate * mode. As such, we can't loop back and ask for more input. 64207c478bd9Sstevel@tonic-gate * It was OK to prompt for such things as whether or not to 64217c478bd9Sstevel@tonic-gate * really delete a zone in the command handler called from 64227c478bd9Sstevel@tonic-gate * yyparse() above, but "really quit?" makes no sense in this 64237c478bd9Sstevel@tonic-gate * context. So disable prompting. 64247c478bd9Sstevel@tonic-gate */ 6425bbec428eSgjelinek ok_to_prompt = B_FALSE; 64267c478bd9Sstevel@tonic-gate } 64277c478bd9Sstevel@tonic-gate if (!global_scope) { 64287c478bd9Sstevel@tonic-gate if (!time_to_exit) { 64297c478bd9Sstevel@tonic-gate /* 64307c478bd9Sstevel@tonic-gate * Just print a simple error message in the -1 case, 64317c478bd9Sstevel@tonic-gate * since exit_func() already handles that case, and 64327c478bd9Sstevel@tonic-gate * EOF means we are finished anyway. 64337c478bd9Sstevel@tonic-gate */ 6434bbec428eSgjelinek answer = ask_yesno(B_FALSE, 64357c478bd9Sstevel@tonic-gate gettext("Resource incomplete; really quit")); 64367c478bd9Sstevel@tonic-gate if (answer == -1) { 64377c478bd9Sstevel@tonic-gate zerr(gettext("Resource incomplete.")); 64387c478bd9Sstevel@tonic-gate return (Z_ERR); 64397c478bd9Sstevel@tonic-gate } 64407c478bd9Sstevel@tonic-gate if (answer != 1) { 64417c478bd9Sstevel@tonic-gate yyin = stdin; 64427c478bd9Sstevel@tonic-gate return (Z_REPEAT); 64437c478bd9Sstevel@tonic-gate } 64447c478bd9Sstevel@tonic-gate } else { 6445bbec428eSgjelinek saw_error = B_TRUE; 64467c478bd9Sstevel@tonic-gate } 64477c478bd9Sstevel@tonic-gate } 64487c478bd9Sstevel@tonic-gate /* 64497c478bd9Sstevel@tonic-gate * Make sure we tried something and that the handle checks 64507c478bd9Sstevel@tonic-gate * out, or we would get a false error trying to commit. 64517c478bd9Sstevel@tonic-gate */ 64527c478bd9Sstevel@tonic-gate if (need_to_commit && zonecfg_check_handle(handle) == Z_OK) { 64537c478bd9Sstevel@tonic-gate if ((cmd = alloc_cmd()) == NULL) { 6454bbec428eSgjelinek zone_perror(zone, Z_NOMEM, B_TRUE); 64557c478bd9Sstevel@tonic-gate return (Z_ERR); 64567c478bd9Sstevel@tonic-gate } 64577c478bd9Sstevel@tonic-gate cmd->cmd_argc = 0; 64587c478bd9Sstevel@tonic-gate cmd->cmd_argv[0] = NULL; 64597c478bd9Sstevel@tonic-gate commit_func(cmd); 64607c478bd9Sstevel@tonic-gate free_cmd(cmd); 64617c478bd9Sstevel@tonic-gate /* 64627c478bd9Sstevel@tonic-gate * need_to_commit will get set back to FALSE if the 64637c478bd9Sstevel@tonic-gate * configuration is saved successfully. 64647c478bd9Sstevel@tonic-gate */ 64657c478bd9Sstevel@tonic-gate if (need_to_commit) { 64667c478bd9Sstevel@tonic-gate if (force_exit) { 64677c478bd9Sstevel@tonic-gate zerr(gettext("Configuration not saved.")); 64687c478bd9Sstevel@tonic-gate return (Z_ERR); 64697c478bd9Sstevel@tonic-gate } 6470bbec428eSgjelinek answer = ask_yesno(B_FALSE, 64717c478bd9Sstevel@tonic-gate gettext("Configuration not saved; really quit")); 64727c478bd9Sstevel@tonic-gate if (answer == -1) { 64737c478bd9Sstevel@tonic-gate zerr(gettext("Configuration not saved.")); 64747c478bd9Sstevel@tonic-gate return (Z_ERR); 64757c478bd9Sstevel@tonic-gate } 64767c478bd9Sstevel@tonic-gate if (answer != 1) { 6477bbec428eSgjelinek time_to_exit = B_FALSE; 64787c478bd9Sstevel@tonic-gate yyin = stdin; 64797c478bd9Sstevel@tonic-gate return (Z_REPEAT); 64807c478bd9Sstevel@tonic-gate } 64817c478bd9Sstevel@tonic-gate } 64827c478bd9Sstevel@tonic-gate } 64837c478bd9Sstevel@tonic-gate return ((need_to_commit || saw_error) ? Z_ERR : Z_OK); 64847c478bd9Sstevel@tonic-gate } 64857c478bd9Sstevel@tonic-gate 64867c478bd9Sstevel@tonic-gate /* 64877c478bd9Sstevel@tonic-gate * read_input() is the driver of this program. It is a wrapper around 64887c478bd9Sstevel@tonic-gate * yyparse(), printing appropriate prompts when needed, checking for 64897c478bd9Sstevel@tonic-gate * exit conditions and reacting appropriately [the latter in its cleanup() 64907c478bd9Sstevel@tonic-gate * helper function]. 64917c478bd9Sstevel@tonic-gate * 64927c478bd9Sstevel@tonic-gate * Like most zonecfg functions, it returns Z_OK or Z_ERR, *or* Z_REPEAT 64937c478bd9Sstevel@tonic-gate * so do_interactive() knows that we are not really done (i.e, we asked 64947c478bd9Sstevel@tonic-gate * the user if we should really quit and the user said no). 64957c478bd9Sstevel@tonic-gate */ 64967c478bd9Sstevel@tonic-gate static int 64977c478bd9Sstevel@tonic-gate read_input() 64987c478bd9Sstevel@tonic-gate { 6499bbec428eSgjelinek boolean_t yyin_is_a_tty = isatty(fileno(yyin)); 65007c478bd9Sstevel@tonic-gate /* 65017c478bd9Sstevel@tonic-gate * The prompt is "e:z> " or "e:z:r> " where e is execname, z is zone 65027c478bd9Sstevel@tonic-gate * and r is resource_scope: 5 is for the two ":"s + "> " + terminator. 65037c478bd9Sstevel@tonic-gate */ 65047c478bd9Sstevel@tonic-gate char prompt[MAXPATHLEN + ZONENAME_MAX + MAX_RT_STRLEN + 5], *line; 65057c478bd9Sstevel@tonic-gate 65067c478bd9Sstevel@tonic-gate /* yyin should have been set to the appropriate (FILE *) if not stdin */ 6507bbec428eSgjelinek newline_terminated = B_TRUE; 65087c478bd9Sstevel@tonic-gate for (;;) { 65097c478bd9Sstevel@tonic-gate if (yyin_is_a_tty) { 65107c478bd9Sstevel@tonic-gate if (newline_terminated) { 65117c478bd9Sstevel@tonic-gate if (global_scope) 65127c478bd9Sstevel@tonic-gate (void) snprintf(prompt, sizeof (prompt), 65137c478bd9Sstevel@tonic-gate "%s:%s> ", execname, zone); 65147c478bd9Sstevel@tonic-gate else 65157c478bd9Sstevel@tonic-gate (void) snprintf(prompt, sizeof (prompt), 65167c478bd9Sstevel@tonic-gate "%s:%s:%s> ", execname, zone, 65177c478bd9Sstevel@tonic-gate rt_to_str(resource_scope)); 65187c478bd9Sstevel@tonic-gate } 65197c478bd9Sstevel@tonic-gate /* 65207c478bd9Sstevel@tonic-gate * If the user hits ^C then we want to catch it and 65217c478bd9Sstevel@tonic-gate * start over. If the user hits EOF then we want to 65227c478bd9Sstevel@tonic-gate * bail out. 65237c478bd9Sstevel@tonic-gate */ 65247c478bd9Sstevel@tonic-gate line = gl_get_line(gl, prompt, NULL, -1); 65257c478bd9Sstevel@tonic-gate if (gl_return_status(gl) == GLR_SIGNAL) { 65267c478bd9Sstevel@tonic-gate gl_abandon_line(gl); 65277c478bd9Sstevel@tonic-gate continue; 65287c478bd9Sstevel@tonic-gate } 65297c478bd9Sstevel@tonic-gate if (line == NULL) 65307c478bd9Sstevel@tonic-gate break; 65317c478bd9Sstevel@tonic-gate (void) string_to_yyin(line); 65327c478bd9Sstevel@tonic-gate while (!feof(yyin)) 65337c478bd9Sstevel@tonic-gate yyparse(); 65347c478bd9Sstevel@tonic-gate } else { 65357c478bd9Sstevel@tonic-gate yyparse(); 65367c478bd9Sstevel@tonic-gate } 65377c478bd9Sstevel@tonic-gate /* Bail out on an error in command file mode. */ 65387c478bd9Sstevel@tonic-gate if (saw_error && cmd_file_mode && !interactive_mode) 6539bbec428eSgjelinek time_to_exit = B_TRUE; 65407c478bd9Sstevel@tonic-gate if (time_to_exit || (!yyin_is_a_tty && feof(yyin))) 65417c478bd9Sstevel@tonic-gate break; 65427c478bd9Sstevel@tonic-gate } 65437c478bd9Sstevel@tonic-gate return (cleanup()); 65447c478bd9Sstevel@tonic-gate } 65457c478bd9Sstevel@tonic-gate 65467c478bd9Sstevel@tonic-gate /* 65477c478bd9Sstevel@tonic-gate * This function is used in the zonecfg-interactive-mode scenario: it just 65487c478bd9Sstevel@tonic-gate * calls read_input() until we are done. 65497c478bd9Sstevel@tonic-gate */ 65507c478bd9Sstevel@tonic-gate 65517c478bd9Sstevel@tonic-gate static int 65527c478bd9Sstevel@tonic-gate do_interactive(void) 65537c478bd9Sstevel@tonic-gate { 65547c478bd9Sstevel@tonic-gate int err; 65557c478bd9Sstevel@tonic-gate 6556bbec428eSgjelinek interactive_mode = B_TRUE; 65577c478bd9Sstevel@tonic-gate if (!read_only_mode) { 65587c478bd9Sstevel@tonic-gate /* 65597c478bd9Sstevel@tonic-gate * Try to set things up proactively in interactive mode, so 65607c478bd9Sstevel@tonic-gate * that if the zone in question does not exist yet, we can 65617c478bd9Sstevel@tonic-gate * provide the user with a clue. 65627c478bd9Sstevel@tonic-gate */ 6563bbec428eSgjelinek (void) initialize(B_FALSE); 65647c478bd9Sstevel@tonic-gate } 6565087719fdSdp do { 65667c478bd9Sstevel@tonic-gate err = read_input(); 6567087719fdSdp } while (err == Z_REPEAT); 65687c478bd9Sstevel@tonic-gate return (err); 65697c478bd9Sstevel@tonic-gate } 65707c478bd9Sstevel@tonic-gate 65717c478bd9Sstevel@tonic-gate /* 65727c478bd9Sstevel@tonic-gate * cmd_file is slightly more complicated, as it has to open the command file 65737c478bd9Sstevel@tonic-gate * and set yyin appropriately. Once that is done, though, it just calls 65747c478bd9Sstevel@tonic-gate * read_input(), and only once, since prompting is not possible. 65757c478bd9Sstevel@tonic-gate */ 65767c478bd9Sstevel@tonic-gate 65777c478bd9Sstevel@tonic-gate static int 65787c478bd9Sstevel@tonic-gate cmd_file(char *file) 65797c478bd9Sstevel@tonic-gate { 65807c478bd9Sstevel@tonic-gate FILE *infile; 65817c478bd9Sstevel@tonic-gate int err; 65827c478bd9Sstevel@tonic-gate struct stat statbuf; 6583bbec428eSgjelinek boolean_t using_real_file = (strcmp(file, "-") != 0); 65847c478bd9Sstevel@tonic-gate 65857c478bd9Sstevel@tonic-gate if (using_real_file) { 65867c478bd9Sstevel@tonic-gate /* 65877c478bd9Sstevel@tonic-gate * zerr() prints a line number in cmd_file_mode, which we do 65887c478bd9Sstevel@tonic-gate * not want here, so temporarily unset it. 65897c478bd9Sstevel@tonic-gate */ 6590bbec428eSgjelinek cmd_file_mode = B_FALSE; 65917c478bd9Sstevel@tonic-gate if ((infile = fopen(file, "r")) == NULL) { 65927c478bd9Sstevel@tonic-gate zerr(gettext("could not open file %s: %s"), 65937c478bd9Sstevel@tonic-gate file, strerror(errno)); 65947c478bd9Sstevel@tonic-gate return (Z_ERR); 65957c478bd9Sstevel@tonic-gate } 65967c478bd9Sstevel@tonic-gate if ((err = fstat(fileno(infile), &statbuf)) != 0) { 65977c478bd9Sstevel@tonic-gate zerr(gettext("could not stat file %s: %s"), 65987c478bd9Sstevel@tonic-gate file, strerror(errno)); 65997c478bd9Sstevel@tonic-gate err = Z_ERR; 66007c478bd9Sstevel@tonic-gate goto done; 66017c478bd9Sstevel@tonic-gate } 66027c478bd9Sstevel@tonic-gate if (!S_ISREG(statbuf.st_mode)) { 66037c478bd9Sstevel@tonic-gate zerr(gettext("%s is not a regular file."), file); 66047c478bd9Sstevel@tonic-gate err = Z_ERR; 66057c478bd9Sstevel@tonic-gate goto done; 66067c478bd9Sstevel@tonic-gate } 66077c478bd9Sstevel@tonic-gate yyin = infile; 6608bbec428eSgjelinek cmd_file_mode = B_TRUE; 6609bbec428eSgjelinek ok_to_prompt = B_FALSE; 66107c478bd9Sstevel@tonic-gate } else { 66117c478bd9Sstevel@tonic-gate /* 66127c478bd9Sstevel@tonic-gate * "-f -" is essentially the same as interactive mode, 66137c478bd9Sstevel@tonic-gate * so treat it that way. 66147c478bd9Sstevel@tonic-gate */ 6615bbec428eSgjelinek interactive_mode = B_TRUE; 66167c478bd9Sstevel@tonic-gate } 66177c478bd9Sstevel@tonic-gate /* Z_REPEAT is for interactive mode; treat it like Z_ERR here. */ 66187c478bd9Sstevel@tonic-gate if ((err = read_input()) == Z_REPEAT) 66197c478bd9Sstevel@tonic-gate err = Z_ERR; 66207c478bd9Sstevel@tonic-gate done: 66217c478bd9Sstevel@tonic-gate if (using_real_file) 66227c478bd9Sstevel@tonic-gate (void) fclose(infile); 66237c478bd9Sstevel@tonic-gate return (err); 66247c478bd9Sstevel@tonic-gate } 66257c478bd9Sstevel@tonic-gate 66267c478bd9Sstevel@tonic-gate /* 66277c478bd9Sstevel@tonic-gate * Since yacc is based on reading from a (FILE *) whereas what we get from 66287c478bd9Sstevel@tonic-gate * the command line is in argv format, we need to convert when the user 66297c478bd9Sstevel@tonic-gate * gives us commands directly from the command line. That is done here by 66307c478bd9Sstevel@tonic-gate * concatenating the argv list into a space-separated string, writing it 66317c478bd9Sstevel@tonic-gate * to a temp file, and rewinding the file so yyin can be set to it. Then 66327c478bd9Sstevel@tonic-gate * we call read_input(), and only once, since prompting about whether to 66337c478bd9Sstevel@tonic-gate * continue or quit would make no sense in this context. 66347c478bd9Sstevel@tonic-gate */ 66357c478bd9Sstevel@tonic-gate 66367c478bd9Sstevel@tonic-gate static int 66377c478bd9Sstevel@tonic-gate one_command_at_a_time(int argc, char *argv[]) 66387c478bd9Sstevel@tonic-gate { 66397c478bd9Sstevel@tonic-gate char *command; 66407c478bd9Sstevel@tonic-gate size_t len = 2; /* terminal \n\0 */ 66417c478bd9Sstevel@tonic-gate int i, err; 66427c478bd9Sstevel@tonic-gate 66437c478bd9Sstevel@tonic-gate for (i = 0; i < argc; i++) 66447c478bd9Sstevel@tonic-gate len += strlen(argv[i]) + 1; 66457c478bd9Sstevel@tonic-gate if ((command = malloc(len)) == NULL) { 6646bbec428eSgjelinek zone_perror(execname, Z_NOMEM, B_TRUE); 66477c478bd9Sstevel@tonic-gate return (Z_ERR); 66487c478bd9Sstevel@tonic-gate } 66497c478bd9Sstevel@tonic-gate (void) strlcpy(command, argv[0], len); 66507c478bd9Sstevel@tonic-gate for (i = 1; i < argc; i++) { 66517c478bd9Sstevel@tonic-gate (void) strlcat(command, " ", len); 66527c478bd9Sstevel@tonic-gate (void) strlcat(command, argv[i], len); 66537c478bd9Sstevel@tonic-gate } 66547c478bd9Sstevel@tonic-gate (void) strlcat(command, "\n", len); 66557c478bd9Sstevel@tonic-gate err = string_to_yyin(command); 66567c478bd9Sstevel@tonic-gate free(command); 66577c478bd9Sstevel@tonic-gate if (err != Z_OK) 66587c478bd9Sstevel@tonic-gate return (err); 66597c478bd9Sstevel@tonic-gate while (!feof(yyin)) 66607c478bd9Sstevel@tonic-gate yyparse(); 66617c478bd9Sstevel@tonic-gate return (cleanup()); 66627c478bd9Sstevel@tonic-gate } 66637c478bd9Sstevel@tonic-gate 66647c478bd9Sstevel@tonic-gate static char * 66657c478bd9Sstevel@tonic-gate get_execbasename(char *execfullname) 66667c478bd9Sstevel@tonic-gate { 66677c478bd9Sstevel@tonic-gate char *last_slash, *execbasename; 66687c478bd9Sstevel@tonic-gate 66697c478bd9Sstevel@tonic-gate /* guard against '/' at end of command invocation */ 66707c478bd9Sstevel@tonic-gate for (;;) { 66717c478bd9Sstevel@tonic-gate last_slash = strrchr(execfullname, '/'); 66727c478bd9Sstevel@tonic-gate if (last_slash == NULL) { 66737c478bd9Sstevel@tonic-gate execbasename = execfullname; 66747c478bd9Sstevel@tonic-gate break; 66757c478bd9Sstevel@tonic-gate } else { 66767c478bd9Sstevel@tonic-gate execbasename = last_slash + 1; 66777c478bd9Sstevel@tonic-gate if (*execbasename == '\0') { 66787c478bd9Sstevel@tonic-gate *last_slash = '\0'; 66797c478bd9Sstevel@tonic-gate continue; 66807c478bd9Sstevel@tonic-gate } 66817c478bd9Sstevel@tonic-gate break; 66827c478bd9Sstevel@tonic-gate } 66837c478bd9Sstevel@tonic-gate } 66847c478bd9Sstevel@tonic-gate return (execbasename); 66857c478bd9Sstevel@tonic-gate } 66867c478bd9Sstevel@tonic-gate 66877c478bd9Sstevel@tonic-gate int 66887c478bd9Sstevel@tonic-gate main(int argc, char *argv[]) 66897c478bd9Sstevel@tonic-gate { 66907c478bd9Sstevel@tonic-gate int err, arg; 6691555afedfScarlsonj struct stat st; 66927c478bd9Sstevel@tonic-gate 66937c478bd9Sstevel@tonic-gate /* This must be before anything goes to stdout. */ 66947c478bd9Sstevel@tonic-gate setbuf(stdout, NULL); 66957c478bd9Sstevel@tonic-gate 6696bbec428eSgjelinek saw_error = B_FALSE; 6697bbec428eSgjelinek cmd_file_mode = B_FALSE; 66987c478bd9Sstevel@tonic-gate execname = get_execbasename(argv[0]); 66997c478bd9Sstevel@tonic-gate 67007c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 67017c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 67027c478bd9Sstevel@tonic-gate 67037c478bd9Sstevel@tonic-gate if (getzoneid() != GLOBAL_ZONEID) { 67047c478bd9Sstevel@tonic-gate zerr(gettext("%s can only be run from the global zone."), 67057c478bd9Sstevel@tonic-gate execname); 67067c478bd9Sstevel@tonic-gate exit(Z_ERR); 67077c478bd9Sstevel@tonic-gate } 67087c478bd9Sstevel@tonic-gate 67097c478bd9Sstevel@tonic-gate if (argc < 2) { 6710bbec428eSgjelinek usage(B_FALSE, HELP_USAGE | HELP_SUBCMDS); 67117c478bd9Sstevel@tonic-gate exit(Z_USAGE); 67127c478bd9Sstevel@tonic-gate } 67137c478bd9Sstevel@tonic-gate if (strcmp(argv[1], cmd_to_str(CMD_HELP)) == 0) { 67147c478bd9Sstevel@tonic-gate (void) one_command_at_a_time(argc - 1, &(argv[1])); 67157c478bd9Sstevel@tonic-gate exit(Z_OK); 67167c478bd9Sstevel@tonic-gate } 67177c478bd9Sstevel@tonic-gate 6718555afedfScarlsonj while ((arg = getopt(argc, argv, "?f:R:z:")) != EOF) { 67197c478bd9Sstevel@tonic-gate switch (arg) { 67207c478bd9Sstevel@tonic-gate case '?': 67217c478bd9Sstevel@tonic-gate if (optopt == '?') 6722bbec428eSgjelinek usage(B_TRUE, HELP_USAGE | HELP_SUBCMDS); 67237c478bd9Sstevel@tonic-gate else 6724bbec428eSgjelinek usage(B_FALSE, HELP_USAGE); 67257c478bd9Sstevel@tonic-gate exit(Z_USAGE); 67267c478bd9Sstevel@tonic-gate /* NOTREACHED */ 67277c478bd9Sstevel@tonic-gate case 'f': 67287c478bd9Sstevel@tonic-gate cmd_file_name = optarg; 6729bbec428eSgjelinek cmd_file_mode = B_TRUE; 67307c478bd9Sstevel@tonic-gate break; 6731555afedfScarlsonj case 'R': 6732555afedfScarlsonj if (*optarg != '/') { 6733555afedfScarlsonj zerr(gettext("root path must be absolute: %s"), 6734555afedfScarlsonj optarg); 6735555afedfScarlsonj exit(Z_USAGE); 6736555afedfScarlsonj } 6737555afedfScarlsonj if (stat(optarg, &st) == -1 || !S_ISDIR(st.st_mode)) { 6738555afedfScarlsonj zerr(gettext( 6739555afedfScarlsonj "root path must be a directory: %s"), 6740555afedfScarlsonj optarg); 6741555afedfScarlsonj exit(Z_USAGE); 6742555afedfScarlsonj } 6743555afedfScarlsonj zonecfg_set_root(optarg); 6744555afedfScarlsonj break; 67457c478bd9Sstevel@tonic-gate case 'z': 67460209230bSgjelinek if (strcmp(optarg, GLOBAL_ZONENAME) == 0) { 6747bbec428eSgjelinek global_zone = B_TRUE; 67480209230bSgjelinek } else if (zonecfg_validate_zonename(optarg) != Z_OK) { 6749bbec428eSgjelinek zone_perror(optarg, Z_BOGUS_ZONE_NAME, B_TRUE); 6750bbec428eSgjelinek usage(B_FALSE, HELP_SYNTAX); 6751087719fdSdp exit(Z_USAGE); 6752087719fdSdp } 6753087719fdSdp (void) strlcpy(zone, optarg, sizeof (zone)); 6754087719fdSdp (void) strlcpy(revert_zone, optarg, sizeof (zone)); 67557c478bd9Sstevel@tonic-gate break; 67567c478bd9Sstevel@tonic-gate default: 6757bbec428eSgjelinek usage(B_FALSE, HELP_USAGE); 67587c478bd9Sstevel@tonic-gate exit(Z_USAGE); 67597c478bd9Sstevel@tonic-gate } 67607c478bd9Sstevel@tonic-gate } 67617c478bd9Sstevel@tonic-gate 6762087719fdSdp if (optind > argc || strcmp(zone, "") == 0) { 6763bbec428eSgjelinek usage(B_FALSE, HELP_USAGE); 67647c478bd9Sstevel@tonic-gate exit(Z_USAGE); 67657c478bd9Sstevel@tonic-gate } 67667c478bd9Sstevel@tonic-gate 6767087719fdSdp if ((err = zonecfg_access(zone, W_OK)) == Z_OK) { 6768bbec428eSgjelinek read_only_mode = B_FALSE; 6769087719fdSdp } else if (err == Z_ACCES) { 6770bbec428eSgjelinek read_only_mode = B_TRUE; 67717c478bd9Sstevel@tonic-gate /* skip this message in one-off from command line mode */ 67727c478bd9Sstevel@tonic-gate if (optind == argc) 67737c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("WARNING: you do not " 67747c478bd9Sstevel@tonic-gate "have write access to this zone's configuration " 67757c478bd9Sstevel@tonic-gate "file;\ngoing into read-only mode.\n")); 6776087719fdSdp } else { 6777087719fdSdp fprintf(stderr, "%s: Could not access zone configuration " 6778087719fdSdp "store: %s\n", execname, zonecfg_strerror(err)); 6779087719fdSdp exit(Z_ERR); 67807c478bd9Sstevel@tonic-gate } 67817c478bd9Sstevel@tonic-gate 67827c478bd9Sstevel@tonic-gate if ((handle = zonecfg_init_handle()) == NULL) { 6783bbec428eSgjelinek zone_perror(execname, Z_NOMEM, B_TRUE); 67847c478bd9Sstevel@tonic-gate exit(Z_ERR); 67857c478bd9Sstevel@tonic-gate } 67867c478bd9Sstevel@tonic-gate 67877c478bd9Sstevel@tonic-gate /* 67887c478bd9Sstevel@tonic-gate * This may get set back to FALSE again in cmd_file() if cmd_file_name 67897c478bd9Sstevel@tonic-gate * is a "real" file as opposed to "-" (i.e. meaning use stdin). 67907c478bd9Sstevel@tonic-gate */ 67917c478bd9Sstevel@tonic-gate if (isatty(STDIN_FILENO)) 6792bbec428eSgjelinek ok_to_prompt = B_TRUE; 67937c478bd9Sstevel@tonic-gate if ((gl = new_GetLine(MAX_LINE_LEN, MAX_CMD_HIST)) == NULL) 67947c478bd9Sstevel@tonic-gate exit(Z_ERR); 67957c478bd9Sstevel@tonic-gate if (gl_customize_completion(gl, NULL, cmd_cpl_fn) != 0) 67967c478bd9Sstevel@tonic-gate exit(Z_ERR); 67977c478bd9Sstevel@tonic-gate (void) sigset(SIGINT, SIG_IGN); 67987c478bd9Sstevel@tonic-gate if (optind == argc) { 67997c478bd9Sstevel@tonic-gate if (!cmd_file_mode) 68007c478bd9Sstevel@tonic-gate err = do_interactive(); 68017c478bd9Sstevel@tonic-gate else 68027c478bd9Sstevel@tonic-gate err = cmd_file(cmd_file_name); 68037c478bd9Sstevel@tonic-gate } else { 68047c478bd9Sstevel@tonic-gate err = one_command_at_a_time(argc - optind, &(argv[optind])); 68057c478bd9Sstevel@tonic-gate } 68067c478bd9Sstevel@tonic-gate zonecfg_fini_handle(handle); 68079acbbeafSnn35248 if (brand != NULL) 68089acbbeafSnn35248 brand_close(brand); 68097c478bd9Sstevel@tonic-gate (void) del_GetLine(gl); 68107c478bd9Sstevel@tonic-gate return (err); 68117c478bd9Sstevel@tonic-gate } 6812