10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51676Sjpk * Common Development and Distribution License (the "License"). 61676Sjpk * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 2212273SCasper.Dik@Sun.COM * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. 230Sstevel@tonic-gate */ 240Sstevel@tonic-gate 250Sstevel@tonic-gate #ifndef _SYS_ZONE_H 260Sstevel@tonic-gate #define _SYS_ZONE_H 270Sstevel@tonic-gate 280Sstevel@tonic-gate #include <sys/types.h> 290Sstevel@tonic-gate #include <sys/mutex.h> 300Sstevel@tonic-gate #include <sys/param.h> 310Sstevel@tonic-gate #include <sys/rctl.h> 322677Sml93401 #include <sys/ipc_rctl.h> 330Sstevel@tonic-gate #include <sys/pset.h> 341676Sjpk #include <sys/tsol/label.h> 353448Sdh155122 #include <sys/cred.h> 363448Sdh155122 #include <sys/netstack.h> 372267Sdp #include <sys/uadmin.h> 3810910SRobert.Harris@Sun.COM #include <sys/ksynch.h> 390Sstevel@tonic-gate 400Sstevel@tonic-gate #ifdef __cplusplus 410Sstevel@tonic-gate extern "C" { 420Sstevel@tonic-gate #endif 430Sstevel@tonic-gate 440Sstevel@tonic-gate /* 450Sstevel@tonic-gate * NOTE 460Sstevel@tonic-gate * 470Sstevel@tonic-gate * The contents of this file are private to the implementation of 480Sstevel@tonic-gate * Solaris and are subject to change at any time without notice. 490Sstevel@tonic-gate * Applications and drivers using these interfaces may fail to 500Sstevel@tonic-gate * run on future releases. 510Sstevel@tonic-gate */ 520Sstevel@tonic-gate 530Sstevel@tonic-gate /* Available both in kernel and for user space */ 540Sstevel@tonic-gate 550Sstevel@tonic-gate /* zone id restrictions and special ids */ 560Sstevel@tonic-gate #define MAX_ZONEID 9999 570Sstevel@tonic-gate #define MIN_USERZONEID 1 /* lowest user-creatable zone ID */ 580Sstevel@tonic-gate #define MIN_ZONEID 0 /* minimum zone ID on system */ 590Sstevel@tonic-gate #define GLOBAL_ZONEID 0 600Sstevel@tonic-gate #define ZONEID_WIDTH 4 /* for printf */ 610Sstevel@tonic-gate 621676Sjpk /* 631676Sjpk * Special zoneid_t token to refer to all zones. 641676Sjpk */ 651676Sjpk #define ALL_ZONES (-1) 661676Sjpk 670Sstevel@tonic-gate /* system call subcodes */ 683448Sdh155122 #define ZONE_CREATE 0 693448Sdh155122 #define ZONE_DESTROY 1 703448Sdh155122 #define ZONE_GETATTR 2 713448Sdh155122 #define ZONE_ENTER 3 723448Sdh155122 #define ZONE_LIST 4 733448Sdh155122 #define ZONE_SHUTDOWN 5 743448Sdh155122 #define ZONE_LOOKUP 6 753448Sdh155122 #define ZONE_BOOT 7 763448Sdh155122 #define ZONE_VERSION 8 773448Sdh155122 #define ZONE_SETATTR 9 783448Sdh155122 #define ZONE_ADD_DATALINK 10 793448Sdh155122 #define ZONE_DEL_DATALINK 11 803448Sdh155122 #define ZONE_CHECK_DATALINK 12 813448Sdh155122 #define ZONE_LIST_DATALINK 13 820Sstevel@tonic-gate 830Sstevel@tonic-gate /* zone attributes */ 840Sstevel@tonic-gate #define ZONE_ATTR_ROOT 1 850Sstevel@tonic-gate #define ZONE_ATTR_NAME 2 860Sstevel@tonic-gate #define ZONE_ATTR_STATUS 3 870Sstevel@tonic-gate #define ZONE_ATTR_PRIVSET 4 880Sstevel@tonic-gate #define ZONE_ATTR_UNIQID 5 890Sstevel@tonic-gate #define ZONE_ATTR_POOLID 6 900Sstevel@tonic-gate #define ZONE_ATTR_INITPID 7 911676Sjpk #define ZONE_ATTR_SLBL 8 922267Sdp #define ZONE_ATTR_INITNAME 9 932267Sdp #define ZONE_ATTR_BOOTARGS 10 942712Snn35248 #define ZONE_ATTR_BRAND 11 953247Sgjelinek #define ZONE_ATTR_PHYS_MCAP 12 963247Sgjelinek #define ZONE_ATTR_SCHED_CLASS 13 973448Sdh155122 #define ZONE_ATTR_FLAGS 14 988662SJordan.Vaughan@Sun.com #define ZONE_ATTR_HOSTID 15 9912633Sjohn.levon@sun.com #define ZONE_ATTR_FS_ALLOWED 16 1002712Snn35248 1012712Snn35248 /* Start of the brand-specific attribute namespace */ 1022712Snn35248 #define ZONE_ATTR_BRAND_ATTRS 32768 1030Sstevel@tonic-gate 10412633Sjohn.levon@sun.com #define ZONE_FS_ALLOWED_MAX 1024 10512633Sjohn.levon@sun.com 1061166Sdstaff #define ZONE_EVENT_CHANNEL "com.sun:zones:status" 1071166Sdstaff #define ZONE_EVENT_STATUS_CLASS "status" 1081166Sdstaff #define ZONE_EVENT_STATUS_SUBCLASS "change" 1091166Sdstaff 1101166Sdstaff #define ZONE_EVENT_UNINITIALIZED "uninitialized" 1115880Snordmark #define ZONE_EVENT_INITIALIZED "initialized" 1121166Sdstaff #define ZONE_EVENT_READY "ready" 1131166Sdstaff #define ZONE_EVENT_RUNNING "running" 1141166Sdstaff #define ZONE_EVENT_SHUTTING_DOWN "shutting_down" 1151166Sdstaff 1161166Sdstaff #define ZONE_CB_NAME "zonename" 1171166Sdstaff #define ZONE_CB_NEWSTATE "newstate" 1181166Sdstaff #define ZONE_CB_OLDSTATE "oldstate" 1191166Sdstaff #define ZONE_CB_TIMESTAMP "when" 1201166Sdstaff #define ZONE_CB_ZONEID "zoneid" 1211166Sdstaff 1222712Snn35248 /* 1232712Snn35248 * Exit values that may be returned by scripts or programs invoked by various 1242712Snn35248 * zone commands. 1252712Snn35248 * 1262712Snn35248 * These are defined as: 1272712Snn35248 * 1282712Snn35248 * ZONE_SUBPROC_OK 1292712Snn35248 * =============== 1302712Snn35248 * The subprocess completed successfully. 1312712Snn35248 * 1322712Snn35248 * ZONE_SUBPROC_USAGE 1332712Snn35248 * ================== 1342712Snn35248 * The subprocess failed with a usage message, or a usage message should 1352712Snn35248 * be output in its behalf. 1362712Snn35248 * 1372712Snn35248 * ZONE_SUBPROC_NOTCOMPLETE 1382712Snn35248 * ======================== 1392712Snn35248 * The subprocess did not complete, but the actions performed by the 1402712Snn35248 * subprocess require no recovery actions by the user. 1412712Snn35248 * 1422712Snn35248 * For example, if the subprocess were called by "zoneadm install," the 1432712Snn35248 * installation of the zone did not succeed but the user need not perform 1442712Snn35248 * a "zoneadm uninstall" before attempting another install. 1452712Snn35248 * 1462712Snn35248 * ZONE_SUBPROC_FATAL 1472712Snn35248 * ================== 1482712Snn35248 * The subprocess failed in a fatal manner, usually one that will require 1492712Snn35248 * some type of recovery action by the user. 1502712Snn35248 * 1512712Snn35248 * For example, if the subprocess were called by "zoneadm install," the 1522712Snn35248 * installation of the zone did not succeed and the user will need to 1532712Snn35248 * perform a "zoneadm uninstall" before another install attempt is 1542712Snn35248 * possible. 1552712Snn35248 * 1562712Snn35248 * The non-success exit values are large to avoid accidental collision 1572712Snn35248 * with values used internally by some commands (e.g. "Z_ERR" and 1582712Snn35248 * "Z_USAGE" as used by zoneadm.) 1592712Snn35248 */ 1602712Snn35248 #define ZONE_SUBPROC_OK 0 1612712Snn35248 #define ZONE_SUBPROC_USAGE 253 1622712Snn35248 #define ZONE_SUBPROC_NOTCOMPLETE 254 1632712Snn35248 #define ZONE_SUBPROC_FATAL 255 1642712Snn35248 1650Sstevel@tonic-gate #ifdef _SYSCALL32 1660Sstevel@tonic-gate typedef struct { 1670Sstevel@tonic-gate caddr32_t zone_name; 1680Sstevel@tonic-gate caddr32_t zone_root; 1690Sstevel@tonic-gate caddr32_t zone_privs; 170813Sdp size32_t zone_privssz; 1710Sstevel@tonic-gate caddr32_t rctlbuf; 1720Sstevel@tonic-gate size32_t rctlbufsz; 1730Sstevel@tonic-gate caddr32_t extended_error; 174789Sahrens caddr32_t zfsbuf; 175789Sahrens size32_t zfsbufsz; 1762110Srica int match; /* match level */ 1772110Srica uint32_t doi; /* DOI for label */ 1782110Srica caddr32_t label; /* label associated with zone */ 1793448Sdh155122 int flags; 1800Sstevel@tonic-gate } zone_def32; 1810Sstevel@tonic-gate #endif 1820Sstevel@tonic-gate typedef struct { 1830Sstevel@tonic-gate const char *zone_name; 1840Sstevel@tonic-gate const char *zone_root; 1850Sstevel@tonic-gate const struct priv_set *zone_privs; 186813Sdp size_t zone_privssz; 1870Sstevel@tonic-gate const char *rctlbuf; 1880Sstevel@tonic-gate size_t rctlbufsz; 1890Sstevel@tonic-gate int *extended_error; 190789Sahrens const char *zfsbuf; 191789Sahrens size_t zfsbufsz; 1921676Sjpk int match; /* match level */ 1932110Srica uint32_t doi; /* DOI for label */ 1941676Sjpk const bslabel_t *label; /* label associated with zone */ 1953448Sdh155122 int flags; 1960Sstevel@tonic-gate } zone_def; 1970Sstevel@tonic-gate 1980Sstevel@tonic-gate /* extended error information */ 1990Sstevel@tonic-gate #define ZE_UNKNOWN 0 /* No extended error info */ 2000Sstevel@tonic-gate #define ZE_CHROOTED 1 /* tried to zone_create from chroot */ 2010Sstevel@tonic-gate #define ZE_AREMOUNTS 2 /* there are mounts within the zone */ 2024791Ston #define ZE_LABELINUSE 3 /* label is already in use by some other zone */ 2030Sstevel@tonic-gate 2040Sstevel@tonic-gate /* zone_status */ 2050Sstevel@tonic-gate typedef enum { 2060Sstevel@tonic-gate ZONE_IS_UNINITIALIZED = 0, 2075880Snordmark ZONE_IS_INITIALIZED, 2080Sstevel@tonic-gate ZONE_IS_READY, 2090Sstevel@tonic-gate ZONE_IS_BOOTING, 2100Sstevel@tonic-gate ZONE_IS_RUNNING, 2110Sstevel@tonic-gate ZONE_IS_SHUTTING_DOWN, 2120Sstevel@tonic-gate ZONE_IS_EMPTY, 2130Sstevel@tonic-gate ZONE_IS_DOWN, 2140Sstevel@tonic-gate ZONE_IS_DYING, 2150Sstevel@tonic-gate ZONE_IS_DEAD 2160Sstevel@tonic-gate } zone_status_t; 2170Sstevel@tonic-gate #define ZONE_MIN_STATE ZONE_IS_UNINITIALIZED 2180Sstevel@tonic-gate #define ZONE_MAX_STATE ZONE_IS_DEAD 2190Sstevel@tonic-gate 2200Sstevel@tonic-gate /* 2210Sstevel@tonic-gate * Valid commands which may be issued by zoneadm to zoneadmd. The kernel also 2220Sstevel@tonic-gate * communicates with zoneadmd, but only uses Z_REBOOT and Z_HALT. 2230Sstevel@tonic-gate */ 2240Sstevel@tonic-gate typedef enum zone_cmd { 2252712Snn35248 Z_READY, Z_BOOT, Z_FORCEBOOT, Z_REBOOT, Z_HALT, Z_NOTE_UNINSTALLING, 2262712Snn35248 Z_MOUNT, Z_FORCEMOUNT, Z_UNMOUNT 2270Sstevel@tonic-gate } zone_cmd_t; 2280Sstevel@tonic-gate 2290Sstevel@tonic-gate /* 2300Sstevel@tonic-gate * The structure of a request to zoneadmd. 2310Sstevel@tonic-gate */ 2320Sstevel@tonic-gate typedef struct zone_cmd_arg { 2330Sstevel@tonic-gate uint64_t uniqid; /* unique "generation number" */ 2340Sstevel@tonic-gate zone_cmd_t cmd; /* requested action */ 2352267Sdp uint32_t _pad; /* need consistent 32/64 bit alignmt */ 2360Sstevel@tonic-gate char locale[MAXPATHLEN]; /* locale in which to render messages */ 2372267Sdp char bootbuf[BOOTARGS_MAX]; /* arguments passed to zone_boot() */ 2380Sstevel@tonic-gate } zone_cmd_arg_t; 2390Sstevel@tonic-gate 2400Sstevel@tonic-gate /* 2410Sstevel@tonic-gate * Structure of zoneadmd's response to a request. A NULL return value means 2420Sstevel@tonic-gate * the caller should attempt to restart zoneadmd and retry. 2430Sstevel@tonic-gate */ 2440Sstevel@tonic-gate typedef struct zone_cmd_rval { 2450Sstevel@tonic-gate int rval; /* return value of request */ 2460Sstevel@tonic-gate char errbuf[1]; /* variable-sized buffer containing error messages */ 2470Sstevel@tonic-gate } zone_cmd_rval_t; 2480Sstevel@tonic-gate 2490Sstevel@tonic-gate /* 2500Sstevel@tonic-gate * The zone support infrastructure uses the zone name as a component 2510Sstevel@tonic-gate * of unix domain (AF_UNIX) sockets, which are limited to 108 characters 2520Sstevel@tonic-gate * in length, so ZONENAME_MAX is limited by that. 2530Sstevel@tonic-gate */ 2540Sstevel@tonic-gate #define ZONENAME_MAX 64 2550Sstevel@tonic-gate 2560Sstevel@tonic-gate #define GLOBAL_ZONENAME "global" 2570Sstevel@tonic-gate 2580Sstevel@tonic-gate /* 2590Sstevel@tonic-gate * Extended Regular expression (see regex(5)) which matches all valid zone 2600Sstevel@tonic-gate * names. 2610Sstevel@tonic-gate */ 2620Sstevel@tonic-gate #define ZONENAME_REGEXP "[a-zA-Z0-9][-_.a-zA-Z0-9]{0,62}" 2630Sstevel@tonic-gate 2640Sstevel@tonic-gate /* 2650Sstevel@tonic-gate * Where the zones support infrastructure places temporary files. 2660Sstevel@tonic-gate */ 2670Sstevel@tonic-gate #define ZONES_TMPDIR "/var/run/zones" 2680Sstevel@tonic-gate 2690Sstevel@tonic-gate /* 2700Sstevel@tonic-gate * The path to the door used by clients to communicate with zoneadmd. 2710Sstevel@tonic-gate */ 2720Sstevel@tonic-gate #define ZONE_DOOR_PATH ZONES_TMPDIR "/%s.zoneadmd_door" 2730Sstevel@tonic-gate 2743448Sdh155122 /* zone_flags */ 2753448Sdh155122 #define ZF_HASHED_LABEL 0x2 /* zone has a unique label */ 2763448Sdh155122 #define ZF_IS_SCRATCH 0x4 /* scratch zone */ 2773448Sdh155122 #define ZF_NET_EXCL 0x8 /* Zone has an exclusive IP stack */ 2783448Sdh155122 2793448Sdh155122 /* zone_create flags */ 2803448Sdh155122 #define ZCF_NET_EXCL 0x1 /* Create a zone with exclusive IP */ 2813448Sdh155122 2820Sstevel@tonic-gate #ifdef _KERNEL 2830Sstevel@tonic-gate /* 2840Sstevel@tonic-gate * We need to protect the definition of 'list_t' from userland applications and 2850Sstevel@tonic-gate * libraries which may be defining ther own versions. 2860Sstevel@tonic-gate */ 2870Sstevel@tonic-gate #include <sys/list.h> 2880Sstevel@tonic-gate 2890Sstevel@tonic-gate #define GLOBAL_ZONEUNIQID 0 /* uniqid of the global zone */ 2900Sstevel@tonic-gate 2910Sstevel@tonic-gate struct pool; 2922712Snn35248 struct brand; 2930Sstevel@tonic-gate 294789Sahrens /* 295789Sahrens * Structure to record list of ZFS datasets exported to a zone. 296789Sahrens */ 297789Sahrens typedef struct zone_dataset { 298789Sahrens char *zd_dataset; 299789Sahrens list_node_t zd_linkage; 300789Sahrens } zone_dataset_t; 301789Sahrens 3023247Sgjelinek /* 3033247Sgjelinek * structure for zone kstats 3043247Sgjelinek */ 3053247Sgjelinek typedef struct zone_kstat { 3063247Sgjelinek kstat_named_t zk_zonename; 3073247Sgjelinek kstat_named_t zk_usage; 3083247Sgjelinek kstat_named_t zk_value; 3093247Sgjelinek } zone_kstat_t; 3103247Sgjelinek 3113792Sakolb struct cpucap; 3123792Sakolb 3130Sstevel@tonic-gate typedef struct zone { 3140Sstevel@tonic-gate /* 3150Sstevel@tonic-gate * zone_name is never modified once set. 3160Sstevel@tonic-gate */ 3170Sstevel@tonic-gate char *zone_name; /* zone's configuration name */ 3180Sstevel@tonic-gate /* 3190Sstevel@tonic-gate * zone_nodename and zone_domain are never freed once allocated. 3200Sstevel@tonic-gate */ 3210Sstevel@tonic-gate char *zone_nodename; /* utsname.nodename equivalent */ 3220Sstevel@tonic-gate char *zone_domain; /* srpc_domain equivalent */ 3230Sstevel@tonic-gate /* 3248662SJordan.Vaughan@Sun.com * zone_hostid is used for per-zone hostid emulation. 3258662SJordan.Vaughan@Sun.com * Currently it isn't modified after it's set (so no locks protect 3268662SJordan.Vaughan@Sun.com * accesses), but that might have to change when we allow 3278662SJordan.Vaughan@Sun.com * administrators to change running zones' properties. 3288662SJordan.Vaughan@Sun.com * 3298662SJordan.Vaughan@Sun.com * The global zone's zone_hostid must always be HW_INVALID_HOSTID so 3308662SJordan.Vaughan@Sun.com * that zone_get_hostid() will function correctly. 3318662SJordan.Vaughan@Sun.com */ 3328662SJordan.Vaughan@Sun.com uint32_t zone_hostid; /* zone's hostid, HW_INVALID_HOSTID */ 3338662SJordan.Vaughan@Sun.com /* if not emulated */ 3348662SJordan.Vaughan@Sun.com /* 3350Sstevel@tonic-gate * zone_lock protects the following fields of a zone_t: 3360Sstevel@tonic-gate * zone_ref 3370Sstevel@tonic-gate * zone_cred_ref 3380Sstevel@tonic-gate * zone_ntasks 3390Sstevel@tonic-gate * zone_flags 3400Sstevel@tonic-gate * zone_zsd 34112273SCasper.Dik@Sun.COM * zone_pfexecd 3420Sstevel@tonic-gate */ 3430Sstevel@tonic-gate kmutex_t zone_lock; 3440Sstevel@tonic-gate /* 3450Sstevel@tonic-gate * zone_linkage is the zone's linkage into the active or 3460Sstevel@tonic-gate * death-row list. The field is protected by zonehash_lock. 3470Sstevel@tonic-gate */ 3480Sstevel@tonic-gate list_node_t zone_linkage; 3490Sstevel@tonic-gate zoneid_t zone_id; /* ID of zone */ 3500Sstevel@tonic-gate uint_t zone_ref; /* count of zone_hold()s on zone */ 3510Sstevel@tonic-gate uint_t zone_cred_ref; /* count of zone_hold_cred()s on zone */ 3520Sstevel@tonic-gate /* 3530Sstevel@tonic-gate * zone_rootvp and zone_rootpath can never be modified once set. 3540Sstevel@tonic-gate */ 3550Sstevel@tonic-gate struct vnode *zone_rootvp; /* zone's root vnode */ 3560Sstevel@tonic-gate char *zone_rootpath; /* Path to zone's root + '/' */ 3570Sstevel@tonic-gate ushort_t zone_flags; /* misc flags */ 3580Sstevel@tonic-gate zone_status_t zone_status; /* protected by zone_status_lock */ 3590Sstevel@tonic-gate uint_t zone_ntasks; /* number of tasks executing in zone */ 3600Sstevel@tonic-gate kmutex_t zone_nlwps_lock; /* protects zone_nlwps, and *_nlwps */ 3610Sstevel@tonic-gate /* counters in projects and tasks */ 3620Sstevel@tonic-gate /* that are within the zone */ 3630Sstevel@tonic-gate rctl_qty_t zone_nlwps; /* number of lwps in zone */ 3640Sstevel@tonic-gate rctl_qty_t zone_nlwps_ctl; /* protected by zone_rctls->rcs_lock */ 3652677Sml93401 rctl_qty_t zone_shmmax; /* System V shared memory usage */ 3662677Sml93401 ipc_rqty_t zone_ipc; /* System V IPC id resource usage */ 3670Sstevel@tonic-gate 3680Sstevel@tonic-gate uint_t zone_rootpathlen; /* strlen(zone_rootpath) + 1 */ 3690Sstevel@tonic-gate uint32_t zone_shares; /* FSS shares allocated to zone */ 3700Sstevel@tonic-gate rctl_set_t *zone_rctls; /* zone-wide (zone.*) rctls */ 3713247Sgjelinek kmutex_t zone_mem_lock; /* protects zone_locked_mem and */ 3722768Ssl108498 /* kpd_locked_mem for all */ 3733247Sgjelinek /* projects in zone. */ 3743247Sgjelinek /* Also protects zone_max_swap */ 3752768Ssl108498 /* grab after p_lock, before rcs_lock */ 3763247Sgjelinek rctl_qty_t zone_locked_mem; /* bytes of locked memory in */ 3773247Sgjelinek /* zone */ 3783247Sgjelinek rctl_qty_t zone_locked_mem_ctl; /* Current locked memory */ 3792768Ssl108498 /* limit. Protected by */ 3802768Ssl108498 /* zone_rctls->rcs_lock */ 3813247Sgjelinek rctl_qty_t zone_max_swap; /* bytes of swap reserved by zone */ 3823247Sgjelinek rctl_qty_t zone_max_swap_ctl; /* current swap limit. */ 3833247Sgjelinek /* Protected by */ 3843247Sgjelinek /* zone_rctls->rcs_lock */ 38512633Sjohn.levon@sun.com kmutex_t zone_rctl_lock; /* protects zone_max_lofi */ 38612633Sjohn.levon@sun.com rctl_qty_t zone_max_lofi; /* lofi devs for zone */ 38712633Sjohn.levon@sun.com rctl_qty_t zone_max_lofi_ctl; /* current lofi limit. */ 38812633Sjohn.levon@sun.com /* Protected by */ 38912633Sjohn.levon@sun.com /* zone_rctls->rcs_lock */ 3900Sstevel@tonic-gate list_t zone_zsd; /* list of Zone-Specific Data values */ 3910Sstevel@tonic-gate kcondvar_t zone_cv; /* used to signal state changes */ 3920Sstevel@tonic-gate struct proc *zone_zsched; /* Dummy kernel "zsched" process */ 3930Sstevel@tonic-gate pid_t zone_proc_initpid; /* pid of "init" for this zone */ 3942267Sdp char *zone_initname; /* fs path to 'init' */ 3950Sstevel@tonic-gate int zone_boot_err; /* for zone_boot() if boot fails */ 3960Sstevel@tonic-gate char *zone_bootargs; /* arguments passed via zone_boot() */ 3973247Sgjelinek uint64_t zone_phys_mcap; /* physical memory cap */ 3980Sstevel@tonic-gate /* 3990Sstevel@tonic-gate * zone_kthreads is protected by zone_status_lock. 4000Sstevel@tonic-gate */ 4010Sstevel@tonic-gate kthread_t *zone_kthreads; /* kernel threads in zone */ 4020Sstevel@tonic-gate struct priv_set *zone_privset; /* limit set for zone */ 4030Sstevel@tonic-gate /* 4040Sstevel@tonic-gate * zone_vfslist is protected by vfs_list_lock(). 4050Sstevel@tonic-gate */ 4060Sstevel@tonic-gate struct vfs *zone_vfslist; /* list of FS's mounted in zone */ 4070Sstevel@tonic-gate uint64_t zone_uniqid; /* unique zone generation number */ 4080Sstevel@tonic-gate struct cred *zone_kcred; /* kcred-like, zone-limited cred */ 4090Sstevel@tonic-gate /* 4100Sstevel@tonic-gate * zone_pool is protected by pool_lock(). 4110Sstevel@tonic-gate */ 4120Sstevel@tonic-gate struct pool *zone_pool; /* pool the zone is bound to */ 4130Sstevel@tonic-gate hrtime_t zone_pool_mod; /* last pool bind modification time */ 4140Sstevel@tonic-gate /* zone_psetid is protected by cpu_lock */ 4150Sstevel@tonic-gate psetid_t zone_psetid; /* pset the zone is bound to */ 4160Sstevel@tonic-gate /* 4170Sstevel@tonic-gate * The following two can be read without holding any locks. They are 4180Sstevel@tonic-gate * updated under cpu_lock. 4190Sstevel@tonic-gate */ 4200Sstevel@tonic-gate int zone_ncpus; /* zone's idea of ncpus */ 4210Sstevel@tonic-gate int zone_ncpus_online; /* zone's idea of ncpus_online */ 422789Sahrens /* 423789Sahrens * List of ZFS datasets exported to this zone. 424789Sahrens */ 425789Sahrens list_t zone_datasets; /* list of datasets */ 4261676Sjpk 4272110Srica ts_label_t *zone_slabel; /* zone sensitivity label */ 4282110Srica int zone_match; /* require label match for packets */ 4291676Sjpk tsol_mlp_list_t zone_mlps; /* MLPs on zone-private addresses */ 4302267Sdp 4312712Snn35248 boolean_t zone_restart_init; /* Restart init if it dies? */ 4322712Snn35248 struct brand *zone_brand; /* zone's brand */ 4334888Seh208807 void *zone_brand_data; /* store brand specific data */ 4343247Sgjelinek id_t zone_defaultcid; /* dflt scheduling class id */ 4353247Sgjelinek kstat_t *zone_swapresv_kstat; 4363247Sgjelinek kstat_t *zone_lockedmem_kstat; 4373448Sdh155122 /* 4383448Sdh155122 * zone_dl_list is protected by zone_lock 4393448Sdh155122 */ 44010616SSebastien.Roy@Sun.COM list_t zone_dl_list; 4413448Sdh155122 netstack_t *zone_netstack; 4423792Sakolb struct cpucap *zone_cpucap; /* CPU caps data */ 4434197Spaulson /* 4444197Spaulson * Solaris Auditing per-zone audit context 4454197Spaulson */ 4464197Spaulson struct au_kcontext *zone_audit_kctxt; 44710910SRobert.Harris@Sun.COM /* 44810910SRobert.Harris@Sun.COM * For private use by mntfs. 44910910SRobert.Harris@Sun.COM */ 45010910SRobert.Harris@Sun.COM struct mntelem *zone_mntfs_db; 45110910SRobert.Harris@Sun.COM krwlock_t zone_mntfs_db_lock; 45212273SCasper.Dik@Sun.COM 45312273SCasper.Dik@Sun.COM struct klpd_reg *zone_pfexecd; 45412633Sjohn.levon@sun.com 45512633Sjohn.levon@sun.com char *zone_fs_allowed; 456*12725SMenno.Lageman@Sun.COM rctl_qty_t zone_nprocs; /* number of processes in the zone */ 457*12725SMenno.Lageman@Sun.COM rctl_qty_t zone_nprocs_ctl; /* current limit protected by */ 458*12725SMenno.Lageman@Sun.COM /* zone_rctls->rcs_lock */ 459*12725SMenno.Lageman@Sun.COM kstat_t *zone_nprocs_kstat; 4600Sstevel@tonic-gate } zone_t; 4610Sstevel@tonic-gate 4620Sstevel@tonic-gate /* 4630Sstevel@tonic-gate * Special value of zone_psetid to indicate that pools are disabled. 4640Sstevel@tonic-gate */ 4650Sstevel@tonic-gate #define ZONE_PS_INVAL PS_MYID 4660Sstevel@tonic-gate 4673448Sdh155122 4680Sstevel@tonic-gate extern zone_t zone0; 4690Sstevel@tonic-gate extern zone_t *global_zone; 4700Sstevel@tonic-gate extern uint_t maxzones; 4710Sstevel@tonic-gate extern rctl_hndl_t rc_zone_nlwps; 472*12725SMenno.Lageman@Sun.COM extern rctl_hndl_t rc_zone_nprocs; 4730Sstevel@tonic-gate 474789Sahrens extern long zone(int, void *, void *, void *, void *); 4750Sstevel@tonic-gate extern void zone_zsd_init(void); 4760Sstevel@tonic-gate extern void zone_init(void); 4770Sstevel@tonic-gate extern void zone_hold(zone_t *); 4780Sstevel@tonic-gate extern void zone_rele(zone_t *); 4790Sstevel@tonic-gate extern void zone_cred_hold(zone_t *); 4800Sstevel@tonic-gate extern void zone_cred_rele(zone_t *); 4810Sstevel@tonic-gate extern void zone_task_hold(zone_t *); 4820Sstevel@tonic-gate extern void zone_task_rele(zone_t *); 4830Sstevel@tonic-gate extern zone_t *zone_find_by_id(zoneid_t); 4841676Sjpk extern zone_t *zone_find_by_label(const ts_label_t *); 4850Sstevel@tonic-gate extern zone_t *zone_find_by_name(char *); 4861769Scarlsonj extern zone_t *zone_find_by_any_path(const char *, boolean_t); 4870Sstevel@tonic-gate extern zone_t *zone_find_by_path(const char *); 4880Sstevel@tonic-gate extern zoneid_t getzoneid(void); 4893448Sdh155122 extern zone_t *zone_find_by_id_nolock(zoneid_t); 49010616SSebastien.Roy@Sun.COM extern int zone_datalink_walk(zoneid_t, int (*)(datalink_id_t, void *), void *); 49110616SSebastien.Roy@Sun.COM extern int zone_check_datalink(zoneid_t *, datalink_id_t); 4920Sstevel@tonic-gate 4930Sstevel@tonic-gate /* 4940Sstevel@tonic-gate * Zone-specific data (ZSD) APIs 4950Sstevel@tonic-gate */ 4960Sstevel@tonic-gate /* 4970Sstevel@tonic-gate * The following is what code should be initializing its zone_key_t to if it 4980Sstevel@tonic-gate * calls zone_getspecific() without necessarily knowing that zone_key_create() 4990Sstevel@tonic-gate * has been called on the key. 5000Sstevel@tonic-gate */ 5010Sstevel@tonic-gate #define ZONE_KEY_UNINITIALIZED 0 5020Sstevel@tonic-gate 5030Sstevel@tonic-gate typedef uint_t zone_key_t; 5040Sstevel@tonic-gate 5050Sstevel@tonic-gate extern void zone_key_create(zone_key_t *, void *(*)(zoneid_t), 5060Sstevel@tonic-gate void (*)(zoneid_t, void *), void (*)(zoneid_t, void *)); 5070Sstevel@tonic-gate extern int zone_key_delete(zone_key_t); 5080Sstevel@tonic-gate extern void *zone_getspecific(zone_key_t, zone_t *); 5090Sstevel@tonic-gate extern int zone_setspecific(zone_key_t, zone_t *, const void *); 5100Sstevel@tonic-gate 5110Sstevel@tonic-gate /* 5120Sstevel@tonic-gate * The definition of a zsd_entry is truly private to zone.c and is only 5130Sstevel@tonic-gate * placed here so it can be shared with mdb. 5145880Snordmark * 5155880Snordmark * State maintained for each zone times each registered key, which tracks 5165880Snordmark * the state of the create, shutdown and destroy callbacks. 5175880Snordmark * 5185880Snordmark * zsd_flags is used to keep track of pending actions to avoid holding locks 5195880Snordmark * when calling the create/shutdown/destroy callbacks, since doing so 5205880Snordmark * could lead to deadlocks. 5210Sstevel@tonic-gate */ 5220Sstevel@tonic-gate struct zsd_entry { 5230Sstevel@tonic-gate zone_key_t zsd_key; /* Key used to lookup value */ 5240Sstevel@tonic-gate void *zsd_data; /* Caller-managed value */ 5250Sstevel@tonic-gate /* 5260Sstevel@tonic-gate * Callbacks to be executed when a zone is created, shutdown, and 5270Sstevel@tonic-gate * destroyed, respectively. 5280Sstevel@tonic-gate */ 5290Sstevel@tonic-gate void *(*zsd_create)(zoneid_t); 5300Sstevel@tonic-gate void (*zsd_shutdown)(zoneid_t, void *); 5310Sstevel@tonic-gate void (*zsd_destroy)(zoneid_t, void *); 5320Sstevel@tonic-gate list_node_t zsd_linkage; 5335880Snordmark uint16_t zsd_flags; /* See below */ 5345880Snordmark kcondvar_t zsd_cv; 5350Sstevel@tonic-gate }; 5360Sstevel@tonic-gate 5370Sstevel@tonic-gate /* 5385880Snordmark * zsd_flags 5395880Snordmark */ 5405880Snordmark #define ZSD_CREATE_NEEDED 0x0001 5415880Snordmark #define ZSD_CREATE_INPROGRESS 0x0002 5425880Snordmark #define ZSD_CREATE_COMPLETED 0x0004 5435880Snordmark #define ZSD_SHUTDOWN_NEEDED 0x0010 5445880Snordmark #define ZSD_SHUTDOWN_INPROGRESS 0x0020 5455880Snordmark #define ZSD_SHUTDOWN_COMPLETED 0x0040 5465880Snordmark #define ZSD_DESTROY_NEEDED 0x0100 5475880Snordmark #define ZSD_DESTROY_INPROGRESS 0x0200 5485880Snordmark #define ZSD_DESTROY_COMPLETED 0x0400 5495880Snordmark 5505880Snordmark #define ZSD_CREATE_ALL \ 5515880Snordmark (ZSD_CREATE_NEEDED|ZSD_CREATE_INPROGRESS|ZSD_CREATE_COMPLETED) 5525880Snordmark #define ZSD_SHUTDOWN_ALL \ 5535880Snordmark (ZSD_SHUTDOWN_NEEDED|ZSD_SHUTDOWN_INPROGRESS|ZSD_SHUTDOWN_COMPLETED) 5545880Snordmark #define ZSD_DESTROY_ALL \ 5555880Snordmark (ZSD_DESTROY_NEEDED|ZSD_DESTROY_INPROGRESS|ZSD_DESTROY_COMPLETED) 5565880Snordmark 5575880Snordmark #define ZSD_ALL_INPROGRESS \ 5585880Snordmark (ZSD_CREATE_INPROGRESS|ZSD_SHUTDOWN_INPROGRESS|ZSD_DESTROY_INPROGRESS) 5595880Snordmark 5605880Snordmark /* 5610Sstevel@tonic-gate * Macros to help with zone visibility restrictions. 5620Sstevel@tonic-gate */ 5630Sstevel@tonic-gate 5640Sstevel@tonic-gate /* 5650Sstevel@tonic-gate * Is process in the global zone? 5660Sstevel@tonic-gate */ 5670Sstevel@tonic-gate #define INGLOBALZONE(p) \ 5680Sstevel@tonic-gate ((p)->p_zone == global_zone) 5690Sstevel@tonic-gate 5700Sstevel@tonic-gate /* 5710Sstevel@tonic-gate * Can process view objects in given zone? 5720Sstevel@tonic-gate */ 5730Sstevel@tonic-gate #define HASZONEACCESS(p, zoneid) \ 5740Sstevel@tonic-gate ((p)->p_zone->zone_id == (zoneid) || INGLOBALZONE(p)) 5750Sstevel@tonic-gate 5760Sstevel@tonic-gate /* 5770Sstevel@tonic-gate * Convenience macro to see if a resolved path is visible from within a 5780Sstevel@tonic-gate * given zone. 5790Sstevel@tonic-gate * 5800Sstevel@tonic-gate * The basic idea is that the first (zone_rootpathlen - 1) bytes of the 5810Sstevel@tonic-gate * two strings must be equal. Since the rootpathlen has a trailing '/', 5820Sstevel@tonic-gate * we want to skip everything in the path up to (but not including) the 5830Sstevel@tonic-gate * trailing '/'. 5840Sstevel@tonic-gate */ 5850Sstevel@tonic-gate #define ZONE_PATH_VISIBLE(path, zone) \ 5860Sstevel@tonic-gate (strncmp((path), (zone)->zone_rootpath, \ 5870Sstevel@tonic-gate (zone)->zone_rootpathlen - 1) == 0) 5880Sstevel@tonic-gate 5890Sstevel@tonic-gate /* 5900Sstevel@tonic-gate * Convenience macro to go from the global view of a path to that seen 5910Sstevel@tonic-gate * from within said zone. It is the responsibility of the caller to 5920Sstevel@tonic-gate * ensure that the path is a resolved one (ie, no '..'s or '.'s), and is 5930Sstevel@tonic-gate * in fact visible from within the zone. 5940Sstevel@tonic-gate */ 5950Sstevel@tonic-gate #define ZONE_PATH_TRANSLATE(path, zone) \ 5960Sstevel@tonic-gate (ASSERT(ZONE_PATH_VISIBLE(path, zone)), \ 5970Sstevel@tonic-gate (path) + (zone)->zone_rootpathlen - 2) 5980Sstevel@tonic-gate 5990Sstevel@tonic-gate /* 6000Sstevel@tonic-gate * Special processes visible in all zones. 6010Sstevel@tonic-gate */ 6020Sstevel@tonic-gate #define ZONE_SPECIALPID(x) ((x) == 0 || (x) == 1) 6030Sstevel@tonic-gate 6040Sstevel@tonic-gate /* 6050Sstevel@tonic-gate * Zone-safe version of thread_create() to be used when the caller wants to 6060Sstevel@tonic-gate * create a kernel thread to run within the current zone's context. 6070Sstevel@tonic-gate */ 6080Sstevel@tonic-gate extern kthread_t *zthread_create(caddr_t, size_t, void (*)(), void *, size_t, 6090Sstevel@tonic-gate pri_t); 6100Sstevel@tonic-gate extern void zthread_exit(void); 6110Sstevel@tonic-gate 6120Sstevel@tonic-gate /* 6130Sstevel@tonic-gate * Functions for an external observer to register interest in a zone's status 6140Sstevel@tonic-gate * change. Observers will be woken up when the zone status equals the status 6150Sstevel@tonic-gate * argument passed in (in the case of zone_status_timedwait, the function may 6160Sstevel@tonic-gate * also return because of a timeout; zone_status_wait_sig may return early due 6170Sstevel@tonic-gate * to a signal being delivered; zone_status_timedwait_sig may return for any of 6180Sstevel@tonic-gate * the above reasons). 6190Sstevel@tonic-gate * 6200Sstevel@tonic-gate * Otherwise these behave identically to cv_timedwait(), cv_wait(), and 6210Sstevel@tonic-gate * cv_wait_sig() respectively. 6220Sstevel@tonic-gate */ 6230Sstevel@tonic-gate extern clock_t zone_status_timedwait(zone_t *, clock_t, zone_status_t); 6240Sstevel@tonic-gate extern clock_t zone_status_timedwait_sig(zone_t *, clock_t, zone_status_t); 6250Sstevel@tonic-gate extern void zone_status_wait(zone_t *, zone_status_t); 6260Sstevel@tonic-gate extern int zone_status_wait_sig(zone_t *, zone_status_t); 6270Sstevel@tonic-gate 6280Sstevel@tonic-gate /* 6290Sstevel@tonic-gate * Get the status of the zone (at the time it was called). The state may 6300Sstevel@tonic-gate * have progressed by the time it is returned. 6310Sstevel@tonic-gate */ 6320Sstevel@tonic-gate extern zone_status_t zone_status_get(zone_t *); 6330Sstevel@tonic-gate 6340Sstevel@tonic-gate /* 6358662SJordan.Vaughan@Sun.com * Safely get the hostid of the specified zone (defaults to machine's hostid 6368662SJordan.Vaughan@Sun.com * if the specified zone doesn't emulate a hostid). Passing NULL retrieves 6378662SJordan.Vaughan@Sun.com * the global zone's (i.e., physical system's) hostid. 6388662SJordan.Vaughan@Sun.com */ 6398662SJordan.Vaughan@Sun.com extern uint32_t zone_get_hostid(zone_t *); 6408662SJordan.Vaughan@Sun.com 6418662SJordan.Vaughan@Sun.com /* 6420Sstevel@tonic-gate * Get the "kcred" credentials corresponding to the given zone. 6430Sstevel@tonic-gate */ 6440Sstevel@tonic-gate extern struct cred *zone_get_kcred(zoneid_t); 6450Sstevel@tonic-gate 6460Sstevel@tonic-gate /* 6470Sstevel@tonic-gate * Get/set the pool the zone is currently bound to. 6480Sstevel@tonic-gate */ 6490Sstevel@tonic-gate extern struct pool *zone_pool_get(zone_t *); 6500Sstevel@tonic-gate extern void zone_pool_set(zone_t *, struct pool *); 6510Sstevel@tonic-gate 6520Sstevel@tonic-gate /* 6530Sstevel@tonic-gate * Get/set the pset the zone is currently using. 6540Sstevel@tonic-gate */ 6550Sstevel@tonic-gate extern psetid_t zone_pset_get(zone_t *); 6560Sstevel@tonic-gate extern void zone_pset_set(zone_t *, psetid_t); 6570Sstevel@tonic-gate 6580Sstevel@tonic-gate /* 6590Sstevel@tonic-gate * Get the number of cpus/online-cpus visible from the given zone. 6600Sstevel@tonic-gate */ 6610Sstevel@tonic-gate extern int zone_ncpus_get(zone_t *); 6620Sstevel@tonic-gate extern int zone_ncpus_online_get(zone_t *); 6630Sstevel@tonic-gate 6640Sstevel@tonic-gate /* 665789Sahrens * Returns true if the named pool/dataset is visible in the current zone. 666789Sahrens */ 667789Sahrens extern int zone_dataset_visible(const char *, int *); 668789Sahrens 669789Sahrens /* 6702267Sdp * zone version of kadmin() 6710Sstevel@tonic-gate */ 6722267Sdp extern int zone_kadmin(int, int, const char *, cred_t *); 6730Sstevel@tonic-gate extern void zone_shutdown_global(void); 6740Sstevel@tonic-gate 6750Sstevel@tonic-gate extern void mount_in_progress(void); 6760Sstevel@tonic-gate extern void mount_completed(void); 6770Sstevel@tonic-gate 6780Sstevel@tonic-gate extern int zone_walk(int (*)(zone_t *, void *), void *); 6790Sstevel@tonic-gate 6802768Ssl108498 extern rctl_hndl_t rc_zone_locked_mem; 6813247Sgjelinek extern rctl_hndl_t rc_zone_max_swap; 68212633Sjohn.levon@sun.com extern rctl_hndl_t rc_zone_max_lofi; 6832768Ssl108498 6840Sstevel@tonic-gate #endif /* _KERNEL */ 6850Sstevel@tonic-gate 6860Sstevel@tonic-gate #ifdef __cplusplus 6870Sstevel@tonic-gate } 6880Sstevel@tonic-gate #endif 6890Sstevel@tonic-gate 6900Sstevel@tonic-gate #endif /* _SYS_ZONE_H */ 691