xref: /onnv-gate/usr/src/uts/common/sys/zone.h (revision 13096:b02331b7b26d)
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>
3912748SSowmini.Varadhan@oracle.COM #include <sys/socket_impl.h>
4012748SSowmini.Varadhan@oracle.COM #include <netinet/in.h>
410Sstevel@tonic-gate 
420Sstevel@tonic-gate #ifdef	__cplusplus
430Sstevel@tonic-gate extern "C" {
440Sstevel@tonic-gate #endif
450Sstevel@tonic-gate 
460Sstevel@tonic-gate /*
470Sstevel@tonic-gate  * NOTE
480Sstevel@tonic-gate  *
490Sstevel@tonic-gate  * The contents of this file are private to the implementation of
500Sstevel@tonic-gate  * Solaris and are subject to change at any time without notice.
510Sstevel@tonic-gate  * Applications and drivers using these interfaces may fail to
520Sstevel@tonic-gate  * run on future releases.
530Sstevel@tonic-gate  */
540Sstevel@tonic-gate 
550Sstevel@tonic-gate /* Available both in kernel and for user space */
560Sstevel@tonic-gate 
570Sstevel@tonic-gate /* zone id restrictions and special ids */
580Sstevel@tonic-gate #define	MAX_ZONEID	9999
590Sstevel@tonic-gate #define	MIN_USERZONEID	1	/* lowest user-creatable zone ID */
600Sstevel@tonic-gate #define	MIN_ZONEID	0	/* minimum zone ID on system */
610Sstevel@tonic-gate #define	GLOBAL_ZONEID	0
620Sstevel@tonic-gate #define	ZONEID_WIDTH	4	/* for printf */
630Sstevel@tonic-gate 
641676Sjpk /*
651676Sjpk  * Special zoneid_t token to refer to all zones.
661676Sjpk  */
671676Sjpk #define	ALL_ZONES	(-1)
681676Sjpk 
690Sstevel@tonic-gate /* system call subcodes */
703448Sdh155122 #define	ZONE_CREATE		0
713448Sdh155122 #define	ZONE_DESTROY		1
723448Sdh155122 #define	ZONE_GETATTR		2
733448Sdh155122 #define	ZONE_ENTER		3
743448Sdh155122 #define	ZONE_LIST		4
753448Sdh155122 #define	ZONE_SHUTDOWN		5
763448Sdh155122 #define	ZONE_LOOKUP		6
773448Sdh155122 #define	ZONE_BOOT		7
783448Sdh155122 #define	ZONE_VERSION		8
793448Sdh155122 #define	ZONE_SETATTR		9
803448Sdh155122 #define	ZONE_ADD_DATALINK	10
813448Sdh155122 #define	ZONE_DEL_DATALINK	11
823448Sdh155122 #define	ZONE_CHECK_DATALINK	12
833448Sdh155122 #define	ZONE_LIST_DATALINK	13
840Sstevel@tonic-gate 
850Sstevel@tonic-gate /* zone attributes */
860Sstevel@tonic-gate #define	ZONE_ATTR_ROOT		1
870Sstevel@tonic-gate #define	ZONE_ATTR_NAME		2
880Sstevel@tonic-gate #define	ZONE_ATTR_STATUS	3
890Sstevel@tonic-gate #define	ZONE_ATTR_PRIVSET	4
900Sstevel@tonic-gate #define	ZONE_ATTR_UNIQID	5
910Sstevel@tonic-gate #define	ZONE_ATTR_POOLID	6
920Sstevel@tonic-gate #define	ZONE_ATTR_INITPID	7
931676Sjpk #define	ZONE_ATTR_SLBL		8
942267Sdp #define	ZONE_ATTR_INITNAME	9
952267Sdp #define	ZONE_ATTR_BOOTARGS	10
962712Snn35248 #define	ZONE_ATTR_BRAND		11
973247Sgjelinek #define	ZONE_ATTR_PHYS_MCAP	12
983247Sgjelinek #define	ZONE_ATTR_SCHED_CLASS	13
993448Sdh155122 #define	ZONE_ATTR_FLAGS		14
1008662SJordan.Vaughan@Sun.com #define	ZONE_ATTR_HOSTID	15
10112633Sjohn.levon@sun.com #define	ZONE_ATTR_FS_ALLOWED	16
10212748SSowmini.Varadhan@oracle.COM #define	ZONE_ATTR_NETWORK	17
1032712Snn35248 
1042712Snn35248 /* Start of the brand-specific attribute namespace */
1052712Snn35248 #define	ZONE_ATTR_BRAND_ATTRS	32768
1060Sstevel@tonic-gate 
10712633Sjohn.levon@sun.com #define	ZONE_FS_ALLOWED_MAX	1024
10812633Sjohn.levon@sun.com 
1091166Sdstaff #define	ZONE_EVENT_CHANNEL	"com.sun:zones:status"
1101166Sdstaff #define	ZONE_EVENT_STATUS_CLASS	"status"
1111166Sdstaff #define	ZONE_EVENT_STATUS_SUBCLASS	"change"
1121166Sdstaff 
1131166Sdstaff #define	ZONE_EVENT_UNINITIALIZED	"uninitialized"
1145880Snordmark #define	ZONE_EVENT_INITIALIZED		"initialized"
1151166Sdstaff #define	ZONE_EVENT_READY		"ready"
1161166Sdstaff #define	ZONE_EVENT_RUNNING		"running"
1171166Sdstaff #define	ZONE_EVENT_SHUTTING_DOWN	"shutting_down"
1181166Sdstaff 
1191166Sdstaff #define	ZONE_CB_NAME		"zonename"
1201166Sdstaff #define	ZONE_CB_NEWSTATE	"newstate"
1211166Sdstaff #define	ZONE_CB_OLDSTATE	"oldstate"
1221166Sdstaff #define	ZONE_CB_TIMESTAMP	"when"
1231166Sdstaff #define	ZONE_CB_ZONEID		"zoneid"
1241166Sdstaff 
1252712Snn35248 /*
1262712Snn35248  * Exit values that may be returned by scripts or programs invoked by various
1272712Snn35248  * zone commands.
1282712Snn35248  *
1292712Snn35248  * These are defined as:
1302712Snn35248  *
1312712Snn35248  *	ZONE_SUBPROC_OK
1322712Snn35248  *	===============
1332712Snn35248  *	The subprocess completed successfully.
1342712Snn35248  *
1352712Snn35248  *	ZONE_SUBPROC_USAGE
1362712Snn35248  *	==================
1372712Snn35248  *	The subprocess failed with a usage message, or a usage message should
1382712Snn35248  *	be output in its behalf.
1392712Snn35248  *
1402712Snn35248  *	ZONE_SUBPROC_NOTCOMPLETE
1412712Snn35248  *	========================
1422712Snn35248  *	The subprocess did not complete, but the actions performed by the
1432712Snn35248  *	subprocess require no recovery actions by the user.
1442712Snn35248  *
1452712Snn35248  *	For example, if the subprocess were called by "zoneadm install," the
1462712Snn35248  *	installation of the zone did not succeed but the user need not perform
1472712Snn35248  *	a "zoneadm uninstall" before attempting another install.
1482712Snn35248  *
1492712Snn35248  *	ZONE_SUBPROC_FATAL
1502712Snn35248  *	==================
1512712Snn35248  *	The subprocess failed in a fatal manner, usually one that will require
1522712Snn35248  *	some type of recovery action by the user.
1532712Snn35248  *
1542712Snn35248  *	For example, if the subprocess were called by "zoneadm install," the
1552712Snn35248  *	installation of the zone did not succeed and the user will need to
1562712Snn35248  *	perform a "zoneadm uninstall" before another install attempt is
1572712Snn35248  *	possible.
1582712Snn35248  *
1592712Snn35248  *	The non-success exit values are large to avoid accidental collision
1602712Snn35248  *	with values used internally by some commands (e.g. "Z_ERR" and
1612712Snn35248  *	"Z_USAGE" as used by zoneadm.)
1622712Snn35248  */
1632712Snn35248 #define	ZONE_SUBPROC_OK			0
1642712Snn35248 #define	ZONE_SUBPROC_USAGE		253
1652712Snn35248 #define	ZONE_SUBPROC_NOTCOMPLETE	254
1662712Snn35248 #define	ZONE_SUBPROC_FATAL		255
1672712Snn35248 
1680Sstevel@tonic-gate #ifdef _SYSCALL32
1690Sstevel@tonic-gate typedef struct {
1700Sstevel@tonic-gate 	caddr32_t zone_name;
1710Sstevel@tonic-gate 	caddr32_t zone_root;
1720Sstevel@tonic-gate 	caddr32_t zone_privs;
173813Sdp 	size32_t zone_privssz;
1740Sstevel@tonic-gate 	caddr32_t rctlbuf;
1750Sstevel@tonic-gate 	size32_t rctlbufsz;
1760Sstevel@tonic-gate 	caddr32_t extended_error;
177789Sahrens 	caddr32_t zfsbuf;
178789Sahrens 	size32_t  zfsbufsz;
1792110Srica 	int match;			/* match level */
1802110Srica 	uint32_t doi;			/* DOI for label */
1812110Srica 	caddr32_t label;		/* label associated with zone */
1823448Sdh155122 	int flags;
1830Sstevel@tonic-gate } zone_def32;
1840Sstevel@tonic-gate #endif
1850Sstevel@tonic-gate typedef struct {
1860Sstevel@tonic-gate 	const char *zone_name;
1870Sstevel@tonic-gate 	const char *zone_root;
1880Sstevel@tonic-gate 	const struct priv_set *zone_privs;
189813Sdp 	size_t zone_privssz;
1900Sstevel@tonic-gate 	const char *rctlbuf;
1910Sstevel@tonic-gate 	size_t rctlbufsz;
1920Sstevel@tonic-gate 	int *extended_error;
193789Sahrens 	const char *zfsbuf;
194789Sahrens 	size_t zfsbufsz;
1951676Sjpk 	int match;			/* match level */
1962110Srica 	uint32_t doi;			/* DOI for label */
1971676Sjpk 	const bslabel_t *label;		/* label associated with zone */
1983448Sdh155122 	int flags;
1990Sstevel@tonic-gate } zone_def;
2000Sstevel@tonic-gate 
2010Sstevel@tonic-gate /* extended error information */
2020Sstevel@tonic-gate #define	ZE_UNKNOWN	0	/* No extended error info */
2030Sstevel@tonic-gate #define	ZE_CHROOTED	1	/* tried to zone_create from chroot */
2040Sstevel@tonic-gate #define	ZE_AREMOUNTS	2	/* there are mounts within the zone */
2054791Ston #define	ZE_LABELINUSE	3	/* label is already in use by some other zone */
2060Sstevel@tonic-gate 
207*13096SJordan.Vaughan@Sun.com /*
208*13096SJordan.Vaughan@Sun.com  * zone_status values
209*13096SJordan.Vaughan@Sun.com  *
210*13096SJordan.Vaughan@Sun.com  * You must modify zone_status_names in mdb(1M)'s genunix module
211*13096SJordan.Vaughan@Sun.com  * (genunix/zone.c) when you modify this enum.
212*13096SJordan.Vaughan@Sun.com  */
2130Sstevel@tonic-gate typedef enum {
2140Sstevel@tonic-gate 	ZONE_IS_UNINITIALIZED = 0,
2155880Snordmark 	ZONE_IS_INITIALIZED,
2160Sstevel@tonic-gate 	ZONE_IS_READY,
2170Sstevel@tonic-gate 	ZONE_IS_BOOTING,
2180Sstevel@tonic-gate 	ZONE_IS_RUNNING,
2190Sstevel@tonic-gate 	ZONE_IS_SHUTTING_DOWN,
2200Sstevel@tonic-gate 	ZONE_IS_EMPTY,
2210Sstevel@tonic-gate 	ZONE_IS_DOWN,
2220Sstevel@tonic-gate 	ZONE_IS_DYING,
2230Sstevel@tonic-gate 	ZONE_IS_DEAD
2240Sstevel@tonic-gate } zone_status_t;
2250Sstevel@tonic-gate #define	ZONE_MIN_STATE		ZONE_IS_UNINITIALIZED
2260Sstevel@tonic-gate #define	ZONE_MAX_STATE		ZONE_IS_DEAD
2270Sstevel@tonic-gate 
2280Sstevel@tonic-gate /*
2290Sstevel@tonic-gate  * Valid commands which may be issued by zoneadm to zoneadmd.  The kernel also
2300Sstevel@tonic-gate  * communicates with zoneadmd, but only uses Z_REBOOT and Z_HALT.
2310Sstevel@tonic-gate  */
2320Sstevel@tonic-gate typedef enum zone_cmd {
2332712Snn35248 	Z_READY, Z_BOOT, Z_FORCEBOOT, Z_REBOOT, Z_HALT, Z_NOTE_UNINSTALLING,
2342712Snn35248 	Z_MOUNT, Z_FORCEMOUNT, Z_UNMOUNT
2350Sstevel@tonic-gate } zone_cmd_t;
2360Sstevel@tonic-gate 
2370Sstevel@tonic-gate /*
2380Sstevel@tonic-gate  * The structure of a request to zoneadmd.
2390Sstevel@tonic-gate  */
2400Sstevel@tonic-gate typedef struct zone_cmd_arg {
2410Sstevel@tonic-gate 	uint64_t	uniqid;		/* unique "generation number" */
2420Sstevel@tonic-gate 	zone_cmd_t	cmd;		/* requested action */
2432267Sdp 	uint32_t	_pad;		/* need consistent 32/64 bit alignmt */
2440Sstevel@tonic-gate 	char locale[MAXPATHLEN];	/* locale in which to render messages */
2452267Sdp 	char bootbuf[BOOTARGS_MAX];	/* arguments passed to zone_boot() */
2460Sstevel@tonic-gate } zone_cmd_arg_t;
2470Sstevel@tonic-gate 
2480Sstevel@tonic-gate /*
2490Sstevel@tonic-gate  * Structure of zoneadmd's response to a request.  A NULL return value means
2500Sstevel@tonic-gate  * the caller should attempt to restart zoneadmd and retry.
2510Sstevel@tonic-gate  */
2520Sstevel@tonic-gate typedef struct zone_cmd_rval {
2530Sstevel@tonic-gate 	int rval;			/* return value of request */
2540Sstevel@tonic-gate 	char errbuf[1];	/* variable-sized buffer containing error messages */
2550Sstevel@tonic-gate } zone_cmd_rval_t;
2560Sstevel@tonic-gate 
2570Sstevel@tonic-gate /*
2580Sstevel@tonic-gate  * The zone support infrastructure uses the zone name as a component
2590Sstevel@tonic-gate  * of unix domain (AF_UNIX) sockets, which are limited to 108 characters
2600Sstevel@tonic-gate  * in length, so ZONENAME_MAX is limited by that.
2610Sstevel@tonic-gate  */
2620Sstevel@tonic-gate #define	ZONENAME_MAX		64
2630Sstevel@tonic-gate 
2640Sstevel@tonic-gate #define	GLOBAL_ZONENAME		"global"
2650Sstevel@tonic-gate 
2660Sstevel@tonic-gate /*
2670Sstevel@tonic-gate  * Extended Regular expression (see regex(5)) which matches all valid zone
2680Sstevel@tonic-gate  * names.
2690Sstevel@tonic-gate  */
2700Sstevel@tonic-gate #define	ZONENAME_REGEXP		"[a-zA-Z0-9][-_.a-zA-Z0-9]{0,62}"
2710Sstevel@tonic-gate 
2720Sstevel@tonic-gate /*
2730Sstevel@tonic-gate  * Where the zones support infrastructure places temporary files.
2740Sstevel@tonic-gate  */
2750Sstevel@tonic-gate #define	ZONES_TMPDIR		"/var/run/zones"
2760Sstevel@tonic-gate 
2770Sstevel@tonic-gate /*
2780Sstevel@tonic-gate  * The path to the door used by clients to communicate with zoneadmd.
2790Sstevel@tonic-gate  */
2800Sstevel@tonic-gate #define	ZONE_DOOR_PATH		ZONES_TMPDIR "/%s.zoneadmd_door"
2810Sstevel@tonic-gate 
282*13096SJordan.Vaughan@Sun.com 
2833448Sdh155122 /* zone_flags */
284*13096SJordan.Vaughan@Sun.com /*
285*13096SJordan.Vaughan@Sun.com  * Threads that read or write the following flag must hold zone_lock.
286*13096SJordan.Vaughan@Sun.com  */
287*13096SJordan.Vaughan@Sun.com #define	ZF_REFCOUNTS_LOGGED	0x1	/* a thread logged the zone's refs */
288*13096SJordan.Vaughan@Sun.com 
289*13096SJordan.Vaughan@Sun.com /*
290*13096SJordan.Vaughan@Sun.com  * The following threads are set when the zone is created and never changed.
291*13096SJordan.Vaughan@Sun.com  * Threads that test for these flags don't have to hold zone_lock.
292*13096SJordan.Vaughan@Sun.com  */
2933448Sdh155122 #define	ZF_HASHED_LABEL		0x2	/* zone has a unique label */
2943448Sdh155122 #define	ZF_IS_SCRATCH		0x4	/* scratch zone */
2953448Sdh155122 #define	ZF_NET_EXCL		0x8	/* Zone has an exclusive IP stack */
2963448Sdh155122 
297*13096SJordan.Vaughan@Sun.com 
2983448Sdh155122 /* zone_create flags */
2993448Sdh155122 #define	ZCF_NET_EXCL		0x1	/* Create a zone with exclusive IP */
3003448Sdh155122 
30112748SSowmini.Varadhan@oracle.COM /* zone network properties */
30212748SSowmini.Varadhan@oracle.COM #define	ZONE_NETWORK_ADDRESS	1
30312748SSowmini.Varadhan@oracle.COM #define	ZONE_NETWORK_DEFROUTER	2
30412748SSowmini.Varadhan@oracle.COM 
30512748SSowmini.Varadhan@oracle.COM #define	ZONE_NET_ADDRNAME	"address"
30612748SSowmini.Varadhan@oracle.COM #define	ZONE_NET_RTRNAME	"route"
30712748SSowmini.Varadhan@oracle.COM 
30812748SSowmini.Varadhan@oracle.COM typedef struct zone_net_data {
30912748SSowmini.Varadhan@oracle.COM 	int zn_type;
31012748SSowmini.Varadhan@oracle.COM 	int zn_len;
31112748SSowmini.Varadhan@oracle.COM 	datalink_id_t zn_linkid;
31212748SSowmini.Varadhan@oracle.COM 	uint8_t zn_val[1];
31312748SSowmini.Varadhan@oracle.COM } zone_net_data_t;
31412748SSowmini.Varadhan@oracle.COM 
31512748SSowmini.Varadhan@oracle.COM 
3160Sstevel@tonic-gate #ifdef _KERNEL
317*13096SJordan.Vaughan@Sun.com 
3180Sstevel@tonic-gate /*
3190Sstevel@tonic-gate  * We need to protect the definition of 'list_t' from userland applications and
3200Sstevel@tonic-gate  * libraries which may be defining ther own versions.
3210Sstevel@tonic-gate  */
3220Sstevel@tonic-gate #include <sys/list.h>
3230Sstevel@tonic-gate 
3240Sstevel@tonic-gate #define	GLOBAL_ZONEUNIQID	0	/* uniqid of the global zone */
3250Sstevel@tonic-gate 
3260Sstevel@tonic-gate struct pool;
3272712Snn35248 struct brand;
3280Sstevel@tonic-gate 
329789Sahrens /*
330*13096SJordan.Vaughan@Sun.com  * Each of these constants identifies a kernel subsystem that acquires and
331*13096SJordan.Vaughan@Sun.com  * releases zone references.  Each subsystem that invokes
332*13096SJordan.Vaughan@Sun.com  * zone_hold_ref() and zone_rele_ref() should specify the
333*13096SJordan.Vaughan@Sun.com  * zone_ref_subsys_t constant associated with the subsystem.  Tracked holds
334*13096SJordan.Vaughan@Sun.com  * help users and developers quickly identify subsystems that stall zone
335*13096SJordan.Vaughan@Sun.com  * shutdowns indefinitely.
336*13096SJordan.Vaughan@Sun.com  *
337*13096SJordan.Vaughan@Sun.com  * NOTE: You must modify zone_ref_subsys_names in usr/src/uts/common/os/zone.c
338*13096SJordan.Vaughan@Sun.com  * when you modify this enumeration.
339*13096SJordan.Vaughan@Sun.com  */
340*13096SJordan.Vaughan@Sun.com typedef enum zone_ref_subsys {
341*13096SJordan.Vaughan@Sun.com 	ZONE_REF_NFS,			/* NFS */
342*13096SJordan.Vaughan@Sun.com 	ZONE_REF_NFSV4,			/* NFSv4 */
343*13096SJordan.Vaughan@Sun.com 	ZONE_REF_SMBFS,			/* SMBFS */
344*13096SJordan.Vaughan@Sun.com 	ZONE_REF_MNTFS,			/* MNTFS */
345*13096SJordan.Vaughan@Sun.com 	ZONE_REF_LOFI,			/* LOFI devices */
346*13096SJordan.Vaughan@Sun.com 	ZONE_REF_VFS,			/* VFS infrastructure */
347*13096SJordan.Vaughan@Sun.com 	ZONE_REF_IPC,			/* IPC infrastructure */
348*13096SJordan.Vaughan@Sun.com 	ZONE_REF_NUM_SUBSYS		/* This must be the last entry. */
349*13096SJordan.Vaughan@Sun.com } zone_ref_subsys_t;
350*13096SJordan.Vaughan@Sun.com 
351*13096SJordan.Vaughan@Sun.com /*
352*13096SJordan.Vaughan@Sun.com  * zone_ref represents a general-purpose references to a zone.  Each zone's
353*13096SJordan.Vaughan@Sun.com  * references are linked into the zone's zone_t::zone_ref_list.  This allows
354*13096SJordan.Vaughan@Sun.com  * debuggers to walk zones' references.
355*13096SJordan.Vaughan@Sun.com  */
356*13096SJordan.Vaughan@Sun.com typedef struct zone_ref {
357*13096SJordan.Vaughan@Sun.com 	struct zone	*zref_zone; /* the zone to which the reference refers */
358*13096SJordan.Vaughan@Sun.com 	list_node_t	zref_linkage; /* linkage for zone_t::zone_ref_list */
359*13096SJordan.Vaughan@Sun.com } zone_ref_t;
360*13096SJordan.Vaughan@Sun.com 
361*13096SJordan.Vaughan@Sun.com /*
362789Sahrens  * Structure to record list of ZFS datasets exported to a zone.
363789Sahrens  */
364789Sahrens typedef struct zone_dataset {
365789Sahrens 	char		*zd_dataset;
366789Sahrens 	list_node_t	zd_linkage;
367789Sahrens } zone_dataset_t;
368789Sahrens 
3693247Sgjelinek /*
3703247Sgjelinek  * structure for zone kstats
3713247Sgjelinek  */
3723247Sgjelinek typedef struct zone_kstat {
3733247Sgjelinek 	kstat_named_t zk_zonename;
3743247Sgjelinek 	kstat_named_t zk_usage;
3753247Sgjelinek 	kstat_named_t zk_value;
3763247Sgjelinek } zone_kstat_t;
3773247Sgjelinek 
3783792Sakolb struct cpucap;
3793792Sakolb 
3800Sstevel@tonic-gate typedef struct zone {
3810Sstevel@tonic-gate 	/*
3820Sstevel@tonic-gate 	 * zone_name is never modified once set.
3830Sstevel@tonic-gate 	 */
3840Sstevel@tonic-gate 	char		*zone_name;	/* zone's configuration name */
3850Sstevel@tonic-gate 	/*
3860Sstevel@tonic-gate 	 * zone_nodename and zone_domain are never freed once allocated.
3870Sstevel@tonic-gate 	 */
3880Sstevel@tonic-gate 	char		*zone_nodename;	/* utsname.nodename equivalent */
3890Sstevel@tonic-gate 	char		*zone_domain;	/* srpc_domain equivalent */
3900Sstevel@tonic-gate 	/*
3918662SJordan.Vaughan@Sun.com 	 * zone_hostid is used for per-zone hostid emulation.
3928662SJordan.Vaughan@Sun.com 	 * Currently it isn't modified after it's set (so no locks protect
3938662SJordan.Vaughan@Sun.com 	 * accesses), but that might have to change when we allow
3948662SJordan.Vaughan@Sun.com 	 * administrators to change running zones' properties.
3958662SJordan.Vaughan@Sun.com 	 *
3968662SJordan.Vaughan@Sun.com 	 * The global zone's zone_hostid must always be HW_INVALID_HOSTID so
3978662SJordan.Vaughan@Sun.com 	 * that zone_get_hostid() will function correctly.
3988662SJordan.Vaughan@Sun.com 	 */
3998662SJordan.Vaughan@Sun.com 	uint32_t	zone_hostid;	/* zone's hostid, HW_INVALID_HOSTID */
4008662SJordan.Vaughan@Sun.com 					/* if not emulated */
4018662SJordan.Vaughan@Sun.com 	/*
4020Sstevel@tonic-gate 	 * zone_lock protects the following fields of a zone_t:
4030Sstevel@tonic-gate 	 * 	zone_ref
4040Sstevel@tonic-gate 	 * 	zone_cred_ref
405*13096SJordan.Vaughan@Sun.com 	 * 	zone_subsys_ref
406*13096SJordan.Vaughan@Sun.com 	 * 	zone_ref_list
4070Sstevel@tonic-gate 	 * 	zone_ntasks
4080Sstevel@tonic-gate 	 * 	zone_flags
4090Sstevel@tonic-gate 	 * 	zone_zsd
41012273SCasper.Dik@Sun.COM 	 *	zone_pfexecd
4110Sstevel@tonic-gate 	 */
4120Sstevel@tonic-gate 	kmutex_t	zone_lock;
4130Sstevel@tonic-gate 	/*
4140Sstevel@tonic-gate 	 * zone_linkage is the zone's linkage into the active or
4150Sstevel@tonic-gate 	 * death-row list.  The field is protected by zonehash_lock.
4160Sstevel@tonic-gate 	 */
4170Sstevel@tonic-gate 	list_node_t	zone_linkage;
4180Sstevel@tonic-gate 	zoneid_t	zone_id;	/* ID of zone */
4190Sstevel@tonic-gate 	uint_t		zone_ref;	/* count of zone_hold()s on zone */
4200Sstevel@tonic-gate 	uint_t		zone_cred_ref;	/* count of zone_hold_cred()s on zone */
4210Sstevel@tonic-gate 	/*
422*13096SJordan.Vaughan@Sun.com 	 * Fixed-sized array of subsystem-specific reference counts
423*13096SJordan.Vaughan@Sun.com 	 * The sum of all of the counts must be less than or equal to zone_ref.
424*13096SJordan.Vaughan@Sun.com 	 * The array is indexed by the counts' subsystems' zone_ref_subsys_t
425*13096SJordan.Vaughan@Sun.com 	 * constants.
426*13096SJordan.Vaughan@Sun.com 	 */
427*13096SJordan.Vaughan@Sun.com 	uint_t		zone_subsys_ref[ZONE_REF_NUM_SUBSYS];
428*13096SJordan.Vaughan@Sun.com 	list_t		zone_ref_list;	/* list of zone_ref_t structs */
429*13096SJordan.Vaughan@Sun.com 	/*
4300Sstevel@tonic-gate 	 * zone_rootvp and zone_rootpath can never be modified once set.
4310Sstevel@tonic-gate 	 */
4320Sstevel@tonic-gate 	struct vnode	*zone_rootvp;	/* zone's root vnode */
4330Sstevel@tonic-gate 	char		*zone_rootpath;	/* Path to zone's root + '/' */
4340Sstevel@tonic-gate 	ushort_t	zone_flags;	/* misc flags */
4350Sstevel@tonic-gate 	zone_status_t	zone_status;	/* protected by zone_status_lock */
4360Sstevel@tonic-gate 	uint_t		zone_ntasks;	/* number of tasks executing in zone */
4370Sstevel@tonic-gate 	kmutex_t	zone_nlwps_lock; /* protects zone_nlwps, and *_nlwps */
4380Sstevel@tonic-gate 					/* counters in projects and tasks */
4390Sstevel@tonic-gate 					/* that are within the zone */
4400Sstevel@tonic-gate 	rctl_qty_t	zone_nlwps;	/* number of lwps in zone */
4410Sstevel@tonic-gate 	rctl_qty_t	zone_nlwps_ctl; /* protected by zone_rctls->rcs_lock */
4422677Sml93401 	rctl_qty_t	zone_shmmax;	/* System V shared memory usage */
4432677Sml93401 	ipc_rqty_t	zone_ipc;	/* System V IPC id resource usage */
4440Sstevel@tonic-gate 
4450Sstevel@tonic-gate 	uint_t		zone_rootpathlen; /* strlen(zone_rootpath) + 1 */
4460Sstevel@tonic-gate 	uint32_t	zone_shares;	/* FSS shares allocated to zone */
4470Sstevel@tonic-gate 	rctl_set_t	*zone_rctls;	/* zone-wide (zone.*) rctls */
4483247Sgjelinek 	kmutex_t	zone_mem_lock;	/* protects zone_locked_mem and */
4492768Ssl108498 					/* kpd_locked_mem for all */
4503247Sgjelinek 					/* projects in zone. */
4513247Sgjelinek 					/* Also protects zone_max_swap */
4522768Ssl108498 					/* grab after p_lock, before rcs_lock */
4533247Sgjelinek 	rctl_qty_t	zone_locked_mem;	/* bytes of locked memory in */
4543247Sgjelinek 						/* zone */
4553247Sgjelinek 	rctl_qty_t	zone_locked_mem_ctl;	/* Current locked memory */
4562768Ssl108498 						/* limit.  Protected by */
4572768Ssl108498 						/* zone_rctls->rcs_lock */
4583247Sgjelinek 	rctl_qty_t	zone_max_swap; /* bytes of swap reserved by zone */
4593247Sgjelinek 	rctl_qty_t	zone_max_swap_ctl;	/* current swap limit. */
4603247Sgjelinek 						/* Protected by */
4613247Sgjelinek 						/* zone_rctls->rcs_lock */
46212633Sjohn.levon@sun.com 	kmutex_t	zone_rctl_lock;	/* protects zone_max_lofi */
46312633Sjohn.levon@sun.com 	rctl_qty_t	zone_max_lofi; /* lofi devs for zone */
46412633Sjohn.levon@sun.com 	rctl_qty_t	zone_max_lofi_ctl;	/* current lofi limit. */
46512633Sjohn.levon@sun.com 						/* Protected by */
46612633Sjohn.levon@sun.com 						/* zone_rctls->rcs_lock */
4670Sstevel@tonic-gate 	list_t		zone_zsd;	/* list of Zone-Specific Data values */
4680Sstevel@tonic-gate 	kcondvar_t	zone_cv;	/* used to signal state changes */
4690Sstevel@tonic-gate 	struct proc	*zone_zsched;	/* Dummy kernel "zsched" process */
4700Sstevel@tonic-gate 	pid_t		zone_proc_initpid; /* pid of "init" for this zone */
4712267Sdp 	char		*zone_initname;	/* fs path to 'init' */
4720Sstevel@tonic-gate 	int		zone_boot_err;  /* for zone_boot() if boot fails */
4730Sstevel@tonic-gate 	char		*zone_bootargs;	/* arguments passed via zone_boot() */
4743247Sgjelinek 	uint64_t	zone_phys_mcap;	/* physical memory cap */
4750Sstevel@tonic-gate 	/*
4760Sstevel@tonic-gate 	 * zone_kthreads is protected by zone_status_lock.
4770Sstevel@tonic-gate 	 */
4780Sstevel@tonic-gate 	kthread_t	*zone_kthreads;	/* kernel threads in zone */
4790Sstevel@tonic-gate 	struct priv_set	*zone_privset;	/* limit set for zone */
4800Sstevel@tonic-gate 	/*
4810Sstevel@tonic-gate 	 * zone_vfslist is protected by vfs_list_lock().
4820Sstevel@tonic-gate 	 */
4830Sstevel@tonic-gate 	struct vfs	*zone_vfslist;	/* list of FS's mounted in zone */
4840Sstevel@tonic-gate 	uint64_t	zone_uniqid;	/* unique zone generation number */
4850Sstevel@tonic-gate 	struct cred	*zone_kcred;	/* kcred-like, zone-limited cred */
4860Sstevel@tonic-gate 	/*
4870Sstevel@tonic-gate 	 * zone_pool is protected by pool_lock().
4880Sstevel@tonic-gate 	 */
4890Sstevel@tonic-gate 	struct pool	*zone_pool;	/* pool the zone is bound to */
4900Sstevel@tonic-gate 	hrtime_t	zone_pool_mod;	/* last pool bind modification time */
4910Sstevel@tonic-gate 	/* zone_psetid is protected by cpu_lock */
4920Sstevel@tonic-gate 	psetid_t	zone_psetid;	/* pset the zone is bound to */
4930Sstevel@tonic-gate 	/*
4940Sstevel@tonic-gate 	 * The following two can be read without holding any locks.  They are
4950Sstevel@tonic-gate 	 * updated under cpu_lock.
4960Sstevel@tonic-gate 	 */
4970Sstevel@tonic-gate 	int		zone_ncpus;  /* zone's idea of ncpus */
4980Sstevel@tonic-gate 	int		zone_ncpus_online; /* zone's idea of ncpus_online */
499789Sahrens 	/*
500789Sahrens 	 * List of ZFS datasets exported to this zone.
501789Sahrens 	 */
502789Sahrens 	list_t		zone_datasets;	/* list of datasets */
5031676Sjpk 
5042110Srica 	ts_label_t	*zone_slabel;	/* zone sensitivity label */
5052110Srica 	int		zone_match;	/* require label match for packets */
5061676Sjpk 	tsol_mlp_list_t zone_mlps;	/* MLPs on zone-private addresses */
5072267Sdp 
5082712Snn35248 	boolean_t	zone_restart_init;	/* Restart init if it dies? */
5092712Snn35248 	struct brand	*zone_brand;		/* zone's brand */
5104888Seh208807 	void 		*zone_brand_data;	/* store brand specific data */
5113247Sgjelinek 	id_t		zone_defaultcid;	/* dflt scheduling class id */
5123247Sgjelinek 	kstat_t		*zone_swapresv_kstat;
5133247Sgjelinek 	kstat_t		*zone_lockedmem_kstat;
5143448Sdh155122 	/*
5153448Sdh155122 	 * zone_dl_list is protected by zone_lock
5163448Sdh155122 	 */
51710616SSebastien.Roy@Sun.COM 	list_t		zone_dl_list;
5183448Sdh155122 	netstack_t	*zone_netstack;
5193792Sakolb 	struct cpucap	*zone_cpucap;	/* CPU caps data */
5204197Spaulson 	/*
5214197Spaulson 	 * Solaris Auditing per-zone audit context
5224197Spaulson 	 */
5234197Spaulson 	struct au_kcontext	*zone_audit_kctxt;
52410910SRobert.Harris@Sun.COM 	/*
52510910SRobert.Harris@Sun.COM 	 * For private use by mntfs.
52610910SRobert.Harris@Sun.COM 	 */
52710910SRobert.Harris@Sun.COM 	struct mntelem	*zone_mntfs_db;
52810910SRobert.Harris@Sun.COM 	krwlock_t	zone_mntfs_db_lock;
52912273SCasper.Dik@Sun.COM 
53012273SCasper.Dik@Sun.COM 	struct klpd_reg		*zone_pfexecd;
53112633Sjohn.levon@sun.com 
53212633Sjohn.levon@sun.com 	char		*zone_fs_allowed;
53312725SMenno.Lageman@Sun.COM 	rctl_qty_t	zone_nprocs;	/* number of processes in the zone */
53412725SMenno.Lageman@Sun.COM 	rctl_qty_t	zone_nprocs_ctl;	/* current limit protected by */
53512725SMenno.Lageman@Sun.COM 						/* zone_rctls->rcs_lock */
53612725SMenno.Lageman@Sun.COM 	kstat_t		*zone_nprocs_kstat;
5370Sstevel@tonic-gate } zone_t;
5380Sstevel@tonic-gate 
5390Sstevel@tonic-gate /*
5400Sstevel@tonic-gate  * Special value of zone_psetid to indicate that pools are disabled.
5410Sstevel@tonic-gate  */
5420Sstevel@tonic-gate #define	ZONE_PS_INVAL	PS_MYID
5430Sstevel@tonic-gate 
5443448Sdh155122 
5450Sstevel@tonic-gate extern zone_t zone0;
5460Sstevel@tonic-gate extern zone_t *global_zone;
5470Sstevel@tonic-gate extern uint_t maxzones;
5480Sstevel@tonic-gate extern rctl_hndl_t rc_zone_nlwps;
54912725SMenno.Lageman@Sun.COM extern rctl_hndl_t rc_zone_nprocs;
5500Sstevel@tonic-gate 
551789Sahrens extern long zone(int, void *, void *, void *, void *);
5520Sstevel@tonic-gate extern void zone_zsd_init(void);
5530Sstevel@tonic-gate extern void zone_init(void);
5540Sstevel@tonic-gate extern void zone_hold(zone_t *);
5550Sstevel@tonic-gate extern void zone_rele(zone_t *);
556*13096SJordan.Vaughan@Sun.com extern void zone_init_ref(zone_ref_t *);
557*13096SJordan.Vaughan@Sun.com extern void zone_hold_ref(zone_t *, zone_ref_t *, zone_ref_subsys_t);
558*13096SJordan.Vaughan@Sun.com extern void zone_rele_ref(zone_ref_t *, zone_ref_subsys_t);
5590Sstevel@tonic-gate extern void zone_cred_hold(zone_t *);
5600Sstevel@tonic-gate extern void zone_cred_rele(zone_t *);
5610Sstevel@tonic-gate extern void zone_task_hold(zone_t *);
5620Sstevel@tonic-gate extern void zone_task_rele(zone_t *);
5630Sstevel@tonic-gate extern zone_t *zone_find_by_id(zoneid_t);
5641676Sjpk extern zone_t *zone_find_by_label(const ts_label_t *);
5650Sstevel@tonic-gate extern zone_t *zone_find_by_name(char *);
5661769Scarlsonj extern zone_t *zone_find_by_any_path(const char *, boolean_t);
5670Sstevel@tonic-gate extern zone_t *zone_find_by_path(const char *);
5680Sstevel@tonic-gate extern zoneid_t getzoneid(void);
5693448Sdh155122 extern zone_t *zone_find_by_id_nolock(zoneid_t);
57010616SSebastien.Roy@Sun.COM extern int zone_datalink_walk(zoneid_t, int (*)(datalink_id_t, void *), void *);
57110616SSebastien.Roy@Sun.COM extern int zone_check_datalink(zoneid_t *, datalink_id_t);
5720Sstevel@tonic-gate 
5730Sstevel@tonic-gate /*
5740Sstevel@tonic-gate  * Zone-specific data (ZSD) APIs
5750Sstevel@tonic-gate  */
5760Sstevel@tonic-gate /*
5770Sstevel@tonic-gate  * The following is what code should be initializing its zone_key_t to if it
5780Sstevel@tonic-gate  * calls zone_getspecific() without necessarily knowing that zone_key_create()
5790Sstevel@tonic-gate  * has been called on the key.
5800Sstevel@tonic-gate  */
5810Sstevel@tonic-gate #define	ZONE_KEY_UNINITIALIZED	0
5820Sstevel@tonic-gate 
5830Sstevel@tonic-gate typedef uint_t zone_key_t;
5840Sstevel@tonic-gate 
5850Sstevel@tonic-gate extern void	zone_key_create(zone_key_t *, void *(*)(zoneid_t),
5860Sstevel@tonic-gate     void (*)(zoneid_t, void *), void (*)(zoneid_t, void *));
5870Sstevel@tonic-gate extern int 	zone_key_delete(zone_key_t);
5880Sstevel@tonic-gate extern void	*zone_getspecific(zone_key_t, zone_t *);
5890Sstevel@tonic-gate extern int	zone_setspecific(zone_key_t, zone_t *, const void *);
5900Sstevel@tonic-gate 
5910Sstevel@tonic-gate /*
5920Sstevel@tonic-gate  * The definition of a zsd_entry is truly private to zone.c and is only
5930Sstevel@tonic-gate  * placed here so it can be shared with mdb.
5945880Snordmark  *
5955880Snordmark  * State maintained for each zone times each registered key, which tracks
5965880Snordmark  * the state of the create, shutdown and destroy callbacks.
5975880Snordmark  *
5985880Snordmark  * zsd_flags is used to keep track of pending actions to avoid holding locks
5995880Snordmark  * when calling the create/shutdown/destroy callbacks, since doing so
6005880Snordmark  * could lead to deadlocks.
6010Sstevel@tonic-gate  */
6020Sstevel@tonic-gate struct zsd_entry {
6030Sstevel@tonic-gate 	zone_key_t		zsd_key;	/* Key used to lookup value */
6040Sstevel@tonic-gate 	void			*zsd_data;	/* Caller-managed value */
6050Sstevel@tonic-gate 	/*
6060Sstevel@tonic-gate 	 * Callbacks to be executed when a zone is created, shutdown, and
6070Sstevel@tonic-gate 	 * destroyed, respectively.
6080Sstevel@tonic-gate 	 */
6090Sstevel@tonic-gate 	void			*(*zsd_create)(zoneid_t);
6100Sstevel@tonic-gate 	void			(*zsd_shutdown)(zoneid_t, void *);
6110Sstevel@tonic-gate 	void			(*zsd_destroy)(zoneid_t, void *);
6120Sstevel@tonic-gate 	list_node_t		zsd_linkage;
6135880Snordmark 	uint16_t 		zsd_flags;	/* See below */
6145880Snordmark 	kcondvar_t		zsd_cv;
6150Sstevel@tonic-gate };
6160Sstevel@tonic-gate 
6170Sstevel@tonic-gate /*
6185880Snordmark  * zsd_flags
6195880Snordmark  */
6205880Snordmark #define	ZSD_CREATE_NEEDED	0x0001
6215880Snordmark #define	ZSD_CREATE_INPROGRESS	0x0002
6225880Snordmark #define	ZSD_CREATE_COMPLETED	0x0004
6235880Snordmark #define	ZSD_SHUTDOWN_NEEDED	0x0010
6245880Snordmark #define	ZSD_SHUTDOWN_INPROGRESS	0x0020
6255880Snordmark #define	ZSD_SHUTDOWN_COMPLETED	0x0040
6265880Snordmark #define	ZSD_DESTROY_NEEDED	0x0100
6275880Snordmark #define	ZSD_DESTROY_INPROGRESS	0x0200
6285880Snordmark #define	ZSD_DESTROY_COMPLETED	0x0400
6295880Snordmark 
6305880Snordmark #define	ZSD_CREATE_ALL	\
6315880Snordmark 	(ZSD_CREATE_NEEDED|ZSD_CREATE_INPROGRESS|ZSD_CREATE_COMPLETED)
6325880Snordmark #define	ZSD_SHUTDOWN_ALL	\
6335880Snordmark 	(ZSD_SHUTDOWN_NEEDED|ZSD_SHUTDOWN_INPROGRESS|ZSD_SHUTDOWN_COMPLETED)
6345880Snordmark #define	ZSD_DESTROY_ALL	\
6355880Snordmark 	(ZSD_DESTROY_NEEDED|ZSD_DESTROY_INPROGRESS|ZSD_DESTROY_COMPLETED)
6365880Snordmark 
6375880Snordmark #define	ZSD_ALL_INPROGRESS \
6385880Snordmark 	(ZSD_CREATE_INPROGRESS|ZSD_SHUTDOWN_INPROGRESS|ZSD_DESTROY_INPROGRESS)
6395880Snordmark 
6405880Snordmark /*
6410Sstevel@tonic-gate  * Macros to help with zone visibility restrictions.
6420Sstevel@tonic-gate  */
6430Sstevel@tonic-gate 
6440Sstevel@tonic-gate /*
6450Sstevel@tonic-gate  * Is process in the global zone?
6460Sstevel@tonic-gate  */
6470Sstevel@tonic-gate #define	INGLOBALZONE(p) \
6480Sstevel@tonic-gate 	((p)->p_zone == global_zone)
6490Sstevel@tonic-gate 
6500Sstevel@tonic-gate /*
6510Sstevel@tonic-gate  * Can process view objects in given zone?
6520Sstevel@tonic-gate  */
6530Sstevel@tonic-gate #define	HASZONEACCESS(p, zoneid) \
6540Sstevel@tonic-gate 	((p)->p_zone->zone_id == (zoneid) || INGLOBALZONE(p))
6550Sstevel@tonic-gate 
6560Sstevel@tonic-gate /*
6570Sstevel@tonic-gate  * Convenience macro to see if a resolved path is visible from within a
6580Sstevel@tonic-gate  * given zone.
6590Sstevel@tonic-gate  *
6600Sstevel@tonic-gate  * The basic idea is that the first (zone_rootpathlen - 1) bytes of the
6610Sstevel@tonic-gate  * two strings must be equal.  Since the rootpathlen has a trailing '/',
6620Sstevel@tonic-gate  * we want to skip everything in the path up to (but not including) the
6630Sstevel@tonic-gate  * trailing '/'.
6640Sstevel@tonic-gate  */
6650Sstevel@tonic-gate #define	ZONE_PATH_VISIBLE(path, zone) \
6660Sstevel@tonic-gate 	(strncmp((path), (zone)->zone_rootpath,		\
6670Sstevel@tonic-gate 	    (zone)->zone_rootpathlen - 1) == 0)
6680Sstevel@tonic-gate 
6690Sstevel@tonic-gate /*
6700Sstevel@tonic-gate  * Convenience macro to go from the global view of a path to that seen
6710Sstevel@tonic-gate  * from within said zone.  It is the responsibility of the caller to
6720Sstevel@tonic-gate  * ensure that the path is a resolved one (ie, no '..'s or '.'s), and is
6730Sstevel@tonic-gate  * in fact visible from within the zone.
6740Sstevel@tonic-gate  */
6750Sstevel@tonic-gate #define	ZONE_PATH_TRANSLATE(path, zone)	\
6760Sstevel@tonic-gate 	(ASSERT(ZONE_PATH_VISIBLE(path, zone)),	\
6770Sstevel@tonic-gate 	(path) + (zone)->zone_rootpathlen - 2)
6780Sstevel@tonic-gate 
6790Sstevel@tonic-gate /*
6800Sstevel@tonic-gate  * Special processes visible in all zones.
6810Sstevel@tonic-gate  */
6820Sstevel@tonic-gate #define	ZONE_SPECIALPID(x)	 ((x) == 0 || (x) == 1)
6830Sstevel@tonic-gate 
6840Sstevel@tonic-gate /*
6850Sstevel@tonic-gate  * Zone-safe version of thread_create() to be used when the caller wants to
6860Sstevel@tonic-gate  * create a kernel thread to run within the current zone's context.
6870Sstevel@tonic-gate  */
6880Sstevel@tonic-gate extern kthread_t *zthread_create(caddr_t, size_t, void (*)(), void *, size_t,
6890Sstevel@tonic-gate     pri_t);
6900Sstevel@tonic-gate extern void zthread_exit(void);
6910Sstevel@tonic-gate 
6920Sstevel@tonic-gate /*
6930Sstevel@tonic-gate  * Functions for an external observer to register interest in a zone's status
6940Sstevel@tonic-gate  * change.  Observers will be woken up when the zone status equals the status
6950Sstevel@tonic-gate  * argument passed in (in the case of zone_status_timedwait, the function may
6960Sstevel@tonic-gate  * also return because of a timeout; zone_status_wait_sig may return early due
6970Sstevel@tonic-gate  * to a signal being delivered; zone_status_timedwait_sig may return for any of
6980Sstevel@tonic-gate  * the above reasons).
6990Sstevel@tonic-gate  *
7000Sstevel@tonic-gate  * Otherwise these behave identically to cv_timedwait(), cv_wait(), and
7010Sstevel@tonic-gate  * cv_wait_sig() respectively.
7020Sstevel@tonic-gate  */
7030Sstevel@tonic-gate extern clock_t zone_status_timedwait(zone_t *, clock_t, zone_status_t);
7040Sstevel@tonic-gate extern clock_t zone_status_timedwait_sig(zone_t *, clock_t, zone_status_t);
7050Sstevel@tonic-gate extern void zone_status_wait(zone_t *, zone_status_t);
7060Sstevel@tonic-gate extern int zone_status_wait_sig(zone_t *, zone_status_t);
7070Sstevel@tonic-gate 
7080Sstevel@tonic-gate /*
7090Sstevel@tonic-gate  * Get the status  of the zone (at the time it was called).  The state may
7100Sstevel@tonic-gate  * have progressed by the time it is returned.
7110Sstevel@tonic-gate  */
7120Sstevel@tonic-gate extern zone_status_t zone_status_get(zone_t *);
7130Sstevel@tonic-gate 
7140Sstevel@tonic-gate /*
7158662SJordan.Vaughan@Sun.com  * Safely get the hostid of the specified zone (defaults to machine's hostid
7168662SJordan.Vaughan@Sun.com  * if the specified zone doesn't emulate a hostid).  Passing NULL retrieves
7178662SJordan.Vaughan@Sun.com  * the global zone's (i.e., physical system's) hostid.
7188662SJordan.Vaughan@Sun.com  */
7198662SJordan.Vaughan@Sun.com extern uint32_t zone_get_hostid(zone_t *);
7208662SJordan.Vaughan@Sun.com 
7218662SJordan.Vaughan@Sun.com /*
7220Sstevel@tonic-gate  * Get the "kcred" credentials corresponding to the given zone.
7230Sstevel@tonic-gate  */
7240Sstevel@tonic-gate extern struct cred *zone_get_kcred(zoneid_t);
7250Sstevel@tonic-gate 
7260Sstevel@tonic-gate /*
7270Sstevel@tonic-gate  * Get/set the pool the zone is currently bound to.
7280Sstevel@tonic-gate  */
7290Sstevel@tonic-gate extern struct pool *zone_pool_get(zone_t *);
7300Sstevel@tonic-gate extern void zone_pool_set(zone_t *, struct pool *);
7310Sstevel@tonic-gate 
7320Sstevel@tonic-gate /*
7330Sstevel@tonic-gate  * Get/set the pset the zone is currently using.
7340Sstevel@tonic-gate  */
7350Sstevel@tonic-gate extern psetid_t zone_pset_get(zone_t *);
7360Sstevel@tonic-gate extern void zone_pset_set(zone_t *, psetid_t);
7370Sstevel@tonic-gate 
7380Sstevel@tonic-gate /*
7390Sstevel@tonic-gate  * Get the number of cpus/online-cpus visible from the given zone.
7400Sstevel@tonic-gate  */
7410Sstevel@tonic-gate extern int zone_ncpus_get(zone_t *);
7420Sstevel@tonic-gate extern int zone_ncpus_online_get(zone_t *);
7430Sstevel@tonic-gate 
7440Sstevel@tonic-gate /*
745789Sahrens  * Returns true if the named pool/dataset is visible in the current zone.
746789Sahrens  */
747789Sahrens extern int zone_dataset_visible(const char *, int *);
748789Sahrens 
749789Sahrens /*
7502267Sdp  * zone version of kadmin()
7510Sstevel@tonic-gate  */
7522267Sdp extern int zone_kadmin(int, int, const char *, cred_t *);
7530Sstevel@tonic-gate extern void zone_shutdown_global(void);
7540Sstevel@tonic-gate 
7550Sstevel@tonic-gate extern void mount_in_progress(void);
7560Sstevel@tonic-gate extern void mount_completed(void);
7570Sstevel@tonic-gate 
7580Sstevel@tonic-gate extern int zone_walk(int (*)(zone_t *, void *), void *);
7590Sstevel@tonic-gate 
7602768Ssl108498 extern rctl_hndl_t rc_zone_locked_mem;
7613247Sgjelinek extern rctl_hndl_t rc_zone_max_swap;
76212633Sjohn.levon@sun.com extern rctl_hndl_t rc_zone_max_lofi;
7632768Ssl108498 
7640Sstevel@tonic-gate #endif	/* _KERNEL */
7650Sstevel@tonic-gate 
7660Sstevel@tonic-gate #ifdef	__cplusplus
7670Sstevel@tonic-gate }
7680Sstevel@tonic-gate #endif
7690Sstevel@tonic-gate 
7700Sstevel@tonic-gate #endif	/* _SYS_ZONE_H */
771