xref: /onnv-gate/usr/src/uts/common/sys/zone.h (revision 766:c521de78a32f)
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
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
230Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #ifndef _SYS_ZONE_H
280Sstevel@tonic-gate #define	_SYS_ZONE_H
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #include <sys/types.h>
330Sstevel@tonic-gate #include <sys/mutex.h>
340Sstevel@tonic-gate #include <sys/param.h>
350Sstevel@tonic-gate #include <sys/rctl.h>
360Sstevel@tonic-gate #include <sys/pset.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 
600Sstevel@tonic-gate /* system call subcodes */
610Sstevel@tonic-gate #define	ZONE_CREATE	0
620Sstevel@tonic-gate #define	ZONE_DESTROY	1
630Sstevel@tonic-gate #define	ZONE_GETATTR	2
640Sstevel@tonic-gate #define	ZONE_ENTER	3
650Sstevel@tonic-gate #define	ZONE_LIST	4
660Sstevel@tonic-gate #define	ZONE_SHUTDOWN	5
670Sstevel@tonic-gate #define	ZONE_LOOKUP	6
680Sstevel@tonic-gate #define	ZONE_BOOT	7
690Sstevel@tonic-gate 
700Sstevel@tonic-gate /* zone attributes */
710Sstevel@tonic-gate #define	ZONE_ATTR_ROOT		1
720Sstevel@tonic-gate #define	ZONE_ATTR_NAME		2
730Sstevel@tonic-gate #define	ZONE_ATTR_STATUS	3
740Sstevel@tonic-gate #define	ZONE_ATTR_PRIVSET	4
750Sstevel@tonic-gate #define	ZONE_ATTR_UNIQID	5
760Sstevel@tonic-gate #define	ZONE_ATTR_POOLID	6
770Sstevel@tonic-gate #define	ZONE_ATTR_INITPID	7
780Sstevel@tonic-gate 
790Sstevel@tonic-gate #ifdef _SYSCALL32
800Sstevel@tonic-gate typedef struct {
810Sstevel@tonic-gate 	caddr32_t zone_name;
820Sstevel@tonic-gate 	caddr32_t zone_root;
830Sstevel@tonic-gate 	caddr32_t zone_privs;
840Sstevel@tonic-gate 	caddr32_t rctlbuf;
850Sstevel@tonic-gate 	size32_t rctlbufsz;
860Sstevel@tonic-gate 	caddr32_t extended_error;
870Sstevel@tonic-gate } zone_def32;
880Sstevel@tonic-gate #endif
890Sstevel@tonic-gate typedef struct {
900Sstevel@tonic-gate 	const char *zone_name;
910Sstevel@tonic-gate 	const char *zone_root;
920Sstevel@tonic-gate 	const struct priv_set *zone_privs;
930Sstevel@tonic-gate 	const char *rctlbuf;
940Sstevel@tonic-gate 	size_t rctlbufsz;
950Sstevel@tonic-gate 	int *extended_error;
960Sstevel@tonic-gate } zone_def;
970Sstevel@tonic-gate 
980Sstevel@tonic-gate /* extended error information */
990Sstevel@tonic-gate #define	ZE_UNKNOWN	0	/* No extended error info */
1000Sstevel@tonic-gate #define	ZE_CHROOTED	1	/* tried to zone_create from chroot */
1010Sstevel@tonic-gate #define	ZE_AREMOUNTS	2	/* there are mounts within the zone */
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate /* zone_status */
1040Sstevel@tonic-gate typedef enum {
1050Sstevel@tonic-gate 	ZONE_IS_UNINITIALIZED = 0,
1060Sstevel@tonic-gate 	ZONE_IS_READY,
1070Sstevel@tonic-gate 	ZONE_IS_BOOTING,
1080Sstevel@tonic-gate 	ZONE_IS_RUNNING,
1090Sstevel@tonic-gate 	ZONE_IS_SHUTTING_DOWN,
1100Sstevel@tonic-gate 	ZONE_IS_EMPTY,
1110Sstevel@tonic-gate 	ZONE_IS_DOWN,
1120Sstevel@tonic-gate 	ZONE_IS_DYING,
1130Sstevel@tonic-gate 	ZONE_IS_DEAD
1140Sstevel@tonic-gate } zone_status_t;
1150Sstevel@tonic-gate #define	ZONE_MIN_STATE		ZONE_IS_UNINITIALIZED
1160Sstevel@tonic-gate #define	ZONE_MAX_STATE		ZONE_IS_DEAD
1170Sstevel@tonic-gate 
1180Sstevel@tonic-gate /*
1190Sstevel@tonic-gate  * Valid commands which may be issued by zoneadm to zoneadmd.  The kernel also
1200Sstevel@tonic-gate  * communicates with zoneadmd, but only uses Z_REBOOT and Z_HALT.
1210Sstevel@tonic-gate  */
1220Sstevel@tonic-gate typedef enum zone_cmd {
123*766Scarlsonj 	Z_READY, Z_BOOT, Z_REBOOT, Z_HALT, Z_NOTE_UNINSTALLING,
124*766Scarlsonj 	Z_MOUNT, Z_UNMOUNT
1250Sstevel@tonic-gate } zone_cmd_t;
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate #define	ZONEBOOTARGS_MAX	257	/* uadmin()'s buffer is 257 bytes. */
1280Sstevel@tonic-gate 
1290Sstevel@tonic-gate /*
1300Sstevel@tonic-gate  * The structure of a request to zoneadmd.
1310Sstevel@tonic-gate  */
1320Sstevel@tonic-gate typedef struct zone_cmd_arg {
1330Sstevel@tonic-gate 	uint64_t	uniqid;		/* unique "generation number" */
1340Sstevel@tonic-gate 	zone_cmd_t	cmd;		/* requested action */
1350Sstevel@tonic-gate 	char locale[MAXPATHLEN];	/* locale in which to render messages */
1360Sstevel@tonic-gate 	char bootbuf[ZONEBOOTARGS_MAX];	/* arguments passed to zone_boot() */
1370Sstevel@tonic-gate } zone_cmd_arg_t;
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate /*
1400Sstevel@tonic-gate  * Structure of zoneadmd's response to a request.  A NULL return value means
1410Sstevel@tonic-gate  * the caller should attempt to restart zoneadmd and retry.
1420Sstevel@tonic-gate  */
1430Sstevel@tonic-gate typedef struct zone_cmd_rval {
1440Sstevel@tonic-gate 	int rval;			/* return value of request */
1450Sstevel@tonic-gate 	char errbuf[1];	/* variable-sized buffer containing error messages */
1460Sstevel@tonic-gate } zone_cmd_rval_t;
1470Sstevel@tonic-gate 
1480Sstevel@tonic-gate /*
1490Sstevel@tonic-gate  * The zone support infrastructure uses the zone name as a component
1500Sstevel@tonic-gate  * of unix domain (AF_UNIX) sockets, which are limited to 108 characters
1510Sstevel@tonic-gate  * in length, so ZONENAME_MAX is limited by that.
1520Sstevel@tonic-gate  */
1530Sstevel@tonic-gate #define	ZONENAME_MAX		64
1540Sstevel@tonic-gate 
1550Sstevel@tonic-gate #define	GLOBAL_ZONENAME		"global"
1560Sstevel@tonic-gate 
1570Sstevel@tonic-gate /*
1580Sstevel@tonic-gate  * Extended Regular expression (see regex(5)) which matches all valid zone
1590Sstevel@tonic-gate  * names.
1600Sstevel@tonic-gate  */
1610Sstevel@tonic-gate #define	ZONENAME_REGEXP		"[a-zA-Z0-9][-_.a-zA-Z0-9]{0,62}"
1620Sstevel@tonic-gate 
1630Sstevel@tonic-gate /*
1640Sstevel@tonic-gate  * Where the zones support infrastructure places temporary files.
1650Sstevel@tonic-gate  */
1660Sstevel@tonic-gate #define	ZONES_TMPDIR		"/var/run/zones"
1670Sstevel@tonic-gate 
1680Sstevel@tonic-gate /*
1690Sstevel@tonic-gate  * The path to the door used by clients to communicate with zoneadmd.
1700Sstevel@tonic-gate  */
1710Sstevel@tonic-gate #define	ZONE_DOOR_PATH		ZONES_TMPDIR "/%s.zoneadmd_door"
1720Sstevel@tonic-gate 
1730Sstevel@tonic-gate 
1740Sstevel@tonic-gate #ifdef _KERNEL
1750Sstevel@tonic-gate /*
1760Sstevel@tonic-gate  * We need to protect the definition of 'list_t' from userland applications and
1770Sstevel@tonic-gate  * libraries which may be defining ther own versions.
1780Sstevel@tonic-gate  */
1790Sstevel@tonic-gate #include <sys/list.h>
1800Sstevel@tonic-gate 
1810Sstevel@tonic-gate #define	GLOBAL_ZONEUNIQID	0	/* uniqid of the global zone */
1820Sstevel@tonic-gate 
1830Sstevel@tonic-gate /* zone_flags */
1840Sstevel@tonic-gate #define	ZF_DESTROYED		0x1	/* ZSD destructor callbacks run */
1850Sstevel@tonic-gate 
1860Sstevel@tonic-gate struct pool;
1870Sstevel@tonic-gate 
1880Sstevel@tonic-gate typedef struct zone {
1890Sstevel@tonic-gate 	/*
1900Sstevel@tonic-gate 	 * zone_name is never modified once set.
1910Sstevel@tonic-gate 	 */
1920Sstevel@tonic-gate 	char		*zone_name;	/* zone's configuration name */
1930Sstevel@tonic-gate 	/*
1940Sstevel@tonic-gate 	 * zone_nodename and zone_domain are never freed once allocated.
1950Sstevel@tonic-gate 	 */
1960Sstevel@tonic-gate 	char		*zone_nodename;	/* utsname.nodename equivalent */
1970Sstevel@tonic-gate 	char		*zone_domain;	/* srpc_domain equivalent */
1980Sstevel@tonic-gate 	/*
1990Sstevel@tonic-gate 	 * zone_lock protects the following fields of a zone_t:
2000Sstevel@tonic-gate 	 * 	zone_ref
2010Sstevel@tonic-gate 	 * 	zone_cred_ref
2020Sstevel@tonic-gate 	 * 	zone_ntasks
2030Sstevel@tonic-gate 	 * 	zone_flags
2040Sstevel@tonic-gate 	 * 	zone_zsd
2050Sstevel@tonic-gate 	 */
2060Sstevel@tonic-gate 	kmutex_t	zone_lock;
2070Sstevel@tonic-gate 	/*
2080Sstevel@tonic-gate 	 * zone_linkage is the zone's linkage into the active or
2090Sstevel@tonic-gate 	 * death-row list.  The field is protected by zonehash_lock.
2100Sstevel@tonic-gate 	 */
2110Sstevel@tonic-gate 	list_node_t	zone_linkage;
2120Sstevel@tonic-gate 	zoneid_t	zone_id;	/* ID of zone */
2130Sstevel@tonic-gate 	uint_t		zone_ref;	/* count of zone_hold()s on zone */
2140Sstevel@tonic-gate 	uint_t		zone_cred_ref;	/* count of zone_hold_cred()s on zone */
2150Sstevel@tonic-gate 	/*
2160Sstevel@tonic-gate 	 * zone_rootvp and zone_rootpath can never be modified once set.
2170Sstevel@tonic-gate 	 */
2180Sstevel@tonic-gate 	struct vnode	*zone_rootvp;	/* zone's root vnode */
2190Sstevel@tonic-gate 	char		*zone_rootpath;	/* Path to zone's root + '/' */
2200Sstevel@tonic-gate 	ushort_t	zone_flags;	/* misc flags */
2210Sstevel@tonic-gate 	zone_status_t	zone_status;	/* protected by zone_status_lock */
2220Sstevel@tonic-gate 	uint_t		zone_ntasks;	/* number of tasks executing in zone */
2230Sstevel@tonic-gate 	kmutex_t	zone_nlwps_lock; /* protects zone_nlwps, and *_nlwps */
2240Sstevel@tonic-gate 					/* counters in projects and tasks */
2250Sstevel@tonic-gate 					/* that are within the zone */
2260Sstevel@tonic-gate 	rctl_qty_t	zone_nlwps;	/* number of lwps in zone */
2270Sstevel@tonic-gate 	rctl_qty_t	zone_nlwps_ctl; /* protected by zone_rctls->rcs_lock */
2280Sstevel@tonic-gate 
2290Sstevel@tonic-gate 	uint_t		zone_rootpathlen; /* strlen(zone_rootpath) + 1 */
2300Sstevel@tonic-gate 	uint32_t	zone_shares;	/* FSS shares allocated to zone */
2310Sstevel@tonic-gate 	rctl_set_t	*zone_rctls;	/* zone-wide (zone.*) rctls */
2320Sstevel@tonic-gate 	list_t		zone_zsd;	/* list of Zone-Specific Data values */
2330Sstevel@tonic-gate 	kcondvar_t	zone_cv;	/* used to signal state changes */
2340Sstevel@tonic-gate 	struct proc	*zone_zsched;	/* Dummy kernel "zsched" process */
2350Sstevel@tonic-gate 	pid_t		zone_proc_initpid; /* pid of "init" for this zone */
2360Sstevel@tonic-gate 	int		zone_boot_err;  /* for zone_boot() if boot fails */
2370Sstevel@tonic-gate 	char		*zone_bootargs;	/* arguments passed via zone_boot() */
2380Sstevel@tonic-gate 	/*
2390Sstevel@tonic-gate 	 * zone_kthreads is protected by zone_status_lock.
2400Sstevel@tonic-gate 	 */
2410Sstevel@tonic-gate 	kthread_t	*zone_kthreads;	/* kernel threads in zone */
2420Sstevel@tonic-gate 	struct priv_set	*zone_privset;	/* limit set for zone */
2430Sstevel@tonic-gate 	/*
2440Sstevel@tonic-gate 	 * zone_vfslist is protected by vfs_list_lock().
2450Sstevel@tonic-gate 	 */
2460Sstevel@tonic-gate 	struct vfs	*zone_vfslist;	/* list of FS's mounted in zone */
2470Sstevel@tonic-gate 	uint64_t	zone_uniqid;	/* unique zone generation number */
2480Sstevel@tonic-gate 	struct cred	*zone_kcred;	/* kcred-like, zone-limited cred */
2490Sstevel@tonic-gate 	/*
2500Sstevel@tonic-gate 	 * zone_pool is protected by pool_lock().
2510Sstevel@tonic-gate 	 */
2520Sstevel@tonic-gate 	struct pool	*zone_pool;	/* pool the zone is bound to */
2530Sstevel@tonic-gate 	hrtime_t	zone_pool_mod;	/* last pool bind modification time */
2540Sstevel@tonic-gate 	/* zone_psetid is protected by cpu_lock */
2550Sstevel@tonic-gate 	psetid_t	zone_psetid;	/* pset the zone is bound to */
2560Sstevel@tonic-gate 	/*
2570Sstevel@tonic-gate 	 * The following two can be read without holding any locks.  They are
2580Sstevel@tonic-gate 	 * updated under cpu_lock.
2590Sstevel@tonic-gate 	 */
2600Sstevel@tonic-gate 	int		zone_ncpus;  /* zone's idea of ncpus */
2610Sstevel@tonic-gate 	int		zone_ncpus_online; /* zone's idea of ncpus_online */
2620Sstevel@tonic-gate } zone_t;
2630Sstevel@tonic-gate 
2640Sstevel@tonic-gate /*
2650Sstevel@tonic-gate  * Special value of zone_psetid to indicate that pools are disabled.
2660Sstevel@tonic-gate  */
2670Sstevel@tonic-gate #define	ZONE_PS_INVAL	PS_MYID
2680Sstevel@tonic-gate 
2690Sstevel@tonic-gate extern zone_t zone0;
2700Sstevel@tonic-gate extern zone_t *global_zone;
2710Sstevel@tonic-gate extern uint_t maxzones;
2720Sstevel@tonic-gate extern rctl_hndl_t rc_zone_nlwps;
2730Sstevel@tonic-gate 
2740Sstevel@tonic-gate extern const char * const zone_initname;
2750Sstevel@tonic-gate 
2760Sstevel@tonic-gate extern long zone(int, void *, void *, void *, void *, void *);
2770Sstevel@tonic-gate extern void zone_zsd_init(void);
2780Sstevel@tonic-gate extern void zone_init(void);
2790Sstevel@tonic-gate extern void zone_hold(zone_t *);
2800Sstevel@tonic-gate extern void zone_rele(zone_t *);
2810Sstevel@tonic-gate extern void zone_cred_hold(zone_t *);
2820Sstevel@tonic-gate extern void zone_cred_rele(zone_t *);
2830Sstevel@tonic-gate extern void zone_task_hold(zone_t *);
2840Sstevel@tonic-gate extern void zone_task_rele(zone_t *);
2850Sstevel@tonic-gate extern zone_t *zone_find_by_id(zoneid_t);
2860Sstevel@tonic-gate extern zone_t *zone_find_by_name(char *);
2870Sstevel@tonic-gate extern zone_t *zone_find_by_path(const char *);
2880Sstevel@tonic-gate extern zoneid_t getzoneid(void);
2890Sstevel@tonic-gate 
2900Sstevel@tonic-gate /*
2910Sstevel@tonic-gate  * Zone-specific data (ZSD) APIs
2920Sstevel@tonic-gate  */
2930Sstevel@tonic-gate /*
2940Sstevel@tonic-gate  * The following is what code should be initializing its zone_key_t to if it
2950Sstevel@tonic-gate  * calls zone_getspecific() without necessarily knowing that zone_key_create()
2960Sstevel@tonic-gate  * has been called on the key.
2970Sstevel@tonic-gate  */
2980Sstevel@tonic-gate #define	ZONE_KEY_UNINITIALIZED	0
2990Sstevel@tonic-gate 
3000Sstevel@tonic-gate typedef uint_t zone_key_t;
3010Sstevel@tonic-gate 
3020Sstevel@tonic-gate extern void	zone_key_create(zone_key_t *, void *(*)(zoneid_t),
3030Sstevel@tonic-gate     void (*)(zoneid_t, void *), void (*)(zoneid_t, void *));
3040Sstevel@tonic-gate extern int 	zone_key_delete(zone_key_t);
3050Sstevel@tonic-gate extern void	*zone_getspecific(zone_key_t, zone_t *);
3060Sstevel@tonic-gate extern int	zone_setspecific(zone_key_t, zone_t *, const void *);
3070Sstevel@tonic-gate 
3080Sstevel@tonic-gate /*
3090Sstevel@tonic-gate  * The definition of a zsd_entry is truly private to zone.c and is only
3100Sstevel@tonic-gate  * placed here so it can be shared with mdb.
3110Sstevel@tonic-gate  */
3120Sstevel@tonic-gate struct zsd_entry {
3130Sstevel@tonic-gate 	zone_key_t		zsd_key;	/* Key used to lookup value */
3140Sstevel@tonic-gate 	void			*zsd_data;	/* Caller-managed value */
3150Sstevel@tonic-gate 	/*
3160Sstevel@tonic-gate 	 * Callbacks to be executed when a zone is created, shutdown, and
3170Sstevel@tonic-gate 	 * destroyed, respectively.
3180Sstevel@tonic-gate 	 */
3190Sstevel@tonic-gate 	void			*(*zsd_create)(zoneid_t);
3200Sstevel@tonic-gate 	void			(*zsd_shutdown)(zoneid_t, void *);
3210Sstevel@tonic-gate 	void			(*zsd_destroy)(zoneid_t, void *);
3220Sstevel@tonic-gate 	list_node_t		zsd_linkage;
3230Sstevel@tonic-gate };
3240Sstevel@tonic-gate 
3250Sstevel@tonic-gate /*
3260Sstevel@tonic-gate  * Macros to help with zone visibility restrictions.
3270Sstevel@tonic-gate  */
3280Sstevel@tonic-gate 
3290Sstevel@tonic-gate /*
3300Sstevel@tonic-gate  * Is process in the global zone?
3310Sstevel@tonic-gate  */
3320Sstevel@tonic-gate #define	INGLOBALZONE(p) \
3330Sstevel@tonic-gate 	((p)->p_zone == global_zone)
3340Sstevel@tonic-gate 
3350Sstevel@tonic-gate /*
3360Sstevel@tonic-gate  * Can process view objects in given zone?
3370Sstevel@tonic-gate  */
3380Sstevel@tonic-gate #define	HASZONEACCESS(p, zoneid) \
3390Sstevel@tonic-gate 	((p)->p_zone->zone_id == (zoneid) || INGLOBALZONE(p))
3400Sstevel@tonic-gate 
3410Sstevel@tonic-gate /*
3420Sstevel@tonic-gate  * Convenience macro to see if a resolved path is visible from within a
3430Sstevel@tonic-gate  * given zone.
3440Sstevel@tonic-gate  *
3450Sstevel@tonic-gate  * The basic idea is that the first (zone_rootpathlen - 1) bytes of the
3460Sstevel@tonic-gate  * two strings must be equal.  Since the rootpathlen has a trailing '/',
3470Sstevel@tonic-gate  * we want to skip everything in the path up to (but not including) the
3480Sstevel@tonic-gate  * trailing '/'.
3490Sstevel@tonic-gate  */
3500Sstevel@tonic-gate #define	ZONE_PATH_VISIBLE(path, zone) \
3510Sstevel@tonic-gate 	(strncmp((path), (zone)->zone_rootpath,		\
3520Sstevel@tonic-gate 	    (zone)->zone_rootpathlen - 1) == 0)
3530Sstevel@tonic-gate 
3540Sstevel@tonic-gate /*
3550Sstevel@tonic-gate  * Convenience macro to go from the global view of a path to that seen
3560Sstevel@tonic-gate  * from within said zone.  It is the responsibility of the caller to
3570Sstevel@tonic-gate  * ensure that the path is a resolved one (ie, no '..'s or '.'s), and is
3580Sstevel@tonic-gate  * in fact visible from within the zone.
3590Sstevel@tonic-gate  */
3600Sstevel@tonic-gate #define	ZONE_PATH_TRANSLATE(path, zone)	\
3610Sstevel@tonic-gate 	(ASSERT(ZONE_PATH_VISIBLE(path, zone)),	\
3620Sstevel@tonic-gate 	(path) + (zone)->zone_rootpathlen - 2)
3630Sstevel@tonic-gate 
3640Sstevel@tonic-gate /*
3650Sstevel@tonic-gate  * Special processes visible in all zones.
3660Sstevel@tonic-gate  */
3670Sstevel@tonic-gate #define	ZONE_SPECIALPID(x)	 ((x) == 0 || (x) == 1)
3680Sstevel@tonic-gate 
3690Sstevel@tonic-gate /*
3700Sstevel@tonic-gate  * Special zoneid_t token to refer to all zones.
3710Sstevel@tonic-gate  */
3720Sstevel@tonic-gate #define	ALL_ZONES	(-1)
3730Sstevel@tonic-gate 
3740Sstevel@tonic-gate /*
3750Sstevel@tonic-gate  * Zone-safe version of thread_create() to be used when the caller wants to
3760Sstevel@tonic-gate  * create a kernel thread to run within the current zone's context.
3770Sstevel@tonic-gate  */
3780Sstevel@tonic-gate extern kthread_t *zthread_create(caddr_t, size_t, void (*)(), void *, size_t,
3790Sstevel@tonic-gate     pri_t);
3800Sstevel@tonic-gate extern void zthread_exit(void);
3810Sstevel@tonic-gate 
3820Sstevel@tonic-gate /*
3830Sstevel@tonic-gate  * Functions for an external observer to register interest in a zone's status
3840Sstevel@tonic-gate  * change.  Observers will be woken up when the zone status equals the status
3850Sstevel@tonic-gate  * argument passed in (in the case of zone_status_timedwait, the function may
3860Sstevel@tonic-gate  * also return because of a timeout; zone_status_wait_sig may return early due
3870Sstevel@tonic-gate  * to a signal being delivered; zone_status_timedwait_sig may return for any of
3880Sstevel@tonic-gate  * the above reasons).
3890Sstevel@tonic-gate  *
3900Sstevel@tonic-gate  * Otherwise these behave identically to cv_timedwait(), cv_wait(), and
3910Sstevel@tonic-gate  * cv_wait_sig() respectively.
3920Sstevel@tonic-gate  */
3930Sstevel@tonic-gate extern clock_t zone_status_timedwait(zone_t *, clock_t, zone_status_t);
3940Sstevel@tonic-gate extern clock_t zone_status_timedwait_sig(zone_t *, clock_t, zone_status_t);
3950Sstevel@tonic-gate extern void zone_status_wait(zone_t *, zone_status_t);
3960Sstevel@tonic-gate extern int zone_status_wait_sig(zone_t *, zone_status_t);
3970Sstevel@tonic-gate 
3980Sstevel@tonic-gate /*
3990Sstevel@tonic-gate  * Get the status  of the zone (at the time it was called).  The state may
4000Sstevel@tonic-gate  * have progressed by the time it is returned.
4010Sstevel@tonic-gate  */
4020Sstevel@tonic-gate extern zone_status_t zone_status_get(zone_t *);
4030Sstevel@tonic-gate 
4040Sstevel@tonic-gate /*
4050Sstevel@tonic-gate  * Get the "kcred" credentials corresponding to the given zone.
4060Sstevel@tonic-gate  */
4070Sstevel@tonic-gate extern struct cred *zone_get_kcred(zoneid_t);
4080Sstevel@tonic-gate 
4090Sstevel@tonic-gate /*
4100Sstevel@tonic-gate  * Get/set the pool the zone is currently bound to.
4110Sstevel@tonic-gate  */
4120Sstevel@tonic-gate extern struct pool *zone_pool_get(zone_t *);
4130Sstevel@tonic-gate extern void zone_pool_set(zone_t *, struct pool *);
4140Sstevel@tonic-gate 
4150Sstevel@tonic-gate /*
4160Sstevel@tonic-gate  * Get/set the pset the zone is currently using.
4170Sstevel@tonic-gate  */
4180Sstevel@tonic-gate extern psetid_t zone_pset_get(zone_t *);
4190Sstevel@tonic-gate extern void zone_pset_set(zone_t *, psetid_t);
4200Sstevel@tonic-gate 
4210Sstevel@tonic-gate /*
4220Sstevel@tonic-gate  * Get the number of cpus/online-cpus visible from the given zone.
4230Sstevel@tonic-gate  */
4240Sstevel@tonic-gate extern int zone_ncpus_get(zone_t *);
4250Sstevel@tonic-gate extern int zone_ncpus_online_get(zone_t *);
4260Sstevel@tonic-gate 
4270Sstevel@tonic-gate /*
4280Sstevel@tonic-gate  * zone version of uadmin()
4290Sstevel@tonic-gate  */
4300Sstevel@tonic-gate extern int zone_uadmin(int, int, struct cred *);
4310Sstevel@tonic-gate extern void zone_shutdown_global(void);
4320Sstevel@tonic-gate 
4330Sstevel@tonic-gate extern void mount_in_progress(void);
4340Sstevel@tonic-gate extern void mount_completed(void);
4350Sstevel@tonic-gate 
4360Sstevel@tonic-gate extern int zone_walk(int (*)(zone_t *, void *), void *);
4370Sstevel@tonic-gate 
4380Sstevel@tonic-gate #endif	/* _KERNEL */
4390Sstevel@tonic-gate 
4400Sstevel@tonic-gate #ifdef	__cplusplus
4410Sstevel@tonic-gate }
4420Sstevel@tonic-gate #endif
4430Sstevel@tonic-gate 
4440Sstevel@tonic-gate #endif	/* _SYS_ZONE_H */
445