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 /* 221676Sjpk * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _SYS_ZONE_H 270Sstevel@tonic-gate #define _SYS_ZONE_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 300Sstevel@tonic-gate 310Sstevel@tonic-gate #include <sys/types.h> 320Sstevel@tonic-gate #include <sys/mutex.h> 330Sstevel@tonic-gate #include <sys/param.h> 340Sstevel@tonic-gate #include <sys/rctl.h> 350Sstevel@tonic-gate #include <sys/pset.h> 361676Sjpk #include <sys/tsol/label.h> 370Sstevel@tonic-gate 380Sstevel@tonic-gate #ifdef __cplusplus 390Sstevel@tonic-gate extern "C" { 400Sstevel@tonic-gate #endif 410Sstevel@tonic-gate 420Sstevel@tonic-gate /* 430Sstevel@tonic-gate * NOTE 440Sstevel@tonic-gate * 450Sstevel@tonic-gate * The contents of this file are private to the implementation of 460Sstevel@tonic-gate * Solaris and are subject to change at any time without notice. 470Sstevel@tonic-gate * Applications and drivers using these interfaces may fail to 480Sstevel@tonic-gate * run on future releases. 490Sstevel@tonic-gate */ 500Sstevel@tonic-gate 510Sstevel@tonic-gate /* Available both in kernel and for user space */ 520Sstevel@tonic-gate 530Sstevel@tonic-gate /* zone id restrictions and special ids */ 540Sstevel@tonic-gate #define MAX_ZONEID 9999 550Sstevel@tonic-gate #define MIN_USERZONEID 1 /* lowest user-creatable zone ID */ 560Sstevel@tonic-gate #define MIN_ZONEID 0 /* minimum zone ID on system */ 570Sstevel@tonic-gate #define GLOBAL_ZONEID 0 580Sstevel@tonic-gate #define ZONEID_WIDTH 4 /* for printf */ 590Sstevel@tonic-gate 601676Sjpk /* 611676Sjpk * Special zoneid_t token to refer to all zones. 621676Sjpk */ 631676Sjpk #define ALL_ZONES (-1) 641676Sjpk 650Sstevel@tonic-gate /* system call subcodes */ 660Sstevel@tonic-gate #define ZONE_CREATE 0 670Sstevel@tonic-gate #define ZONE_DESTROY 1 680Sstevel@tonic-gate #define ZONE_GETATTR 2 690Sstevel@tonic-gate #define ZONE_ENTER 3 700Sstevel@tonic-gate #define ZONE_LIST 4 710Sstevel@tonic-gate #define ZONE_SHUTDOWN 5 720Sstevel@tonic-gate #define ZONE_LOOKUP 6 730Sstevel@tonic-gate #define ZONE_BOOT 7 74813Sdp #define ZONE_VERSION 8 750Sstevel@tonic-gate 760Sstevel@tonic-gate /* zone attributes */ 770Sstevel@tonic-gate #define ZONE_ATTR_ROOT 1 780Sstevel@tonic-gate #define ZONE_ATTR_NAME 2 790Sstevel@tonic-gate #define ZONE_ATTR_STATUS 3 800Sstevel@tonic-gate #define ZONE_ATTR_PRIVSET 4 810Sstevel@tonic-gate #define ZONE_ATTR_UNIQID 5 820Sstevel@tonic-gate #define ZONE_ATTR_POOLID 6 830Sstevel@tonic-gate #define ZONE_ATTR_INITPID 7 841676Sjpk #define ZONE_ATTR_SLBL 8 850Sstevel@tonic-gate 861166Sdstaff #define ZONE_EVENT_CHANNEL "com.sun:zones:status" 871166Sdstaff #define ZONE_EVENT_STATUS_CLASS "status" 881166Sdstaff #define ZONE_EVENT_STATUS_SUBCLASS "change" 891166Sdstaff 901166Sdstaff #define ZONE_EVENT_UNINITIALIZED "uninitialized" 911166Sdstaff #define ZONE_EVENT_READY "ready" 921166Sdstaff #define ZONE_EVENT_RUNNING "running" 931166Sdstaff #define ZONE_EVENT_SHUTTING_DOWN "shutting_down" 941166Sdstaff 951166Sdstaff #define ZONE_CB_NAME "zonename" 961166Sdstaff #define ZONE_CB_NEWSTATE "newstate" 971166Sdstaff #define ZONE_CB_OLDSTATE "oldstate" 981166Sdstaff #define ZONE_CB_TIMESTAMP "when" 991166Sdstaff #define ZONE_CB_ZONEID "zoneid" 1001166Sdstaff 1010Sstevel@tonic-gate #ifdef _SYSCALL32 1020Sstevel@tonic-gate typedef struct { 1030Sstevel@tonic-gate caddr32_t zone_name; 1040Sstevel@tonic-gate caddr32_t zone_root; 1050Sstevel@tonic-gate caddr32_t zone_privs; 106813Sdp size32_t zone_privssz; 1070Sstevel@tonic-gate caddr32_t rctlbuf; 1080Sstevel@tonic-gate size32_t rctlbufsz; 1090Sstevel@tonic-gate caddr32_t extended_error; 110789Sahrens caddr32_t zfsbuf; 111789Sahrens size32_t zfsbufsz; 112*2110Srica int match; /* match level */ 113*2110Srica uint32_t doi; /* DOI for label */ 114*2110Srica caddr32_t label; /* label associated with zone */ 1150Sstevel@tonic-gate } zone_def32; 1160Sstevel@tonic-gate #endif 1170Sstevel@tonic-gate typedef struct { 1180Sstevel@tonic-gate const char *zone_name; 1190Sstevel@tonic-gate const char *zone_root; 1200Sstevel@tonic-gate const struct priv_set *zone_privs; 121813Sdp size_t zone_privssz; 1220Sstevel@tonic-gate const char *rctlbuf; 1230Sstevel@tonic-gate size_t rctlbufsz; 1240Sstevel@tonic-gate int *extended_error; 125789Sahrens const char *zfsbuf; 126789Sahrens size_t zfsbufsz; 1271676Sjpk int match; /* match level */ 128*2110Srica uint32_t doi; /* DOI for label */ 1291676Sjpk const bslabel_t *label; /* label associated with zone */ 1300Sstevel@tonic-gate } zone_def; 1310Sstevel@tonic-gate 1320Sstevel@tonic-gate /* extended error information */ 1330Sstevel@tonic-gate #define ZE_UNKNOWN 0 /* No extended error info */ 1340Sstevel@tonic-gate #define ZE_CHROOTED 1 /* tried to zone_create from chroot */ 1350Sstevel@tonic-gate #define ZE_AREMOUNTS 2 /* there are mounts within the zone */ 1360Sstevel@tonic-gate 1370Sstevel@tonic-gate /* zone_status */ 1380Sstevel@tonic-gate typedef enum { 1390Sstevel@tonic-gate ZONE_IS_UNINITIALIZED = 0, 1400Sstevel@tonic-gate ZONE_IS_READY, 1410Sstevel@tonic-gate ZONE_IS_BOOTING, 1420Sstevel@tonic-gate ZONE_IS_RUNNING, 1430Sstevel@tonic-gate ZONE_IS_SHUTTING_DOWN, 1440Sstevel@tonic-gate ZONE_IS_EMPTY, 1450Sstevel@tonic-gate ZONE_IS_DOWN, 1460Sstevel@tonic-gate ZONE_IS_DYING, 1470Sstevel@tonic-gate ZONE_IS_DEAD 1480Sstevel@tonic-gate } zone_status_t; 1490Sstevel@tonic-gate #define ZONE_MIN_STATE ZONE_IS_UNINITIALIZED 1500Sstevel@tonic-gate #define ZONE_MAX_STATE ZONE_IS_DEAD 1510Sstevel@tonic-gate 1520Sstevel@tonic-gate /* 1530Sstevel@tonic-gate * Valid commands which may be issued by zoneadm to zoneadmd. The kernel also 1540Sstevel@tonic-gate * communicates with zoneadmd, but only uses Z_REBOOT and Z_HALT. 1550Sstevel@tonic-gate */ 1560Sstevel@tonic-gate typedef enum zone_cmd { 157766Scarlsonj Z_READY, Z_BOOT, Z_REBOOT, Z_HALT, Z_NOTE_UNINSTALLING, 158766Scarlsonj Z_MOUNT, Z_UNMOUNT 1590Sstevel@tonic-gate } zone_cmd_t; 1600Sstevel@tonic-gate 1610Sstevel@tonic-gate #define ZONEBOOTARGS_MAX 257 /* uadmin()'s buffer is 257 bytes. */ 1620Sstevel@tonic-gate 1630Sstevel@tonic-gate /* 1640Sstevel@tonic-gate * The structure of a request to zoneadmd. 1650Sstevel@tonic-gate */ 1660Sstevel@tonic-gate typedef struct zone_cmd_arg { 1670Sstevel@tonic-gate uint64_t uniqid; /* unique "generation number" */ 1680Sstevel@tonic-gate zone_cmd_t cmd; /* requested action */ 1690Sstevel@tonic-gate char locale[MAXPATHLEN]; /* locale in which to render messages */ 1700Sstevel@tonic-gate char bootbuf[ZONEBOOTARGS_MAX]; /* arguments passed to zone_boot() */ 1710Sstevel@tonic-gate } zone_cmd_arg_t; 1720Sstevel@tonic-gate 1730Sstevel@tonic-gate /* 1740Sstevel@tonic-gate * Structure of zoneadmd's response to a request. A NULL return value means 1750Sstevel@tonic-gate * the caller should attempt to restart zoneadmd and retry. 1760Sstevel@tonic-gate */ 1770Sstevel@tonic-gate typedef struct zone_cmd_rval { 1780Sstevel@tonic-gate int rval; /* return value of request */ 1790Sstevel@tonic-gate char errbuf[1]; /* variable-sized buffer containing error messages */ 1800Sstevel@tonic-gate } zone_cmd_rval_t; 1810Sstevel@tonic-gate 1820Sstevel@tonic-gate /* 1830Sstevel@tonic-gate * The zone support infrastructure uses the zone name as a component 1840Sstevel@tonic-gate * of unix domain (AF_UNIX) sockets, which are limited to 108 characters 1850Sstevel@tonic-gate * in length, so ZONENAME_MAX is limited by that. 1860Sstevel@tonic-gate */ 1870Sstevel@tonic-gate #define ZONENAME_MAX 64 1880Sstevel@tonic-gate 1890Sstevel@tonic-gate #define GLOBAL_ZONENAME "global" 1900Sstevel@tonic-gate 1910Sstevel@tonic-gate /* 1920Sstevel@tonic-gate * Extended Regular expression (see regex(5)) which matches all valid zone 1930Sstevel@tonic-gate * names. 1940Sstevel@tonic-gate */ 1950Sstevel@tonic-gate #define ZONENAME_REGEXP "[a-zA-Z0-9][-_.a-zA-Z0-9]{0,62}" 1960Sstevel@tonic-gate 1970Sstevel@tonic-gate /* 1980Sstevel@tonic-gate * Where the zones support infrastructure places temporary files. 1990Sstevel@tonic-gate */ 2000Sstevel@tonic-gate #define ZONES_TMPDIR "/var/run/zones" 2010Sstevel@tonic-gate 2020Sstevel@tonic-gate /* 2030Sstevel@tonic-gate * The path to the door used by clients to communicate with zoneadmd. 2040Sstevel@tonic-gate */ 2050Sstevel@tonic-gate #define ZONE_DOOR_PATH ZONES_TMPDIR "/%s.zoneadmd_door" 2060Sstevel@tonic-gate 2070Sstevel@tonic-gate #ifdef _KERNEL 2080Sstevel@tonic-gate /* 2090Sstevel@tonic-gate * We need to protect the definition of 'list_t' from userland applications and 2100Sstevel@tonic-gate * libraries which may be defining ther own versions. 2110Sstevel@tonic-gate */ 2120Sstevel@tonic-gate #include <sys/list.h> 2130Sstevel@tonic-gate 2140Sstevel@tonic-gate #define GLOBAL_ZONEUNIQID 0 /* uniqid of the global zone */ 2150Sstevel@tonic-gate 2160Sstevel@tonic-gate /* zone_flags */ 2170Sstevel@tonic-gate #define ZF_DESTROYED 0x1 /* ZSD destructor callbacks run */ 2181769Scarlsonj #define ZF_HASHED_LABEL 0x2 /* zone has a unique label */ 2191769Scarlsonj #define ZF_IS_SCRATCH 0x4 /* scratch zone */ 2200Sstevel@tonic-gate 2210Sstevel@tonic-gate struct pool; 2220Sstevel@tonic-gate 223789Sahrens /* 224789Sahrens * Structure to record list of ZFS datasets exported to a zone. 225789Sahrens */ 226789Sahrens typedef struct zone_dataset { 227789Sahrens char *zd_dataset; 228789Sahrens list_node_t zd_linkage; 229789Sahrens } zone_dataset_t; 230789Sahrens 2310Sstevel@tonic-gate typedef struct zone { 2320Sstevel@tonic-gate /* 2330Sstevel@tonic-gate * zone_name is never modified once set. 2340Sstevel@tonic-gate */ 2350Sstevel@tonic-gate char *zone_name; /* zone's configuration name */ 2360Sstevel@tonic-gate /* 2370Sstevel@tonic-gate * zone_nodename and zone_domain are never freed once allocated. 2380Sstevel@tonic-gate */ 2390Sstevel@tonic-gate char *zone_nodename; /* utsname.nodename equivalent */ 2400Sstevel@tonic-gate char *zone_domain; /* srpc_domain equivalent */ 2410Sstevel@tonic-gate /* 2420Sstevel@tonic-gate * zone_lock protects the following fields of a zone_t: 2430Sstevel@tonic-gate * zone_ref 2440Sstevel@tonic-gate * zone_cred_ref 2450Sstevel@tonic-gate * zone_ntasks 2460Sstevel@tonic-gate * zone_flags 2470Sstevel@tonic-gate * zone_zsd 2480Sstevel@tonic-gate */ 2490Sstevel@tonic-gate kmutex_t zone_lock; 2500Sstevel@tonic-gate /* 2510Sstevel@tonic-gate * zone_linkage is the zone's linkage into the active or 2520Sstevel@tonic-gate * death-row list. The field is protected by zonehash_lock. 2530Sstevel@tonic-gate */ 2540Sstevel@tonic-gate list_node_t zone_linkage; 2550Sstevel@tonic-gate zoneid_t zone_id; /* ID of zone */ 2560Sstevel@tonic-gate uint_t zone_ref; /* count of zone_hold()s on zone */ 2570Sstevel@tonic-gate uint_t zone_cred_ref; /* count of zone_hold_cred()s on zone */ 2580Sstevel@tonic-gate /* 2590Sstevel@tonic-gate * zone_rootvp and zone_rootpath can never be modified once set. 2600Sstevel@tonic-gate */ 2610Sstevel@tonic-gate struct vnode *zone_rootvp; /* zone's root vnode */ 2620Sstevel@tonic-gate char *zone_rootpath; /* Path to zone's root + '/' */ 2630Sstevel@tonic-gate ushort_t zone_flags; /* misc flags */ 2640Sstevel@tonic-gate zone_status_t zone_status; /* protected by zone_status_lock */ 2650Sstevel@tonic-gate uint_t zone_ntasks; /* number of tasks executing in zone */ 2660Sstevel@tonic-gate kmutex_t zone_nlwps_lock; /* protects zone_nlwps, and *_nlwps */ 2670Sstevel@tonic-gate /* counters in projects and tasks */ 2680Sstevel@tonic-gate /* that are within the zone */ 2690Sstevel@tonic-gate rctl_qty_t zone_nlwps; /* number of lwps in zone */ 2700Sstevel@tonic-gate rctl_qty_t zone_nlwps_ctl; /* protected by zone_rctls->rcs_lock */ 2710Sstevel@tonic-gate 2720Sstevel@tonic-gate uint_t zone_rootpathlen; /* strlen(zone_rootpath) + 1 */ 2730Sstevel@tonic-gate uint32_t zone_shares; /* FSS shares allocated to zone */ 2740Sstevel@tonic-gate rctl_set_t *zone_rctls; /* zone-wide (zone.*) rctls */ 2750Sstevel@tonic-gate list_t zone_zsd; /* list of Zone-Specific Data values */ 2760Sstevel@tonic-gate kcondvar_t zone_cv; /* used to signal state changes */ 2770Sstevel@tonic-gate struct proc *zone_zsched; /* Dummy kernel "zsched" process */ 2780Sstevel@tonic-gate pid_t zone_proc_initpid; /* pid of "init" for this zone */ 2790Sstevel@tonic-gate int zone_boot_err; /* for zone_boot() if boot fails */ 2800Sstevel@tonic-gate char *zone_bootargs; /* arguments passed via zone_boot() */ 2810Sstevel@tonic-gate /* 2820Sstevel@tonic-gate * zone_kthreads is protected by zone_status_lock. 2830Sstevel@tonic-gate */ 2840Sstevel@tonic-gate kthread_t *zone_kthreads; /* kernel threads in zone */ 2850Sstevel@tonic-gate struct priv_set *zone_privset; /* limit set for zone */ 2860Sstevel@tonic-gate /* 2870Sstevel@tonic-gate * zone_vfslist is protected by vfs_list_lock(). 2880Sstevel@tonic-gate */ 2890Sstevel@tonic-gate struct vfs *zone_vfslist; /* list of FS's mounted in zone */ 2900Sstevel@tonic-gate uint64_t zone_uniqid; /* unique zone generation number */ 2910Sstevel@tonic-gate struct cred *zone_kcred; /* kcred-like, zone-limited cred */ 2920Sstevel@tonic-gate /* 2930Sstevel@tonic-gate * zone_pool is protected by pool_lock(). 2940Sstevel@tonic-gate */ 2950Sstevel@tonic-gate struct pool *zone_pool; /* pool the zone is bound to */ 2960Sstevel@tonic-gate hrtime_t zone_pool_mod; /* last pool bind modification time */ 2970Sstevel@tonic-gate /* zone_psetid is protected by cpu_lock */ 2980Sstevel@tonic-gate psetid_t zone_psetid; /* pset the zone is bound to */ 2990Sstevel@tonic-gate /* 3000Sstevel@tonic-gate * The following two can be read without holding any locks. They are 3010Sstevel@tonic-gate * updated under cpu_lock. 3020Sstevel@tonic-gate */ 3030Sstevel@tonic-gate int zone_ncpus; /* zone's idea of ncpus */ 3040Sstevel@tonic-gate int zone_ncpus_online; /* zone's idea of ncpus_online */ 305789Sahrens /* 306789Sahrens * List of ZFS datasets exported to this zone. 307789Sahrens */ 308789Sahrens list_t zone_datasets; /* list of datasets */ 3091676Sjpk 310*2110Srica ts_label_t *zone_slabel; /* zone sensitivity label */ 311*2110Srica int zone_match; /* require label match for packets */ 3121676Sjpk tsol_mlp_list_t zone_mlps; /* MLPs on zone-private addresses */ 3130Sstevel@tonic-gate } zone_t; 3140Sstevel@tonic-gate 3150Sstevel@tonic-gate /* 3160Sstevel@tonic-gate * Special value of zone_psetid to indicate that pools are disabled. 3170Sstevel@tonic-gate */ 3180Sstevel@tonic-gate #define ZONE_PS_INVAL PS_MYID 3190Sstevel@tonic-gate 3200Sstevel@tonic-gate extern zone_t zone0; 3210Sstevel@tonic-gate extern zone_t *global_zone; 3220Sstevel@tonic-gate extern uint_t maxzones; 3230Sstevel@tonic-gate extern rctl_hndl_t rc_zone_nlwps; 3240Sstevel@tonic-gate 3250Sstevel@tonic-gate extern const char * const zone_initname; 3260Sstevel@tonic-gate 327789Sahrens extern long zone(int, void *, void *, void *, void *); 3280Sstevel@tonic-gate extern void zone_zsd_init(void); 3290Sstevel@tonic-gate extern void zone_init(void); 3300Sstevel@tonic-gate extern void zone_hold(zone_t *); 3310Sstevel@tonic-gate extern void zone_rele(zone_t *); 3320Sstevel@tonic-gate extern void zone_cred_hold(zone_t *); 3330Sstevel@tonic-gate extern void zone_cred_rele(zone_t *); 3340Sstevel@tonic-gate extern void zone_task_hold(zone_t *); 3350Sstevel@tonic-gate extern void zone_task_rele(zone_t *); 3360Sstevel@tonic-gate extern zone_t *zone_find_by_id(zoneid_t); 3371676Sjpk extern zone_t *zone_find_by_label(const ts_label_t *); 3380Sstevel@tonic-gate extern zone_t *zone_find_by_name(char *); 3391769Scarlsonj extern zone_t *zone_find_by_any_path(const char *, boolean_t); 3400Sstevel@tonic-gate extern zone_t *zone_find_by_path(const char *); 3410Sstevel@tonic-gate extern zoneid_t getzoneid(void); 3420Sstevel@tonic-gate 3430Sstevel@tonic-gate /* 3440Sstevel@tonic-gate * Zone-specific data (ZSD) APIs 3450Sstevel@tonic-gate */ 3460Sstevel@tonic-gate /* 3470Sstevel@tonic-gate * The following is what code should be initializing its zone_key_t to if it 3480Sstevel@tonic-gate * calls zone_getspecific() without necessarily knowing that zone_key_create() 3490Sstevel@tonic-gate * has been called on the key. 3500Sstevel@tonic-gate */ 3510Sstevel@tonic-gate #define ZONE_KEY_UNINITIALIZED 0 3520Sstevel@tonic-gate 3530Sstevel@tonic-gate typedef uint_t zone_key_t; 3540Sstevel@tonic-gate 3550Sstevel@tonic-gate extern void zone_key_create(zone_key_t *, void *(*)(zoneid_t), 3560Sstevel@tonic-gate void (*)(zoneid_t, void *), void (*)(zoneid_t, void *)); 3570Sstevel@tonic-gate extern int zone_key_delete(zone_key_t); 3580Sstevel@tonic-gate extern void *zone_getspecific(zone_key_t, zone_t *); 3590Sstevel@tonic-gate extern int zone_setspecific(zone_key_t, zone_t *, const void *); 3600Sstevel@tonic-gate 3610Sstevel@tonic-gate /* 3620Sstevel@tonic-gate * The definition of a zsd_entry is truly private to zone.c and is only 3630Sstevel@tonic-gate * placed here so it can be shared with mdb. 3640Sstevel@tonic-gate */ 3650Sstevel@tonic-gate struct zsd_entry { 3660Sstevel@tonic-gate zone_key_t zsd_key; /* Key used to lookup value */ 3670Sstevel@tonic-gate void *zsd_data; /* Caller-managed value */ 3680Sstevel@tonic-gate /* 3690Sstevel@tonic-gate * Callbacks to be executed when a zone is created, shutdown, and 3700Sstevel@tonic-gate * destroyed, respectively. 3710Sstevel@tonic-gate */ 3720Sstevel@tonic-gate void *(*zsd_create)(zoneid_t); 3730Sstevel@tonic-gate void (*zsd_shutdown)(zoneid_t, void *); 3740Sstevel@tonic-gate void (*zsd_destroy)(zoneid_t, void *); 3750Sstevel@tonic-gate list_node_t zsd_linkage; 3760Sstevel@tonic-gate }; 3770Sstevel@tonic-gate 3780Sstevel@tonic-gate /* 3790Sstevel@tonic-gate * Macros to help with zone visibility restrictions. 3800Sstevel@tonic-gate */ 3810Sstevel@tonic-gate 3820Sstevel@tonic-gate /* 3830Sstevel@tonic-gate * Is process in the global zone? 3840Sstevel@tonic-gate */ 3850Sstevel@tonic-gate #define INGLOBALZONE(p) \ 3860Sstevel@tonic-gate ((p)->p_zone == global_zone) 3870Sstevel@tonic-gate 3880Sstevel@tonic-gate /* 3890Sstevel@tonic-gate * Can process view objects in given zone? 3900Sstevel@tonic-gate */ 3910Sstevel@tonic-gate #define HASZONEACCESS(p, zoneid) \ 3920Sstevel@tonic-gate ((p)->p_zone->zone_id == (zoneid) || INGLOBALZONE(p)) 3930Sstevel@tonic-gate 3940Sstevel@tonic-gate /* 3950Sstevel@tonic-gate * Convenience macro to see if a resolved path is visible from within a 3960Sstevel@tonic-gate * given zone. 3970Sstevel@tonic-gate * 3980Sstevel@tonic-gate * The basic idea is that the first (zone_rootpathlen - 1) bytes of the 3990Sstevel@tonic-gate * two strings must be equal. Since the rootpathlen has a trailing '/', 4000Sstevel@tonic-gate * we want to skip everything in the path up to (but not including) the 4010Sstevel@tonic-gate * trailing '/'. 4020Sstevel@tonic-gate */ 4030Sstevel@tonic-gate #define ZONE_PATH_VISIBLE(path, zone) \ 4040Sstevel@tonic-gate (strncmp((path), (zone)->zone_rootpath, \ 4050Sstevel@tonic-gate (zone)->zone_rootpathlen - 1) == 0) 4060Sstevel@tonic-gate 4070Sstevel@tonic-gate /* 4080Sstevel@tonic-gate * Convenience macro to go from the global view of a path to that seen 4090Sstevel@tonic-gate * from within said zone. It is the responsibility of the caller to 4100Sstevel@tonic-gate * ensure that the path is a resolved one (ie, no '..'s or '.'s), and is 4110Sstevel@tonic-gate * in fact visible from within the zone. 4120Sstevel@tonic-gate */ 4130Sstevel@tonic-gate #define ZONE_PATH_TRANSLATE(path, zone) \ 4140Sstevel@tonic-gate (ASSERT(ZONE_PATH_VISIBLE(path, zone)), \ 4150Sstevel@tonic-gate (path) + (zone)->zone_rootpathlen - 2) 4160Sstevel@tonic-gate 4170Sstevel@tonic-gate /* 4180Sstevel@tonic-gate * Special processes visible in all zones. 4190Sstevel@tonic-gate */ 4200Sstevel@tonic-gate #define ZONE_SPECIALPID(x) ((x) == 0 || (x) == 1) 4210Sstevel@tonic-gate 4220Sstevel@tonic-gate /* 4230Sstevel@tonic-gate * Zone-safe version of thread_create() to be used when the caller wants to 4240Sstevel@tonic-gate * create a kernel thread to run within the current zone's context. 4250Sstevel@tonic-gate */ 4260Sstevel@tonic-gate extern kthread_t *zthread_create(caddr_t, size_t, void (*)(), void *, size_t, 4270Sstevel@tonic-gate pri_t); 4280Sstevel@tonic-gate extern void zthread_exit(void); 4290Sstevel@tonic-gate 4300Sstevel@tonic-gate /* 4310Sstevel@tonic-gate * Functions for an external observer to register interest in a zone's status 4320Sstevel@tonic-gate * change. Observers will be woken up when the zone status equals the status 4330Sstevel@tonic-gate * argument passed in (in the case of zone_status_timedwait, the function may 4340Sstevel@tonic-gate * also return because of a timeout; zone_status_wait_sig may return early due 4350Sstevel@tonic-gate * to a signal being delivered; zone_status_timedwait_sig may return for any of 4360Sstevel@tonic-gate * the above reasons). 4370Sstevel@tonic-gate * 4380Sstevel@tonic-gate * Otherwise these behave identically to cv_timedwait(), cv_wait(), and 4390Sstevel@tonic-gate * cv_wait_sig() respectively. 4400Sstevel@tonic-gate */ 4410Sstevel@tonic-gate extern clock_t zone_status_timedwait(zone_t *, clock_t, zone_status_t); 4420Sstevel@tonic-gate extern clock_t zone_status_timedwait_sig(zone_t *, clock_t, zone_status_t); 4430Sstevel@tonic-gate extern void zone_status_wait(zone_t *, zone_status_t); 4440Sstevel@tonic-gate extern int zone_status_wait_sig(zone_t *, zone_status_t); 4450Sstevel@tonic-gate 4460Sstevel@tonic-gate /* 4470Sstevel@tonic-gate * Get the status of the zone (at the time it was called). The state may 4480Sstevel@tonic-gate * have progressed by the time it is returned. 4490Sstevel@tonic-gate */ 4500Sstevel@tonic-gate extern zone_status_t zone_status_get(zone_t *); 4510Sstevel@tonic-gate 4520Sstevel@tonic-gate /* 4530Sstevel@tonic-gate * Get the "kcred" credentials corresponding to the given zone. 4540Sstevel@tonic-gate */ 4550Sstevel@tonic-gate extern struct cred *zone_get_kcred(zoneid_t); 4560Sstevel@tonic-gate 4570Sstevel@tonic-gate /* 4580Sstevel@tonic-gate * Get/set the pool the zone is currently bound to. 4590Sstevel@tonic-gate */ 4600Sstevel@tonic-gate extern struct pool *zone_pool_get(zone_t *); 4610Sstevel@tonic-gate extern void zone_pool_set(zone_t *, struct pool *); 4620Sstevel@tonic-gate 4630Sstevel@tonic-gate /* 4640Sstevel@tonic-gate * Get/set the pset the zone is currently using. 4650Sstevel@tonic-gate */ 4660Sstevel@tonic-gate extern psetid_t zone_pset_get(zone_t *); 4670Sstevel@tonic-gate extern void zone_pset_set(zone_t *, psetid_t); 4680Sstevel@tonic-gate 4690Sstevel@tonic-gate /* 4700Sstevel@tonic-gate * Get the number of cpus/online-cpus visible from the given zone. 4710Sstevel@tonic-gate */ 4720Sstevel@tonic-gate extern int zone_ncpus_get(zone_t *); 4730Sstevel@tonic-gate extern int zone_ncpus_online_get(zone_t *); 4740Sstevel@tonic-gate 4750Sstevel@tonic-gate /* 476789Sahrens * Returns true if the named pool/dataset is visible in the current zone. 477789Sahrens */ 478789Sahrens extern int zone_dataset_visible(const char *, int *); 479789Sahrens 480789Sahrens /* 4810Sstevel@tonic-gate * zone version of uadmin() 4820Sstevel@tonic-gate */ 4830Sstevel@tonic-gate extern int zone_uadmin(int, int, struct cred *); 4840Sstevel@tonic-gate extern void zone_shutdown_global(void); 4850Sstevel@tonic-gate 4860Sstevel@tonic-gate extern void mount_in_progress(void); 4870Sstevel@tonic-gate extern void mount_completed(void); 4880Sstevel@tonic-gate 4890Sstevel@tonic-gate extern int zone_walk(int (*)(zone_t *, void *), void *); 4900Sstevel@tonic-gate 4910Sstevel@tonic-gate #endif /* _KERNEL */ 4920Sstevel@tonic-gate 4930Sstevel@tonic-gate #ifdef __cplusplus 4940Sstevel@tonic-gate } 4950Sstevel@tonic-gate #endif 4960Sstevel@tonic-gate 4970Sstevel@tonic-gate #endif /* _SYS_ZONE_H */ 498