xref: /titanic_53/usr/src/uts/common/sys/zone.h (revision cf8f45c7690afabe63bdb8066b11db58d708ad09)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef _SYS_ZONE_H
287c478bd9Sstevel@tonic-gate #define	_SYS_ZONE_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <sys/types.h>
337c478bd9Sstevel@tonic-gate #include <sys/mutex.h>
347c478bd9Sstevel@tonic-gate #include <sys/param.h>
357c478bd9Sstevel@tonic-gate #include <sys/rctl.h>
367c478bd9Sstevel@tonic-gate #include <sys/pset.h>
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
397c478bd9Sstevel@tonic-gate extern "C" {
407c478bd9Sstevel@tonic-gate #endif
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate /*
437c478bd9Sstevel@tonic-gate  * NOTE
447c478bd9Sstevel@tonic-gate  *
457c478bd9Sstevel@tonic-gate  * The contents of this file are private to the implementation of
467c478bd9Sstevel@tonic-gate  * Solaris and are subject to change at any time without notice.
477c478bd9Sstevel@tonic-gate  * Applications and drivers using these interfaces may fail to
487c478bd9Sstevel@tonic-gate  * run on future releases.
497c478bd9Sstevel@tonic-gate  */
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate /* Available both in kernel and for user space */
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate /* zone id restrictions and special ids */
547c478bd9Sstevel@tonic-gate #define	MAX_ZONEID	9999
557c478bd9Sstevel@tonic-gate #define	MIN_USERZONEID	1	/* lowest user-creatable zone ID */
567c478bd9Sstevel@tonic-gate #define	MIN_ZONEID	0	/* minimum zone ID on system */
577c478bd9Sstevel@tonic-gate #define	GLOBAL_ZONEID	0
587c478bd9Sstevel@tonic-gate #define	ZONEID_WIDTH	4	/* for printf */
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate /* system call subcodes */
617c478bd9Sstevel@tonic-gate #define	ZONE_CREATE	0
627c478bd9Sstevel@tonic-gate #define	ZONE_DESTROY	1
637c478bd9Sstevel@tonic-gate #define	ZONE_GETATTR	2
647c478bd9Sstevel@tonic-gate #define	ZONE_ENTER	3
657c478bd9Sstevel@tonic-gate #define	ZONE_LIST	4
667c478bd9Sstevel@tonic-gate #define	ZONE_SHUTDOWN	5
677c478bd9Sstevel@tonic-gate #define	ZONE_LOOKUP	6
687c478bd9Sstevel@tonic-gate #define	ZONE_BOOT	7
69821c4a97Sdp #define	ZONE_VERSION	8
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate /* zone attributes */
727c478bd9Sstevel@tonic-gate #define	ZONE_ATTR_ROOT		1
737c478bd9Sstevel@tonic-gate #define	ZONE_ATTR_NAME		2
747c478bd9Sstevel@tonic-gate #define	ZONE_ATTR_STATUS	3
757c478bd9Sstevel@tonic-gate #define	ZONE_ATTR_PRIVSET	4
767c478bd9Sstevel@tonic-gate #define	ZONE_ATTR_UNIQID	5
777c478bd9Sstevel@tonic-gate #define	ZONE_ATTR_POOLID	6
787c478bd9Sstevel@tonic-gate #define	ZONE_ATTR_INITPID	7
797c478bd9Sstevel@tonic-gate 
80*cf8f45c7Sdstaff #define	ZONE_EVENT_CHANNEL	"com.sun:zones:status"
81*cf8f45c7Sdstaff #define	ZONE_EVENT_STATUS_CLASS	"status"
82*cf8f45c7Sdstaff #define	ZONE_EVENT_STATUS_SUBCLASS	"change"
83*cf8f45c7Sdstaff 
84*cf8f45c7Sdstaff #define	ZONE_EVENT_UNINITIALIZED	"uninitialized"
85*cf8f45c7Sdstaff #define	ZONE_EVENT_READY		"ready"
86*cf8f45c7Sdstaff #define	ZONE_EVENT_RUNNING		"running"
87*cf8f45c7Sdstaff #define	ZONE_EVENT_SHUTTING_DOWN	"shutting_down"
88*cf8f45c7Sdstaff 
89*cf8f45c7Sdstaff #define	ZONE_CB_NAME		"zonename"
90*cf8f45c7Sdstaff #define	ZONE_CB_NEWSTATE	"newstate"
91*cf8f45c7Sdstaff #define	ZONE_CB_OLDSTATE	"oldstate"
92*cf8f45c7Sdstaff #define	ZONE_CB_TIMESTAMP	"when"
93*cf8f45c7Sdstaff #define	ZONE_CB_ZONEID		"zoneid"
94*cf8f45c7Sdstaff 
957c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32
967c478bd9Sstevel@tonic-gate typedef struct {
977c478bd9Sstevel@tonic-gate 	caddr32_t zone_name;
987c478bd9Sstevel@tonic-gate 	caddr32_t zone_root;
997c478bd9Sstevel@tonic-gate 	caddr32_t zone_privs;
100821c4a97Sdp 	size32_t zone_privssz;
1017c478bd9Sstevel@tonic-gate 	caddr32_t rctlbuf;
1027c478bd9Sstevel@tonic-gate 	size32_t rctlbufsz;
1037c478bd9Sstevel@tonic-gate 	caddr32_t extended_error;
104fa9e4066Sahrens 	caddr32_t zfsbuf;
105fa9e4066Sahrens 	size32_t  zfsbufsz;
1067c478bd9Sstevel@tonic-gate } zone_def32;
1077c478bd9Sstevel@tonic-gate #endif
1087c478bd9Sstevel@tonic-gate typedef struct {
1097c478bd9Sstevel@tonic-gate 	const char *zone_name;
1107c478bd9Sstevel@tonic-gate 	const char *zone_root;
1117c478bd9Sstevel@tonic-gate 	const struct priv_set *zone_privs;
112821c4a97Sdp 	size_t zone_privssz;
1137c478bd9Sstevel@tonic-gate 	const char *rctlbuf;
1147c478bd9Sstevel@tonic-gate 	size_t rctlbufsz;
1157c478bd9Sstevel@tonic-gate 	int *extended_error;
116fa9e4066Sahrens 	const char *zfsbuf;
117fa9e4066Sahrens 	size_t zfsbufsz;
1187c478bd9Sstevel@tonic-gate } zone_def;
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate /* extended error information */
1217c478bd9Sstevel@tonic-gate #define	ZE_UNKNOWN	0	/* No extended error info */
1227c478bd9Sstevel@tonic-gate #define	ZE_CHROOTED	1	/* tried to zone_create from chroot */
1237c478bd9Sstevel@tonic-gate #define	ZE_AREMOUNTS	2	/* there are mounts within the zone */
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate /* zone_status */
1267c478bd9Sstevel@tonic-gate typedef enum {
1277c478bd9Sstevel@tonic-gate 	ZONE_IS_UNINITIALIZED = 0,
1287c478bd9Sstevel@tonic-gate 	ZONE_IS_READY,
1297c478bd9Sstevel@tonic-gate 	ZONE_IS_BOOTING,
1307c478bd9Sstevel@tonic-gate 	ZONE_IS_RUNNING,
1317c478bd9Sstevel@tonic-gate 	ZONE_IS_SHUTTING_DOWN,
1327c478bd9Sstevel@tonic-gate 	ZONE_IS_EMPTY,
1337c478bd9Sstevel@tonic-gate 	ZONE_IS_DOWN,
1347c478bd9Sstevel@tonic-gate 	ZONE_IS_DYING,
1357c478bd9Sstevel@tonic-gate 	ZONE_IS_DEAD
1367c478bd9Sstevel@tonic-gate } zone_status_t;
1377c478bd9Sstevel@tonic-gate #define	ZONE_MIN_STATE		ZONE_IS_UNINITIALIZED
1387c478bd9Sstevel@tonic-gate #define	ZONE_MAX_STATE		ZONE_IS_DEAD
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate /*
1417c478bd9Sstevel@tonic-gate  * Valid commands which may be issued by zoneadm to zoneadmd.  The kernel also
1427c478bd9Sstevel@tonic-gate  * communicates with zoneadmd, but only uses Z_REBOOT and Z_HALT.
1437c478bd9Sstevel@tonic-gate  */
1447c478bd9Sstevel@tonic-gate typedef enum zone_cmd {
145108322fbScarlsonj 	Z_READY, Z_BOOT, Z_REBOOT, Z_HALT, Z_NOTE_UNINSTALLING,
146108322fbScarlsonj 	Z_MOUNT, Z_UNMOUNT
1477c478bd9Sstevel@tonic-gate } zone_cmd_t;
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate #define	ZONEBOOTARGS_MAX	257	/* uadmin()'s buffer is 257 bytes. */
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate /*
1527c478bd9Sstevel@tonic-gate  * The structure of a request to zoneadmd.
1537c478bd9Sstevel@tonic-gate  */
1547c478bd9Sstevel@tonic-gate typedef struct zone_cmd_arg {
1557c478bd9Sstevel@tonic-gate 	uint64_t	uniqid;		/* unique "generation number" */
1567c478bd9Sstevel@tonic-gate 	zone_cmd_t	cmd;		/* requested action */
1577c478bd9Sstevel@tonic-gate 	char locale[MAXPATHLEN];	/* locale in which to render messages */
1587c478bd9Sstevel@tonic-gate 	char bootbuf[ZONEBOOTARGS_MAX];	/* arguments passed to zone_boot() */
1597c478bd9Sstevel@tonic-gate } zone_cmd_arg_t;
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate /*
1627c478bd9Sstevel@tonic-gate  * Structure of zoneadmd's response to a request.  A NULL return value means
1637c478bd9Sstevel@tonic-gate  * the caller should attempt to restart zoneadmd and retry.
1647c478bd9Sstevel@tonic-gate  */
1657c478bd9Sstevel@tonic-gate typedef struct zone_cmd_rval {
1667c478bd9Sstevel@tonic-gate 	int rval;			/* return value of request */
1677c478bd9Sstevel@tonic-gate 	char errbuf[1];	/* variable-sized buffer containing error messages */
1687c478bd9Sstevel@tonic-gate } zone_cmd_rval_t;
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate /*
1717c478bd9Sstevel@tonic-gate  * The zone support infrastructure uses the zone name as a component
1727c478bd9Sstevel@tonic-gate  * of unix domain (AF_UNIX) sockets, which are limited to 108 characters
1737c478bd9Sstevel@tonic-gate  * in length, so ZONENAME_MAX is limited by that.
1747c478bd9Sstevel@tonic-gate  */
1757c478bd9Sstevel@tonic-gate #define	ZONENAME_MAX		64
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate #define	GLOBAL_ZONENAME		"global"
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate /*
1807c478bd9Sstevel@tonic-gate  * Extended Regular expression (see regex(5)) which matches all valid zone
1817c478bd9Sstevel@tonic-gate  * names.
1827c478bd9Sstevel@tonic-gate  */
1837c478bd9Sstevel@tonic-gate #define	ZONENAME_REGEXP		"[a-zA-Z0-9][-_.a-zA-Z0-9]{0,62}"
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate /*
1867c478bd9Sstevel@tonic-gate  * Where the zones support infrastructure places temporary files.
1877c478bd9Sstevel@tonic-gate  */
1887c478bd9Sstevel@tonic-gate #define	ZONES_TMPDIR		"/var/run/zones"
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate /*
1917c478bd9Sstevel@tonic-gate  * The path to the door used by clients to communicate with zoneadmd.
1927c478bd9Sstevel@tonic-gate  */
1937c478bd9Sstevel@tonic-gate #define	ZONE_DOOR_PATH		ZONES_TMPDIR "/%s.zoneadmd_door"
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate #ifdef _KERNEL
1977c478bd9Sstevel@tonic-gate /*
1987c478bd9Sstevel@tonic-gate  * We need to protect the definition of 'list_t' from userland applications and
1997c478bd9Sstevel@tonic-gate  * libraries which may be defining ther own versions.
2007c478bd9Sstevel@tonic-gate  */
2017c478bd9Sstevel@tonic-gate #include <sys/list.h>
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate #define	GLOBAL_ZONEUNIQID	0	/* uniqid of the global zone */
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate /* zone_flags */
2067c478bd9Sstevel@tonic-gate #define	ZF_DESTROYED		0x1	/* ZSD destructor callbacks run */
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate struct pool;
2097c478bd9Sstevel@tonic-gate 
210fa9e4066Sahrens /*
211fa9e4066Sahrens  * Structure to record list of ZFS datasets exported to a zone.
212fa9e4066Sahrens  */
213fa9e4066Sahrens typedef struct zone_dataset {
214fa9e4066Sahrens 	char		*zd_dataset;
215fa9e4066Sahrens 	list_node_t	zd_linkage;
216fa9e4066Sahrens } zone_dataset_t;
217fa9e4066Sahrens 
2187c478bd9Sstevel@tonic-gate typedef struct zone {
2197c478bd9Sstevel@tonic-gate 	/*
2207c478bd9Sstevel@tonic-gate 	 * zone_name is never modified once set.
2217c478bd9Sstevel@tonic-gate 	 */
2227c478bd9Sstevel@tonic-gate 	char		*zone_name;	/* zone's configuration name */
2237c478bd9Sstevel@tonic-gate 	/*
2247c478bd9Sstevel@tonic-gate 	 * zone_nodename and zone_domain are never freed once allocated.
2257c478bd9Sstevel@tonic-gate 	 */
2267c478bd9Sstevel@tonic-gate 	char		*zone_nodename;	/* utsname.nodename equivalent */
2277c478bd9Sstevel@tonic-gate 	char		*zone_domain;	/* srpc_domain equivalent */
2287c478bd9Sstevel@tonic-gate 	/*
2297c478bd9Sstevel@tonic-gate 	 * zone_lock protects the following fields of a zone_t:
2307c478bd9Sstevel@tonic-gate 	 * 	zone_ref
2317c478bd9Sstevel@tonic-gate 	 * 	zone_cred_ref
2327c478bd9Sstevel@tonic-gate 	 * 	zone_ntasks
2337c478bd9Sstevel@tonic-gate 	 * 	zone_flags
2347c478bd9Sstevel@tonic-gate 	 * 	zone_zsd
2357c478bd9Sstevel@tonic-gate 	 */
2367c478bd9Sstevel@tonic-gate 	kmutex_t	zone_lock;
2377c478bd9Sstevel@tonic-gate 	/*
2387c478bd9Sstevel@tonic-gate 	 * zone_linkage is the zone's linkage into the active or
2397c478bd9Sstevel@tonic-gate 	 * death-row list.  The field is protected by zonehash_lock.
2407c478bd9Sstevel@tonic-gate 	 */
2417c478bd9Sstevel@tonic-gate 	list_node_t	zone_linkage;
2427c478bd9Sstevel@tonic-gate 	zoneid_t	zone_id;	/* ID of zone */
2437c478bd9Sstevel@tonic-gate 	uint_t		zone_ref;	/* count of zone_hold()s on zone */
2447c478bd9Sstevel@tonic-gate 	uint_t		zone_cred_ref;	/* count of zone_hold_cred()s on zone */
2457c478bd9Sstevel@tonic-gate 	/*
2467c478bd9Sstevel@tonic-gate 	 * zone_rootvp and zone_rootpath can never be modified once set.
2477c478bd9Sstevel@tonic-gate 	 */
2487c478bd9Sstevel@tonic-gate 	struct vnode	*zone_rootvp;	/* zone's root vnode */
2497c478bd9Sstevel@tonic-gate 	char		*zone_rootpath;	/* Path to zone's root + '/' */
2507c478bd9Sstevel@tonic-gate 	ushort_t	zone_flags;	/* misc flags */
2517c478bd9Sstevel@tonic-gate 	zone_status_t	zone_status;	/* protected by zone_status_lock */
2527c478bd9Sstevel@tonic-gate 	uint_t		zone_ntasks;	/* number of tasks executing in zone */
2537c478bd9Sstevel@tonic-gate 	kmutex_t	zone_nlwps_lock; /* protects zone_nlwps, and *_nlwps */
2547c478bd9Sstevel@tonic-gate 					/* counters in projects and tasks */
2557c478bd9Sstevel@tonic-gate 					/* that are within the zone */
2567c478bd9Sstevel@tonic-gate 	rctl_qty_t	zone_nlwps;	/* number of lwps in zone */
2577c478bd9Sstevel@tonic-gate 	rctl_qty_t	zone_nlwps_ctl; /* protected by zone_rctls->rcs_lock */
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate 	uint_t		zone_rootpathlen; /* strlen(zone_rootpath) + 1 */
2607c478bd9Sstevel@tonic-gate 	uint32_t	zone_shares;	/* FSS shares allocated to zone */
2617c478bd9Sstevel@tonic-gate 	rctl_set_t	*zone_rctls;	/* zone-wide (zone.*) rctls */
2627c478bd9Sstevel@tonic-gate 	list_t		zone_zsd;	/* list of Zone-Specific Data values */
2637c478bd9Sstevel@tonic-gate 	kcondvar_t	zone_cv;	/* used to signal state changes */
2647c478bd9Sstevel@tonic-gate 	struct proc	*zone_zsched;	/* Dummy kernel "zsched" process */
2657c478bd9Sstevel@tonic-gate 	pid_t		zone_proc_initpid; /* pid of "init" for this zone */
2667c478bd9Sstevel@tonic-gate 	int		zone_boot_err;  /* for zone_boot() if boot fails */
2677c478bd9Sstevel@tonic-gate 	char		*zone_bootargs;	/* arguments passed via zone_boot() */
2687c478bd9Sstevel@tonic-gate 	/*
2697c478bd9Sstevel@tonic-gate 	 * zone_kthreads is protected by zone_status_lock.
2707c478bd9Sstevel@tonic-gate 	 */
2717c478bd9Sstevel@tonic-gate 	kthread_t	*zone_kthreads;	/* kernel threads in zone */
2727c478bd9Sstevel@tonic-gate 	struct priv_set	*zone_privset;	/* limit set for zone */
2737c478bd9Sstevel@tonic-gate 	/*
2747c478bd9Sstevel@tonic-gate 	 * zone_vfslist is protected by vfs_list_lock().
2757c478bd9Sstevel@tonic-gate 	 */
2767c478bd9Sstevel@tonic-gate 	struct vfs	*zone_vfslist;	/* list of FS's mounted in zone */
2777c478bd9Sstevel@tonic-gate 	uint64_t	zone_uniqid;	/* unique zone generation number */
2787c478bd9Sstevel@tonic-gate 	struct cred	*zone_kcred;	/* kcred-like, zone-limited cred */
2797c478bd9Sstevel@tonic-gate 	/*
2807c478bd9Sstevel@tonic-gate 	 * zone_pool is protected by pool_lock().
2817c478bd9Sstevel@tonic-gate 	 */
2827c478bd9Sstevel@tonic-gate 	struct pool	*zone_pool;	/* pool the zone is bound to */
2837c478bd9Sstevel@tonic-gate 	hrtime_t	zone_pool_mod;	/* last pool bind modification time */
2847c478bd9Sstevel@tonic-gate 	/* zone_psetid is protected by cpu_lock */
2857c478bd9Sstevel@tonic-gate 	psetid_t	zone_psetid;	/* pset the zone is bound to */
2867c478bd9Sstevel@tonic-gate 	/*
2877c478bd9Sstevel@tonic-gate 	 * The following two can be read without holding any locks.  They are
2887c478bd9Sstevel@tonic-gate 	 * updated under cpu_lock.
2897c478bd9Sstevel@tonic-gate 	 */
2907c478bd9Sstevel@tonic-gate 	int		zone_ncpus;  /* zone's idea of ncpus */
2917c478bd9Sstevel@tonic-gate 	int		zone_ncpus_online; /* zone's idea of ncpus_online */
292fa9e4066Sahrens 	/*
293fa9e4066Sahrens 	 * List of ZFS datasets exported to this zone.
294fa9e4066Sahrens 	 */
295fa9e4066Sahrens 	list_t		zone_datasets;	/* list of datasets */
2967c478bd9Sstevel@tonic-gate } zone_t;
2977c478bd9Sstevel@tonic-gate 
2987c478bd9Sstevel@tonic-gate /*
2997c478bd9Sstevel@tonic-gate  * Special value of zone_psetid to indicate that pools are disabled.
3007c478bd9Sstevel@tonic-gate  */
3017c478bd9Sstevel@tonic-gate #define	ZONE_PS_INVAL	PS_MYID
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate extern zone_t zone0;
3047c478bd9Sstevel@tonic-gate extern zone_t *global_zone;
3057c478bd9Sstevel@tonic-gate extern uint_t maxzones;
3067c478bd9Sstevel@tonic-gate extern rctl_hndl_t rc_zone_nlwps;
3077c478bd9Sstevel@tonic-gate 
3087c478bd9Sstevel@tonic-gate extern const char * const zone_initname;
3097c478bd9Sstevel@tonic-gate 
310fa9e4066Sahrens extern long zone(int, void *, void *, void *, void *);
3117c478bd9Sstevel@tonic-gate extern void zone_zsd_init(void);
3127c478bd9Sstevel@tonic-gate extern void zone_init(void);
3137c478bd9Sstevel@tonic-gate extern void zone_hold(zone_t *);
3147c478bd9Sstevel@tonic-gate extern void zone_rele(zone_t *);
3157c478bd9Sstevel@tonic-gate extern void zone_cred_hold(zone_t *);
3167c478bd9Sstevel@tonic-gate extern void zone_cred_rele(zone_t *);
3177c478bd9Sstevel@tonic-gate extern void zone_task_hold(zone_t *);
3187c478bd9Sstevel@tonic-gate extern void zone_task_rele(zone_t *);
3197c478bd9Sstevel@tonic-gate extern zone_t *zone_find_by_id(zoneid_t);
3207c478bd9Sstevel@tonic-gate extern zone_t *zone_find_by_name(char *);
3217c478bd9Sstevel@tonic-gate extern zone_t *zone_find_by_path(const char *);
3227c478bd9Sstevel@tonic-gate extern zoneid_t getzoneid(void);
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate /*
3257c478bd9Sstevel@tonic-gate  * Zone-specific data (ZSD) APIs
3267c478bd9Sstevel@tonic-gate  */
3277c478bd9Sstevel@tonic-gate /*
3287c478bd9Sstevel@tonic-gate  * The following is what code should be initializing its zone_key_t to if it
3297c478bd9Sstevel@tonic-gate  * calls zone_getspecific() without necessarily knowing that zone_key_create()
3307c478bd9Sstevel@tonic-gate  * has been called on the key.
3317c478bd9Sstevel@tonic-gate  */
3327c478bd9Sstevel@tonic-gate #define	ZONE_KEY_UNINITIALIZED	0
3337c478bd9Sstevel@tonic-gate 
3347c478bd9Sstevel@tonic-gate typedef uint_t zone_key_t;
3357c478bd9Sstevel@tonic-gate 
3367c478bd9Sstevel@tonic-gate extern void	zone_key_create(zone_key_t *, void *(*)(zoneid_t),
3377c478bd9Sstevel@tonic-gate     void (*)(zoneid_t, void *), void (*)(zoneid_t, void *));
3387c478bd9Sstevel@tonic-gate extern int 	zone_key_delete(zone_key_t);
3397c478bd9Sstevel@tonic-gate extern void	*zone_getspecific(zone_key_t, zone_t *);
3407c478bd9Sstevel@tonic-gate extern int	zone_setspecific(zone_key_t, zone_t *, const void *);
3417c478bd9Sstevel@tonic-gate 
3427c478bd9Sstevel@tonic-gate /*
3437c478bd9Sstevel@tonic-gate  * The definition of a zsd_entry is truly private to zone.c and is only
3447c478bd9Sstevel@tonic-gate  * placed here so it can be shared with mdb.
3457c478bd9Sstevel@tonic-gate  */
3467c478bd9Sstevel@tonic-gate struct zsd_entry {
3477c478bd9Sstevel@tonic-gate 	zone_key_t		zsd_key;	/* Key used to lookup value */
3487c478bd9Sstevel@tonic-gate 	void			*zsd_data;	/* Caller-managed value */
3497c478bd9Sstevel@tonic-gate 	/*
3507c478bd9Sstevel@tonic-gate 	 * Callbacks to be executed when a zone is created, shutdown, and
3517c478bd9Sstevel@tonic-gate 	 * destroyed, respectively.
3527c478bd9Sstevel@tonic-gate 	 */
3537c478bd9Sstevel@tonic-gate 	void			*(*zsd_create)(zoneid_t);
3547c478bd9Sstevel@tonic-gate 	void			(*zsd_shutdown)(zoneid_t, void *);
3557c478bd9Sstevel@tonic-gate 	void			(*zsd_destroy)(zoneid_t, void *);
3567c478bd9Sstevel@tonic-gate 	list_node_t		zsd_linkage;
3577c478bd9Sstevel@tonic-gate };
3587c478bd9Sstevel@tonic-gate 
3597c478bd9Sstevel@tonic-gate /*
3607c478bd9Sstevel@tonic-gate  * Macros to help with zone visibility restrictions.
3617c478bd9Sstevel@tonic-gate  */
3627c478bd9Sstevel@tonic-gate 
3637c478bd9Sstevel@tonic-gate /*
3647c478bd9Sstevel@tonic-gate  * Is process in the global zone?
3657c478bd9Sstevel@tonic-gate  */
3667c478bd9Sstevel@tonic-gate #define	INGLOBALZONE(p) \
3677c478bd9Sstevel@tonic-gate 	((p)->p_zone == global_zone)
3687c478bd9Sstevel@tonic-gate 
3697c478bd9Sstevel@tonic-gate /*
3707c478bd9Sstevel@tonic-gate  * Can process view objects in given zone?
3717c478bd9Sstevel@tonic-gate  */
3727c478bd9Sstevel@tonic-gate #define	HASZONEACCESS(p, zoneid) \
3737c478bd9Sstevel@tonic-gate 	((p)->p_zone->zone_id == (zoneid) || INGLOBALZONE(p))
3747c478bd9Sstevel@tonic-gate 
3757c478bd9Sstevel@tonic-gate /*
3767c478bd9Sstevel@tonic-gate  * Convenience macro to see if a resolved path is visible from within a
3777c478bd9Sstevel@tonic-gate  * given zone.
3787c478bd9Sstevel@tonic-gate  *
3797c478bd9Sstevel@tonic-gate  * The basic idea is that the first (zone_rootpathlen - 1) bytes of the
3807c478bd9Sstevel@tonic-gate  * two strings must be equal.  Since the rootpathlen has a trailing '/',
3817c478bd9Sstevel@tonic-gate  * we want to skip everything in the path up to (but not including) the
3827c478bd9Sstevel@tonic-gate  * trailing '/'.
3837c478bd9Sstevel@tonic-gate  */
3847c478bd9Sstevel@tonic-gate #define	ZONE_PATH_VISIBLE(path, zone) \
3857c478bd9Sstevel@tonic-gate 	(strncmp((path), (zone)->zone_rootpath,		\
3867c478bd9Sstevel@tonic-gate 	    (zone)->zone_rootpathlen - 1) == 0)
3877c478bd9Sstevel@tonic-gate 
3887c478bd9Sstevel@tonic-gate /*
3897c478bd9Sstevel@tonic-gate  * Convenience macro to go from the global view of a path to that seen
3907c478bd9Sstevel@tonic-gate  * from within said zone.  It is the responsibility of the caller to
3917c478bd9Sstevel@tonic-gate  * ensure that the path is a resolved one (ie, no '..'s or '.'s), and is
3927c478bd9Sstevel@tonic-gate  * in fact visible from within the zone.
3937c478bd9Sstevel@tonic-gate  */
3947c478bd9Sstevel@tonic-gate #define	ZONE_PATH_TRANSLATE(path, zone)	\
3957c478bd9Sstevel@tonic-gate 	(ASSERT(ZONE_PATH_VISIBLE(path, zone)),	\
3967c478bd9Sstevel@tonic-gate 	(path) + (zone)->zone_rootpathlen - 2)
3977c478bd9Sstevel@tonic-gate 
3987c478bd9Sstevel@tonic-gate /*
3997c478bd9Sstevel@tonic-gate  * Special processes visible in all zones.
4007c478bd9Sstevel@tonic-gate  */
4017c478bd9Sstevel@tonic-gate #define	ZONE_SPECIALPID(x)	 ((x) == 0 || (x) == 1)
4027c478bd9Sstevel@tonic-gate 
4037c478bd9Sstevel@tonic-gate /*
4047c478bd9Sstevel@tonic-gate  * Special zoneid_t token to refer to all zones.
4057c478bd9Sstevel@tonic-gate  */
4067c478bd9Sstevel@tonic-gate #define	ALL_ZONES	(-1)
4077c478bd9Sstevel@tonic-gate 
4087c478bd9Sstevel@tonic-gate /*
4097c478bd9Sstevel@tonic-gate  * Zone-safe version of thread_create() to be used when the caller wants to
4107c478bd9Sstevel@tonic-gate  * create a kernel thread to run within the current zone's context.
4117c478bd9Sstevel@tonic-gate  */
4127c478bd9Sstevel@tonic-gate extern kthread_t *zthread_create(caddr_t, size_t, void (*)(), void *, size_t,
4137c478bd9Sstevel@tonic-gate     pri_t);
4147c478bd9Sstevel@tonic-gate extern void zthread_exit(void);
4157c478bd9Sstevel@tonic-gate 
4167c478bd9Sstevel@tonic-gate /*
4177c478bd9Sstevel@tonic-gate  * Functions for an external observer to register interest in a zone's status
4187c478bd9Sstevel@tonic-gate  * change.  Observers will be woken up when the zone status equals the status
4197c478bd9Sstevel@tonic-gate  * argument passed in (in the case of zone_status_timedwait, the function may
4207c478bd9Sstevel@tonic-gate  * also return because of a timeout; zone_status_wait_sig may return early due
4217c478bd9Sstevel@tonic-gate  * to a signal being delivered; zone_status_timedwait_sig may return for any of
4227c478bd9Sstevel@tonic-gate  * the above reasons).
4237c478bd9Sstevel@tonic-gate  *
4247c478bd9Sstevel@tonic-gate  * Otherwise these behave identically to cv_timedwait(), cv_wait(), and
4257c478bd9Sstevel@tonic-gate  * cv_wait_sig() respectively.
4267c478bd9Sstevel@tonic-gate  */
4277c478bd9Sstevel@tonic-gate extern clock_t zone_status_timedwait(zone_t *, clock_t, zone_status_t);
4287c478bd9Sstevel@tonic-gate extern clock_t zone_status_timedwait_sig(zone_t *, clock_t, zone_status_t);
4297c478bd9Sstevel@tonic-gate extern void zone_status_wait(zone_t *, zone_status_t);
4307c478bd9Sstevel@tonic-gate extern int zone_status_wait_sig(zone_t *, zone_status_t);
4317c478bd9Sstevel@tonic-gate 
4327c478bd9Sstevel@tonic-gate /*
4337c478bd9Sstevel@tonic-gate  * Get the status  of the zone (at the time it was called).  The state may
4347c478bd9Sstevel@tonic-gate  * have progressed by the time it is returned.
4357c478bd9Sstevel@tonic-gate  */
4367c478bd9Sstevel@tonic-gate extern zone_status_t zone_status_get(zone_t *);
4377c478bd9Sstevel@tonic-gate 
4387c478bd9Sstevel@tonic-gate /*
4397c478bd9Sstevel@tonic-gate  * Get the "kcred" credentials corresponding to the given zone.
4407c478bd9Sstevel@tonic-gate  */
4417c478bd9Sstevel@tonic-gate extern struct cred *zone_get_kcred(zoneid_t);
4427c478bd9Sstevel@tonic-gate 
4437c478bd9Sstevel@tonic-gate /*
4447c478bd9Sstevel@tonic-gate  * Get/set the pool the zone is currently bound to.
4457c478bd9Sstevel@tonic-gate  */
4467c478bd9Sstevel@tonic-gate extern struct pool *zone_pool_get(zone_t *);
4477c478bd9Sstevel@tonic-gate extern void zone_pool_set(zone_t *, struct pool *);
4487c478bd9Sstevel@tonic-gate 
4497c478bd9Sstevel@tonic-gate /*
4507c478bd9Sstevel@tonic-gate  * Get/set the pset the zone is currently using.
4517c478bd9Sstevel@tonic-gate  */
4527c478bd9Sstevel@tonic-gate extern psetid_t zone_pset_get(zone_t *);
4537c478bd9Sstevel@tonic-gate extern void zone_pset_set(zone_t *, psetid_t);
4547c478bd9Sstevel@tonic-gate 
4557c478bd9Sstevel@tonic-gate /*
4567c478bd9Sstevel@tonic-gate  * Get the number of cpus/online-cpus visible from the given zone.
4577c478bd9Sstevel@tonic-gate  */
4587c478bd9Sstevel@tonic-gate extern int zone_ncpus_get(zone_t *);
4597c478bd9Sstevel@tonic-gate extern int zone_ncpus_online_get(zone_t *);
4607c478bd9Sstevel@tonic-gate 
4617c478bd9Sstevel@tonic-gate /*
462fa9e4066Sahrens  * Returns true if the named pool/dataset is visible in the current zone.
463fa9e4066Sahrens  */
464fa9e4066Sahrens extern int zone_dataset_visible(const char *, int *);
465fa9e4066Sahrens 
466fa9e4066Sahrens /*
4677c478bd9Sstevel@tonic-gate  * zone version of uadmin()
4687c478bd9Sstevel@tonic-gate  */
4697c478bd9Sstevel@tonic-gate extern int zone_uadmin(int, int, struct cred *);
4707c478bd9Sstevel@tonic-gate extern void zone_shutdown_global(void);
4717c478bd9Sstevel@tonic-gate 
4727c478bd9Sstevel@tonic-gate extern void mount_in_progress(void);
4737c478bd9Sstevel@tonic-gate extern void mount_completed(void);
4747c478bd9Sstevel@tonic-gate 
4757c478bd9Sstevel@tonic-gate extern int zone_walk(int (*)(zone_t *, void *), void *);
4767c478bd9Sstevel@tonic-gate 
4777c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
4787c478bd9Sstevel@tonic-gate 
4797c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
4807c478bd9Sstevel@tonic-gate }
4817c478bd9Sstevel@tonic-gate #endif
4827c478bd9Sstevel@tonic-gate 
4837c478bd9Sstevel@tonic-gate #endif	/* _SYS_ZONE_H */
484