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> 35*2677Sml93401 #include <sys/ipc_rctl.h> 360Sstevel@tonic-gate #include <sys/pset.h> 371676Sjpk #include <sys/tsol/label.h> 382267Sdp #include <sys/uadmin.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 */ 680Sstevel@tonic-gate #define ZONE_CREATE 0 690Sstevel@tonic-gate #define ZONE_DESTROY 1 700Sstevel@tonic-gate #define ZONE_GETATTR 2 710Sstevel@tonic-gate #define ZONE_ENTER 3 720Sstevel@tonic-gate #define ZONE_LIST 4 730Sstevel@tonic-gate #define ZONE_SHUTDOWN 5 740Sstevel@tonic-gate #define ZONE_LOOKUP 6 750Sstevel@tonic-gate #define ZONE_BOOT 7 76813Sdp #define ZONE_VERSION 8 772267Sdp #define ZONE_SETATTR 9 780Sstevel@tonic-gate 790Sstevel@tonic-gate /* zone attributes */ 800Sstevel@tonic-gate #define ZONE_ATTR_ROOT 1 810Sstevel@tonic-gate #define ZONE_ATTR_NAME 2 820Sstevel@tonic-gate #define ZONE_ATTR_STATUS 3 830Sstevel@tonic-gate #define ZONE_ATTR_PRIVSET 4 840Sstevel@tonic-gate #define ZONE_ATTR_UNIQID 5 850Sstevel@tonic-gate #define ZONE_ATTR_POOLID 6 860Sstevel@tonic-gate #define ZONE_ATTR_INITPID 7 871676Sjpk #define ZONE_ATTR_SLBL 8 882267Sdp #define ZONE_ATTR_INITNAME 9 892267Sdp #define ZONE_ATTR_BOOTARGS 10 900Sstevel@tonic-gate 911166Sdstaff #define ZONE_EVENT_CHANNEL "com.sun:zones:status" 921166Sdstaff #define ZONE_EVENT_STATUS_CLASS "status" 931166Sdstaff #define ZONE_EVENT_STATUS_SUBCLASS "change" 941166Sdstaff 951166Sdstaff #define ZONE_EVENT_UNINITIALIZED "uninitialized" 961166Sdstaff #define ZONE_EVENT_READY "ready" 971166Sdstaff #define ZONE_EVENT_RUNNING "running" 981166Sdstaff #define ZONE_EVENT_SHUTTING_DOWN "shutting_down" 991166Sdstaff 1001166Sdstaff #define ZONE_CB_NAME "zonename" 1011166Sdstaff #define ZONE_CB_NEWSTATE "newstate" 1021166Sdstaff #define ZONE_CB_OLDSTATE "oldstate" 1031166Sdstaff #define ZONE_CB_TIMESTAMP "when" 1041166Sdstaff #define ZONE_CB_ZONEID "zoneid" 1051166Sdstaff 1060Sstevel@tonic-gate #ifdef _SYSCALL32 1070Sstevel@tonic-gate typedef struct { 1080Sstevel@tonic-gate caddr32_t zone_name; 1090Sstevel@tonic-gate caddr32_t zone_root; 1100Sstevel@tonic-gate caddr32_t zone_privs; 111813Sdp size32_t zone_privssz; 1120Sstevel@tonic-gate caddr32_t rctlbuf; 1130Sstevel@tonic-gate size32_t rctlbufsz; 1140Sstevel@tonic-gate caddr32_t extended_error; 115789Sahrens caddr32_t zfsbuf; 116789Sahrens size32_t zfsbufsz; 1172110Srica int match; /* match level */ 1182110Srica uint32_t doi; /* DOI for label */ 1192110Srica caddr32_t label; /* label associated with zone */ 1200Sstevel@tonic-gate } zone_def32; 1210Sstevel@tonic-gate #endif 1220Sstevel@tonic-gate typedef struct { 1230Sstevel@tonic-gate const char *zone_name; 1240Sstevel@tonic-gate const char *zone_root; 1250Sstevel@tonic-gate const struct priv_set *zone_privs; 126813Sdp size_t zone_privssz; 1270Sstevel@tonic-gate const char *rctlbuf; 1280Sstevel@tonic-gate size_t rctlbufsz; 1290Sstevel@tonic-gate int *extended_error; 130789Sahrens const char *zfsbuf; 131789Sahrens size_t zfsbufsz; 1321676Sjpk int match; /* match level */ 1332110Srica uint32_t doi; /* DOI for label */ 1341676Sjpk const bslabel_t *label; /* label associated with zone */ 1350Sstevel@tonic-gate } zone_def; 1360Sstevel@tonic-gate 1370Sstevel@tonic-gate /* extended error information */ 1380Sstevel@tonic-gate #define ZE_UNKNOWN 0 /* No extended error info */ 1390Sstevel@tonic-gate #define ZE_CHROOTED 1 /* tried to zone_create from chroot */ 1400Sstevel@tonic-gate #define ZE_AREMOUNTS 2 /* there are mounts within the zone */ 1410Sstevel@tonic-gate 1420Sstevel@tonic-gate /* zone_status */ 1430Sstevel@tonic-gate typedef enum { 1440Sstevel@tonic-gate ZONE_IS_UNINITIALIZED = 0, 1450Sstevel@tonic-gate ZONE_IS_READY, 1460Sstevel@tonic-gate ZONE_IS_BOOTING, 1470Sstevel@tonic-gate ZONE_IS_RUNNING, 1480Sstevel@tonic-gate ZONE_IS_SHUTTING_DOWN, 1490Sstevel@tonic-gate ZONE_IS_EMPTY, 1500Sstevel@tonic-gate ZONE_IS_DOWN, 1510Sstevel@tonic-gate ZONE_IS_DYING, 1520Sstevel@tonic-gate ZONE_IS_DEAD 1530Sstevel@tonic-gate } zone_status_t; 1540Sstevel@tonic-gate #define ZONE_MIN_STATE ZONE_IS_UNINITIALIZED 1550Sstevel@tonic-gate #define ZONE_MAX_STATE ZONE_IS_DEAD 1560Sstevel@tonic-gate 1570Sstevel@tonic-gate /* 1580Sstevel@tonic-gate * Valid commands which may be issued by zoneadm to zoneadmd. The kernel also 1590Sstevel@tonic-gate * communicates with zoneadmd, but only uses Z_REBOOT and Z_HALT. 1600Sstevel@tonic-gate */ 1610Sstevel@tonic-gate typedef enum zone_cmd { 162766Scarlsonj Z_READY, Z_BOOT, Z_REBOOT, Z_HALT, Z_NOTE_UNINSTALLING, 163766Scarlsonj Z_MOUNT, Z_UNMOUNT 1640Sstevel@tonic-gate } zone_cmd_t; 1650Sstevel@tonic-gate 1660Sstevel@tonic-gate /* 1670Sstevel@tonic-gate * The structure of a request to zoneadmd. 1680Sstevel@tonic-gate */ 1690Sstevel@tonic-gate typedef struct zone_cmd_arg { 1700Sstevel@tonic-gate uint64_t uniqid; /* unique "generation number" */ 1710Sstevel@tonic-gate zone_cmd_t cmd; /* requested action */ 1722267Sdp uint32_t _pad; /* need consistent 32/64 bit alignmt */ 1730Sstevel@tonic-gate char locale[MAXPATHLEN]; /* locale in which to render messages */ 1742267Sdp char bootbuf[BOOTARGS_MAX]; /* arguments passed to zone_boot() */ 1750Sstevel@tonic-gate } zone_cmd_arg_t; 1760Sstevel@tonic-gate 1770Sstevel@tonic-gate /* 1780Sstevel@tonic-gate * Structure of zoneadmd's response to a request. A NULL return value means 1790Sstevel@tonic-gate * the caller should attempt to restart zoneadmd and retry. 1800Sstevel@tonic-gate */ 1810Sstevel@tonic-gate typedef struct zone_cmd_rval { 1820Sstevel@tonic-gate int rval; /* return value of request */ 1830Sstevel@tonic-gate char errbuf[1]; /* variable-sized buffer containing error messages */ 1840Sstevel@tonic-gate } zone_cmd_rval_t; 1850Sstevel@tonic-gate 1860Sstevel@tonic-gate /* 1870Sstevel@tonic-gate * The zone support infrastructure uses the zone name as a component 1880Sstevel@tonic-gate * of unix domain (AF_UNIX) sockets, which are limited to 108 characters 1890Sstevel@tonic-gate * in length, so ZONENAME_MAX is limited by that. 1900Sstevel@tonic-gate */ 1910Sstevel@tonic-gate #define ZONENAME_MAX 64 1920Sstevel@tonic-gate 1930Sstevel@tonic-gate #define GLOBAL_ZONENAME "global" 1940Sstevel@tonic-gate 1950Sstevel@tonic-gate /* 1960Sstevel@tonic-gate * Extended Regular expression (see regex(5)) which matches all valid zone 1970Sstevel@tonic-gate * names. 1980Sstevel@tonic-gate */ 1990Sstevel@tonic-gate #define ZONENAME_REGEXP "[a-zA-Z0-9][-_.a-zA-Z0-9]{0,62}" 2000Sstevel@tonic-gate 2010Sstevel@tonic-gate /* 2020Sstevel@tonic-gate * Where the zones support infrastructure places temporary files. 2030Sstevel@tonic-gate */ 2040Sstevel@tonic-gate #define ZONES_TMPDIR "/var/run/zones" 2050Sstevel@tonic-gate 2060Sstevel@tonic-gate /* 2070Sstevel@tonic-gate * The path to the door used by clients to communicate with zoneadmd. 2080Sstevel@tonic-gate */ 2090Sstevel@tonic-gate #define ZONE_DOOR_PATH ZONES_TMPDIR "/%s.zoneadmd_door" 2100Sstevel@tonic-gate 2110Sstevel@tonic-gate #ifdef _KERNEL 2120Sstevel@tonic-gate /* 2130Sstevel@tonic-gate * We need to protect the definition of 'list_t' from userland applications and 2140Sstevel@tonic-gate * libraries which may be defining ther own versions. 2150Sstevel@tonic-gate */ 2160Sstevel@tonic-gate #include <sys/list.h> 2170Sstevel@tonic-gate 2180Sstevel@tonic-gate #define GLOBAL_ZONEUNIQID 0 /* uniqid of the global zone */ 2190Sstevel@tonic-gate 2200Sstevel@tonic-gate /* zone_flags */ 2210Sstevel@tonic-gate #define ZF_DESTROYED 0x1 /* ZSD destructor callbacks run */ 2221769Scarlsonj #define ZF_HASHED_LABEL 0x2 /* zone has a unique label */ 2231769Scarlsonj #define ZF_IS_SCRATCH 0x4 /* scratch zone */ 2240Sstevel@tonic-gate 2250Sstevel@tonic-gate struct pool; 2260Sstevel@tonic-gate 227789Sahrens /* 228789Sahrens * Structure to record list of ZFS datasets exported to a zone. 229789Sahrens */ 230789Sahrens typedef struct zone_dataset { 231789Sahrens char *zd_dataset; 232789Sahrens list_node_t zd_linkage; 233789Sahrens } zone_dataset_t; 234789Sahrens 2350Sstevel@tonic-gate typedef struct zone { 2360Sstevel@tonic-gate /* 2370Sstevel@tonic-gate * zone_name is never modified once set. 2380Sstevel@tonic-gate */ 2390Sstevel@tonic-gate char *zone_name; /* zone's configuration name */ 2400Sstevel@tonic-gate /* 2410Sstevel@tonic-gate * zone_nodename and zone_domain are never freed once allocated. 2420Sstevel@tonic-gate */ 2430Sstevel@tonic-gate char *zone_nodename; /* utsname.nodename equivalent */ 2440Sstevel@tonic-gate char *zone_domain; /* srpc_domain equivalent */ 2450Sstevel@tonic-gate /* 2460Sstevel@tonic-gate * zone_lock protects the following fields of a zone_t: 2470Sstevel@tonic-gate * zone_ref 2480Sstevel@tonic-gate * zone_cred_ref 2490Sstevel@tonic-gate * zone_ntasks 2500Sstevel@tonic-gate * zone_flags 2510Sstevel@tonic-gate * zone_zsd 2520Sstevel@tonic-gate */ 2530Sstevel@tonic-gate kmutex_t zone_lock; 2540Sstevel@tonic-gate /* 2550Sstevel@tonic-gate * zone_linkage is the zone's linkage into the active or 2560Sstevel@tonic-gate * death-row list. The field is protected by zonehash_lock. 2570Sstevel@tonic-gate */ 2580Sstevel@tonic-gate list_node_t zone_linkage; 2590Sstevel@tonic-gate zoneid_t zone_id; /* ID of zone */ 2600Sstevel@tonic-gate uint_t zone_ref; /* count of zone_hold()s on zone */ 2610Sstevel@tonic-gate uint_t zone_cred_ref; /* count of zone_hold_cred()s on zone */ 2620Sstevel@tonic-gate /* 2630Sstevel@tonic-gate * zone_rootvp and zone_rootpath can never be modified once set. 2640Sstevel@tonic-gate */ 2650Sstevel@tonic-gate struct vnode *zone_rootvp; /* zone's root vnode */ 2660Sstevel@tonic-gate char *zone_rootpath; /* Path to zone's root + '/' */ 2670Sstevel@tonic-gate ushort_t zone_flags; /* misc flags */ 2680Sstevel@tonic-gate zone_status_t zone_status; /* protected by zone_status_lock */ 2690Sstevel@tonic-gate uint_t zone_ntasks; /* number of tasks executing in zone */ 2700Sstevel@tonic-gate kmutex_t zone_nlwps_lock; /* protects zone_nlwps, and *_nlwps */ 2710Sstevel@tonic-gate /* counters in projects and tasks */ 2720Sstevel@tonic-gate /* that are within the zone */ 2730Sstevel@tonic-gate rctl_qty_t zone_nlwps; /* number of lwps in zone */ 2740Sstevel@tonic-gate rctl_qty_t zone_nlwps_ctl; /* protected by zone_rctls->rcs_lock */ 275*2677Sml93401 rctl_qty_t zone_shmmax; /* System V shared memory usage */ 276*2677Sml93401 ipc_rqty_t zone_ipc; /* System V IPC id resource usage */ 2770Sstevel@tonic-gate 2780Sstevel@tonic-gate uint_t zone_rootpathlen; /* strlen(zone_rootpath) + 1 */ 2790Sstevel@tonic-gate uint32_t zone_shares; /* FSS shares allocated to zone */ 2800Sstevel@tonic-gate rctl_set_t *zone_rctls; /* zone-wide (zone.*) rctls */ 2810Sstevel@tonic-gate list_t zone_zsd; /* list of Zone-Specific Data values */ 2820Sstevel@tonic-gate kcondvar_t zone_cv; /* used to signal state changes */ 2830Sstevel@tonic-gate struct proc *zone_zsched; /* Dummy kernel "zsched" process */ 2840Sstevel@tonic-gate pid_t zone_proc_initpid; /* pid of "init" for this zone */ 2852267Sdp char *zone_initname; /* fs path to 'init' */ 2860Sstevel@tonic-gate int zone_boot_err; /* for zone_boot() if boot fails */ 2870Sstevel@tonic-gate char *zone_bootargs; /* arguments passed via zone_boot() */ 2880Sstevel@tonic-gate /* 2890Sstevel@tonic-gate * zone_kthreads is protected by zone_status_lock. 2900Sstevel@tonic-gate */ 2910Sstevel@tonic-gate kthread_t *zone_kthreads; /* kernel threads in zone */ 2920Sstevel@tonic-gate struct priv_set *zone_privset; /* limit set for zone */ 2930Sstevel@tonic-gate /* 2940Sstevel@tonic-gate * zone_vfslist is protected by vfs_list_lock(). 2950Sstevel@tonic-gate */ 2960Sstevel@tonic-gate struct vfs *zone_vfslist; /* list of FS's mounted in zone */ 2970Sstevel@tonic-gate uint64_t zone_uniqid; /* unique zone generation number */ 2980Sstevel@tonic-gate struct cred *zone_kcred; /* kcred-like, zone-limited cred */ 2990Sstevel@tonic-gate /* 3000Sstevel@tonic-gate * zone_pool is protected by pool_lock(). 3010Sstevel@tonic-gate */ 3020Sstevel@tonic-gate struct pool *zone_pool; /* pool the zone is bound to */ 3030Sstevel@tonic-gate hrtime_t zone_pool_mod; /* last pool bind modification time */ 3040Sstevel@tonic-gate /* zone_psetid is protected by cpu_lock */ 3050Sstevel@tonic-gate psetid_t zone_psetid; /* pset the zone is bound to */ 3060Sstevel@tonic-gate /* 3070Sstevel@tonic-gate * The following two can be read without holding any locks. They are 3080Sstevel@tonic-gate * updated under cpu_lock. 3090Sstevel@tonic-gate */ 3100Sstevel@tonic-gate int zone_ncpus; /* zone's idea of ncpus */ 3110Sstevel@tonic-gate int zone_ncpus_online; /* zone's idea of ncpus_online */ 312789Sahrens /* 313789Sahrens * List of ZFS datasets exported to this zone. 314789Sahrens */ 315789Sahrens list_t zone_datasets; /* list of datasets */ 3161676Sjpk 3172110Srica ts_label_t *zone_slabel; /* zone sensitivity label */ 3182110Srica int zone_match; /* require label match for packets */ 3191676Sjpk tsol_mlp_list_t zone_mlps; /* MLPs on zone-private addresses */ 3202267Sdp 3210Sstevel@tonic-gate } zone_t; 3220Sstevel@tonic-gate 3230Sstevel@tonic-gate /* 3240Sstevel@tonic-gate * Special value of zone_psetid to indicate that pools are disabled. 3250Sstevel@tonic-gate */ 3260Sstevel@tonic-gate #define ZONE_PS_INVAL PS_MYID 3270Sstevel@tonic-gate 3280Sstevel@tonic-gate extern zone_t zone0; 3290Sstevel@tonic-gate extern zone_t *global_zone; 3300Sstevel@tonic-gate extern uint_t maxzones; 3310Sstevel@tonic-gate extern rctl_hndl_t rc_zone_nlwps; 3320Sstevel@tonic-gate 3330Sstevel@tonic-gate extern const char * const zone_initname; 3340Sstevel@tonic-gate 335789Sahrens extern long zone(int, void *, void *, void *, void *); 3360Sstevel@tonic-gate extern void zone_zsd_init(void); 3370Sstevel@tonic-gate extern void zone_init(void); 3380Sstevel@tonic-gate extern void zone_hold(zone_t *); 3390Sstevel@tonic-gate extern void zone_rele(zone_t *); 3400Sstevel@tonic-gate extern void zone_cred_hold(zone_t *); 3410Sstevel@tonic-gate extern void zone_cred_rele(zone_t *); 3420Sstevel@tonic-gate extern void zone_task_hold(zone_t *); 3430Sstevel@tonic-gate extern void zone_task_rele(zone_t *); 3440Sstevel@tonic-gate extern zone_t *zone_find_by_id(zoneid_t); 3451676Sjpk extern zone_t *zone_find_by_label(const ts_label_t *); 3460Sstevel@tonic-gate extern zone_t *zone_find_by_name(char *); 3471769Scarlsonj extern zone_t *zone_find_by_any_path(const char *, boolean_t); 3480Sstevel@tonic-gate extern zone_t *zone_find_by_path(const char *); 3490Sstevel@tonic-gate extern zoneid_t getzoneid(void); 3500Sstevel@tonic-gate 3510Sstevel@tonic-gate /* 3520Sstevel@tonic-gate * Zone-specific data (ZSD) APIs 3530Sstevel@tonic-gate */ 3540Sstevel@tonic-gate /* 3550Sstevel@tonic-gate * The following is what code should be initializing its zone_key_t to if it 3560Sstevel@tonic-gate * calls zone_getspecific() without necessarily knowing that zone_key_create() 3570Sstevel@tonic-gate * has been called on the key. 3580Sstevel@tonic-gate */ 3590Sstevel@tonic-gate #define ZONE_KEY_UNINITIALIZED 0 3600Sstevel@tonic-gate 3610Sstevel@tonic-gate typedef uint_t zone_key_t; 3620Sstevel@tonic-gate 3630Sstevel@tonic-gate extern void zone_key_create(zone_key_t *, void *(*)(zoneid_t), 3640Sstevel@tonic-gate void (*)(zoneid_t, void *), void (*)(zoneid_t, void *)); 3650Sstevel@tonic-gate extern int zone_key_delete(zone_key_t); 3660Sstevel@tonic-gate extern void *zone_getspecific(zone_key_t, zone_t *); 3670Sstevel@tonic-gate extern int zone_setspecific(zone_key_t, zone_t *, const void *); 3680Sstevel@tonic-gate 3690Sstevel@tonic-gate /* 3700Sstevel@tonic-gate * The definition of a zsd_entry is truly private to zone.c and is only 3710Sstevel@tonic-gate * placed here so it can be shared with mdb. 3720Sstevel@tonic-gate */ 3730Sstevel@tonic-gate struct zsd_entry { 3740Sstevel@tonic-gate zone_key_t zsd_key; /* Key used to lookup value */ 3750Sstevel@tonic-gate void *zsd_data; /* Caller-managed value */ 3760Sstevel@tonic-gate /* 3770Sstevel@tonic-gate * Callbacks to be executed when a zone is created, shutdown, and 3780Sstevel@tonic-gate * destroyed, respectively. 3790Sstevel@tonic-gate */ 3800Sstevel@tonic-gate void *(*zsd_create)(zoneid_t); 3810Sstevel@tonic-gate void (*zsd_shutdown)(zoneid_t, void *); 3820Sstevel@tonic-gate void (*zsd_destroy)(zoneid_t, void *); 3830Sstevel@tonic-gate list_node_t zsd_linkage; 3840Sstevel@tonic-gate }; 3850Sstevel@tonic-gate 3860Sstevel@tonic-gate /* 3870Sstevel@tonic-gate * Macros to help with zone visibility restrictions. 3880Sstevel@tonic-gate */ 3890Sstevel@tonic-gate 3900Sstevel@tonic-gate /* 3910Sstevel@tonic-gate * Is process in the global zone? 3920Sstevel@tonic-gate */ 3930Sstevel@tonic-gate #define INGLOBALZONE(p) \ 3940Sstevel@tonic-gate ((p)->p_zone == global_zone) 3950Sstevel@tonic-gate 3960Sstevel@tonic-gate /* 3970Sstevel@tonic-gate * Can process view objects in given zone? 3980Sstevel@tonic-gate */ 3990Sstevel@tonic-gate #define HASZONEACCESS(p, zoneid) \ 4000Sstevel@tonic-gate ((p)->p_zone->zone_id == (zoneid) || INGLOBALZONE(p)) 4010Sstevel@tonic-gate 4020Sstevel@tonic-gate /* 4030Sstevel@tonic-gate * Convenience macro to see if a resolved path is visible from within a 4040Sstevel@tonic-gate * given zone. 4050Sstevel@tonic-gate * 4060Sstevel@tonic-gate * The basic idea is that the first (zone_rootpathlen - 1) bytes of the 4070Sstevel@tonic-gate * two strings must be equal. Since the rootpathlen has a trailing '/', 4080Sstevel@tonic-gate * we want to skip everything in the path up to (but not including) the 4090Sstevel@tonic-gate * trailing '/'. 4100Sstevel@tonic-gate */ 4110Sstevel@tonic-gate #define ZONE_PATH_VISIBLE(path, zone) \ 4120Sstevel@tonic-gate (strncmp((path), (zone)->zone_rootpath, \ 4130Sstevel@tonic-gate (zone)->zone_rootpathlen - 1) == 0) 4140Sstevel@tonic-gate 4150Sstevel@tonic-gate /* 4160Sstevel@tonic-gate * Convenience macro to go from the global view of a path to that seen 4170Sstevel@tonic-gate * from within said zone. It is the responsibility of the caller to 4180Sstevel@tonic-gate * ensure that the path is a resolved one (ie, no '..'s or '.'s), and is 4190Sstevel@tonic-gate * in fact visible from within the zone. 4200Sstevel@tonic-gate */ 4210Sstevel@tonic-gate #define ZONE_PATH_TRANSLATE(path, zone) \ 4220Sstevel@tonic-gate (ASSERT(ZONE_PATH_VISIBLE(path, zone)), \ 4230Sstevel@tonic-gate (path) + (zone)->zone_rootpathlen - 2) 4240Sstevel@tonic-gate 4250Sstevel@tonic-gate /* 4260Sstevel@tonic-gate * Special processes visible in all zones. 4270Sstevel@tonic-gate */ 4280Sstevel@tonic-gate #define ZONE_SPECIALPID(x) ((x) == 0 || (x) == 1) 4290Sstevel@tonic-gate 4300Sstevel@tonic-gate /* 4310Sstevel@tonic-gate * Zone-safe version of thread_create() to be used when the caller wants to 4320Sstevel@tonic-gate * create a kernel thread to run within the current zone's context. 4330Sstevel@tonic-gate */ 4340Sstevel@tonic-gate extern kthread_t *zthread_create(caddr_t, size_t, void (*)(), void *, size_t, 4350Sstevel@tonic-gate pri_t); 4360Sstevel@tonic-gate extern void zthread_exit(void); 4370Sstevel@tonic-gate 4380Sstevel@tonic-gate /* 4390Sstevel@tonic-gate * Functions for an external observer to register interest in a zone's status 4400Sstevel@tonic-gate * change. Observers will be woken up when the zone status equals the status 4410Sstevel@tonic-gate * argument passed in (in the case of zone_status_timedwait, the function may 4420Sstevel@tonic-gate * also return because of a timeout; zone_status_wait_sig may return early due 4430Sstevel@tonic-gate * to a signal being delivered; zone_status_timedwait_sig may return for any of 4440Sstevel@tonic-gate * the above reasons). 4450Sstevel@tonic-gate * 4460Sstevel@tonic-gate * Otherwise these behave identically to cv_timedwait(), cv_wait(), and 4470Sstevel@tonic-gate * cv_wait_sig() respectively. 4480Sstevel@tonic-gate */ 4490Sstevel@tonic-gate extern clock_t zone_status_timedwait(zone_t *, clock_t, zone_status_t); 4500Sstevel@tonic-gate extern clock_t zone_status_timedwait_sig(zone_t *, clock_t, zone_status_t); 4510Sstevel@tonic-gate extern void zone_status_wait(zone_t *, zone_status_t); 4520Sstevel@tonic-gate extern int zone_status_wait_sig(zone_t *, zone_status_t); 4530Sstevel@tonic-gate 4540Sstevel@tonic-gate /* 4550Sstevel@tonic-gate * Get the status of the zone (at the time it was called). The state may 4560Sstevel@tonic-gate * have progressed by the time it is returned. 4570Sstevel@tonic-gate */ 4580Sstevel@tonic-gate extern zone_status_t zone_status_get(zone_t *); 4590Sstevel@tonic-gate 4600Sstevel@tonic-gate /* 4610Sstevel@tonic-gate * Get the "kcred" credentials corresponding to the given zone. 4620Sstevel@tonic-gate */ 4630Sstevel@tonic-gate extern struct cred *zone_get_kcred(zoneid_t); 4640Sstevel@tonic-gate 4650Sstevel@tonic-gate /* 4660Sstevel@tonic-gate * Get/set the pool the zone is currently bound to. 4670Sstevel@tonic-gate */ 4680Sstevel@tonic-gate extern struct pool *zone_pool_get(zone_t *); 4690Sstevel@tonic-gate extern void zone_pool_set(zone_t *, struct pool *); 4700Sstevel@tonic-gate 4710Sstevel@tonic-gate /* 4720Sstevel@tonic-gate * Get/set the pset the zone is currently using. 4730Sstevel@tonic-gate */ 4740Sstevel@tonic-gate extern psetid_t zone_pset_get(zone_t *); 4750Sstevel@tonic-gate extern void zone_pset_set(zone_t *, psetid_t); 4760Sstevel@tonic-gate 4770Sstevel@tonic-gate /* 4780Sstevel@tonic-gate * Get the number of cpus/online-cpus visible from the given zone. 4790Sstevel@tonic-gate */ 4800Sstevel@tonic-gate extern int zone_ncpus_get(zone_t *); 4810Sstevel@tonic-gate extern int zone_ncpus_online_get(zone_t *); 4820Sstevel@tonic-gate 4830Sstevel@tonic-gate /* 484789Sahrens * Returns true if the named pool/dataset is visible in the current zone. 485789Sahrens */ 486789Sahrens extern int zone_dataset_visible(const char *, int *); 487789Sahrens 488789Sahrens /* 4892267Sdp * zone version of kadmin() 4900Sstevel@tonic-gate */ 4912267Sdp extern int zone_kadmin(int, int, const char *, cred_t *); 4920Sstevel@tonic-gate extern void zone_shutdown_global(void); 4930Sstevel@tonic-gate 4940Sstevel@tonic-gate extern void mount_in_progress(void); 4950Sstevel@tonic-gate extern void mount_completed(void); 4960Sstevel@tonic-gate 4970Sstevel@tonic-gate extern int zone_walk(int (*)(zone_t *, void *), void *); 4980Sstevel@tonic-gate 4990Sstevel@tonic-gate #endif /* _KERNEL */ 5000Sstevel@tonic-gate 5010Sstevel@tonic-gate #ifdef __cplusplus 5020Sstevel@tonic-gate } 5030Sstevel@tonic-gate #endif 5040Sstevel@tonic-gate 5050Sstevel@tonic-gate #endif /* _SYS_ZONE_H */ 506